Skip to content

Commit 9475260

Browse files
authored
Return/Pass through None instead of failing with an error (#66)
1 parent 3783326 commit 9475260

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

tplinkcloud/device.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ async def _pass_through_request(self, request_type, sub_request_type, request):
6565
return None
6666

6767
request_response = response.get(request_type)
68+
# Check to make sure that -- even though we got a response -- the
69+
# response contained the requested type
70+
if request_response is None:
71+
return None
72+
6873
sub_request_response = request_response.get(sub_request_type)
6974
if self.child_id and sub_request_response.get('children'):
7075
for child in sub_request_response.get('children'):
@@ -95,6 +100,12 @@ async def get_sys_info(self):
95100

96101
async def is_on(self):
97102
device_sys_info = await self.get_sys_info()
103+
104+
# get_sys_info can return `None` if something went wrong with the
105+
# request -- in this case we pass `None` to caller
106+
if device_sys_info is None:
107+
return None
108+
98109
sys_info = device_sys_info.__dict__ if hasattr(
99110
device_sys_info, '__dict__') else device_sys_info
100111
if self.child_id:
@@ -104,6 +115,12 @@ async def is_on(self):
104115

105116
async def is_off(self):
106117
device_sys_info = await self.get_sys_info()
118+
119+
# get_sys_info can return `None` if something went wrong with the
120+
# request -- in this case we pass `None` to caller
121+
if device_sys_info is None:
122+
return None
123+
107124
sys_info = device_sys_info.__dict__ if hasattr(
108125
device_sys_info, '__dict__') else device_sys_info
109126
if self.child_id:

0 commit comments

Comments
 (0)