Device unavailable handling improved.

This commit is contained in:
Sebastian Muszynski
2018-03-16 09:19:19 +01:00
parent 967f8ad5f2
commit d3664113e6

View File

@@ -394,6 +394,8 @@ class XiaomiGenericDevice(FanEntity):
self._device = device self._device = device
self._model = model self._model = model
self._unique_id = unique_id self._unique_id = unique_id
self._available = False
self._state = None self._state = None
self._state_attrs = { self._state_attrs = {
ATTR_MODEL: self._model, ATTR_MODEL: self._model,
@@ -424,7 +426,7 @@ class XiaomiGenericDevice(FanEntity):
@property @property
def available(self): def available(self):
"""Return true when state is known.""" """Return true when state is known."""
return self._state is not None return self._available
@property @property
def device_state_attributes(self): def device_state_attributes(self):
@@ -458,6 +460,7 @@ class XiaomiGenericDevice(FanEntity):
return result == SUCCESS return result == SUCCESS
except DeviceException as exc: except DeviceException as exc:
_LOGGER.error(mask_error, exc) _LOGGER.error(mask_error, exc)
self._available = False
return False return False
async def async_turn_on(self, speed: str = None, async def async_turn_on(self, speed: str = None,
@@ -589,6 +592,7 @@ class XiaomiAirPurifier(XiaomiGenericDevice):
self._device.status) self._device.status)
_LOGGER.debug("Got new state: %s", state) _LOGGER.debug("Got new state: %s", state)
self._available = True
self._state = state.is_on self._state = state.is_on
if self._model == MODEL_AIRPURIFIER_PRO: if self._model == MODEL_AIRPURIFIER_PRO:
@@ -608,7 +612,7 @@ class XiaomiAirPurifier(XiaomiGenericDevice):
AVAILABLE_ATTRIBUTES_AIRPURIFIER.items()}) AVAILABLE_ATTRIBUTES_AIRPURIFIER.items()})
except DeviceException as ex: except DeviceException as ex:
self._state = None self._available = False
_LOGGER.error("Got exception while fetching the state: %s", ex) _LOGGER.error("Got exception while fetching the state: %s", ex)
@property @property
@@ -774,6 +778,7 @@ class XiaomiAirHumidifier(XiaomiGenericDevice):
self._device.status) self._device.status)
_LOGGER.debug("Got new state: %s", state) _LOGGER.debug("Got new state: %s", state)
self._available = True
self._state = state.is_on self._state = state.is_on
self._state_attrs.update( self._state_attrs.update(
@@ -781,7 +786,7 @@ class XiaomiAirHumidifier(XiaomiGenericDevice):
key, value in AVAILABLE_ATTRIBUTES_AIRHUMIDIFIER.items()}) key, value in AVAILABLE_ATTRIBUTES_AIRHUMIDIFIER.items()})
except DeviceException as ex: except DeviceException as ex:
self._state = None self._available = False
_LOGGER.error("Got exception while fetching the state: %s", ex) _LOGGER.error("Got exception while fetching the state: %s", ex)
def speed_list(self) -> list: def speed_list(self) -> list: