Skip to content

Commit 84ab348

Browse files
authored
add additional error catching
1 parent d920d83 commit 84ab348

File tree

1 file changed

+29
-23
lines changed

1 file changed

+29
-23
lines changed

pymyq/__init__.py

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -132,35 +132,41 @@ def get_garage_doors(self):
132132
"""List only MyQ garage door devices."""
133133
devices = self.get_devices()
134134

135-
garage_doors = []
136-
137-
try:
138-
for device in devices:
139-
if device['MyQDeviceTypeName'] in self.SUPPORTED_DEVICE_TYPE_NAMES:
140-
dev = {}
141-
for attribute in device['Attributes']:
142-
if attribute['AttributeDisplayName'] == 'desc':
143-
dev['deviceid'] = device['MyQDeviceId']
144-
dev['name'] = attribute['Value']
145-
garage_doors.append(dev)
146-
147-
return garage_doors
148-
except TypeError:
149-
return False
135+
if devices != False:
136+
garage_doors = []
137+
138+
try:
139+
for device in devices:
140+
if device['MyQDeviceTypeName'] in self.SUPPORTED_DEVICE_TYPE_NAMES:
141+
dev = {}
142+
for attribute in device['Attributes']:
143+
if attribute['AttributeDisplayName'] == 'desc':
144+
dev['deviceid'] = device['MyQDeviceId']
145+
dev['name'] = attribute['Value']
146+
garage_doors.append(dev)
147+
148+
return garage_doors
149+
except TypeError:
150+
return False
151+
else:
152+
return False;
150153

151154
def get_status(self, device_id):
152155
"""List only MyQ garage door devices."""
153156
devices = self.get_devices()
154157

155-
for device in devices:
156-
if device['MyQDeviceTypeName'] in self.SUPPORTED_DEVICE_TYPE_NAMES and device['MyQDeviceId'] == device_id:
157-
dev = {}
158-
for attribute in device['Attributes']:
159-
if attribute['AttributeDisplayName'] == 'doorstate':
160-
garage_state = attribute['Value']
158+
if devices != False:
159+
for device in devices:
160+
if device['MyQDeviceTypeName'] in self.SUPPORTED_DEVICE_TYPE_NAMES and device['MyQDeviceId'] == device_id:
161+
dev = {}
162+
for attribute in device['Attributes']:
163+
if attribute['AttributeDisplayName'] == 'doorstate':
164+
garage_state = attribute['Value']
161165

162-
garage_state = self.DOOR_STATE[garage_state]
163-
return garage_state
166+
garage_state = self.DOOR_STATE[garage_state]
167+
return garage_state
168+
else:
169+
return False
164170

165171
def close_device(self, device_id):
166172
"""Close MyQ Device."""

0 commit comments

Comments
 (0)