mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 06:37:52 +00:00
Allow some failures before setting Xiaomi Miio MIOT air purifiers unavailable (#50755)
This commit is contained in:
parent
0fac3ccebc
commit
97559087b5
@ -551,7 +551,9 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||||||
|
|
||||||
if model in MODELS_PURIFIER_MIOT:
|
if model in MODELS_PURIFIER_MIOT:
|
||||||
air_purifier = AirPurifierMiot(host, token)
|
air_purifier = AirPurifierMiot(host, token)
|
||||||
entity = XiaomiAirPurifierMiot(name, air_purifier, config_entry, unique_id)
|
entity = XiaomiAirPurifierMiot(
|
||||||
|
name, air_purifier, config_entry, unique_id, allowed_failures=2
|
||||||
|
)
|
||||||
elif model.startswith("zhimi.airpurifier."):
|
elif model.startswith("zhimi.airpurifier."):
|
||||||
air_purifier = AirPurifier(host, token)
|
air_purifier = AirPurifier(host, token)
|
||||||
entity = XiaomiAirPurifier(name, air_purifier, config_entry, unique_id)
|
entity = XiaomiAirPurifier(name, air_purifier, config_entry, unique_id)
|
||||||
@ -769,9 +771,11 @@ class XiaomiGenericDevice(XiaomiMiioEntity, FanEntity):
|
|||||||
class XiaomiAirPurifier(XiaomiGenericDevice):
|
class XiaomiAirPurifier(XiaomiGenericDevice):
|
||||||
"""Representation of a Xiaomi Air Purifier."""
|
"""Representation of a Xiaomi Air Purifier."""
|
||||||
|
|
||||||
def __init__(self, name, device, entry, unique_id):
|
def __init__(self, name, device, entry, unique_id, allowed_failures=0):
|
||||||
"""Initialize the plug switch."""
|
"""Initialize the plug switch."""
|
||||||
super().__init__(name, device, entry, unique_id)
|
super().__init__(name, device, entry, unique_id)
|
||||||
|
self._allowed_failures = allowed_failures
|
||||||
|
self._failure = 0
|
||||||
|
|
||||||
if self._model == MODEL_AIRPURIFIER_PRO:
|
if self._model == MODEL_AIRPURIFIER_PRO:
|
||||||
self._device_features = FEATURE_FLAGS_AIRPURIFIER_PRO
|
self._device_features = FEATURE_FLAGS_AIRPURIFIER_PRO
|
||||||
@ -822,10 +826,24 @@ class XiaomiAirPurifier(XiaomiGenericDevice):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self._failure = 0
|
||||||
|
|
||||||
except DeviceException as ex:
|
except DeviceException as ex:
|
||||||
if self._available:
|
self._failure += 1
|
||||||
self._available = False
|
if self._failure < self._allowed_failures:
|
||||||
_LOGGER.error("Got exception while fetching the state: %s", ex)
|
_LOGGER.info(
|
||||||
|
"Got exception while fetching the state: %s, failure: %d",
|
||||||
|
ex,
|
||||||
|
self._failure,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
if self._available:
|
||||||
|
self._available = False
|
||||||
|
_LOGGER.error(
|
||||||
|
"Got exception while fetching the state: %s, failure: %d",
|
||||||
|
ex,
|
||||||
|
self._failure,
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def speed_list(self) -> list:
|
def speed_list(self) -> list:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user