Skip to content

Commit 89969be

Browse files
committed
Set unavailable if unable to retrieve states from cloud
Set available property to false if unable to retrieve states from MyQ cloud. Some lint issues.
1 parent 737b7ca commit 89969be

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

pymyq/device.py

+14-5
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,15 @@ def name(self) -> str:
7070
@property
7171
def available(self) -> bool:
7272
"""Return if device is online or not."""
73-
return next(
74-
attr['Value'] for attr in self._device_json.get('Attributes', [])
75-
if attr.get('AttributeDisplayName') == 'online') == "True"
73+
# Both ability to retrieve state from MyQ cloud AND device itself has
74+
# to be online.
75+
is_available = self.api.online and \
76+
next(
77+
attr['Value'] for attr in
78+
self._device_json.get('Attributes', [])
79+
if attr.get('AttributeDisplayName') == 'online') == "True"
80+
81+
return is_available
7682

7783
@property
7884
def serial(self) -> str:
@@ -107,8 +113,8 @@ def state(self) -> str:
107113
def _update_state(self, value: str) -> None:
108114
"""Update state temporary during open or close."""
109115
attribute = next(attr for attr in self._device['device_info'].get(
110-
'Attributes', []) if attr.get('AttributeDisplayName')
111-
== 'doorstate')
116+
'Attributes', []) if attr.get(
117+
'AttributeDisplayName') == 'doorstate')
112118
if attribute is not None:
113119
attribute['Value'] = value
114120

@@ -143,6 +149,9 @@ async def _set_state(self, state: int) -> bool:
143149
self.name, err)
144150
return False
145151

152+
if set_state_resp is None:
153+
return False
154+
146155
if int(set_state_resp.get('ReturnCode', 1)) != 0:
147156
_LOGGER.error(
148157
'%s: Error setting the device state: %s', self.name,

0 commit comments

Comments
 (0)