mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 19:57:07 +00:00
Use _attr_should_poll in xiaomi_aqara entities (#77197)
* Use _attr_should_poll in xiaomi_aqara entities * Adjust switch
This commit is contained in:
parent
671f129317
commit
a40ddb5e83
@ -225,6 +225,8 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
class XiaomiDevice(Entity):
|
class XiaomiDevice(Entity):
|
||||||
"""Representation a base Xiaomi device."""
|
"""Representation a base Xiaomi device."""
|
||||||
|
|
||||||
|
_attr_should_poll = False
|
||||||
|
|
||||||
def __init__(self, device, device_type, xiaomi_hub, config_entry):
|
def __init__(self, device, device_type, xiaomi_hub, config_entry):
|
||||||
"""Initialize the Xiaomi device."""
|
"""Initialize the Xiaomi device."""
|
||||||
self._state = None
|
self._state = None
|
||||||
@ -309,11 +311,6 @@ class XiaomiDevice(Entity):
|
|||||||
"""Return True if entity is available."""
|
"""Return True if entity is available."""
|
||||||
return self._is_available
|
return self._is_available
|
||||||
|
|
||||||
@property
|
|
||||||
def should_poll(self):
|
|
||||||
"""Return the polling state. No polling needed."""
|
|
||||||
return False
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self):
|
def extra_state_attributes(self):
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
|
@ -140,15 +140,9 @@ class XiaomiBinarySensor(XiaomiDevice, BinarySensorEntity):
|
|||||||
"""Initialize the XiaomiSmokeSensor."""
|
"""Initialize the XiaomiSmokeSensor."""
|
||||||
self._data_key = data_key
|
self._data_key = data_key
|
||||||
self._device_class = device_class
|
self._device_class = device_class
|
||||||
self._should_poll = False
|
|
||||||
self._density = 0
|
self._density = 0
|
||||||
super().__init__(device, name, xiaomi_hub, config_entry)
|
super().__init__(device, name, xiaomi_hub, config_entry)
|
||||||
|
|
||||||
@property
|
|
||||||
def should_poll(self):
|
|
||||||
"""Return True if entity has to be polled for state."""
|
|
||||||
return self._should_poll
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
"""Return true if sensor is on."""
|
"""Return true if sensor is on."""
|
||||||
@ -340,7 +334,7 @@ class XiaomiDoorSensor(XiaomiBinarySensor, RestoreEntity):
|
|||||||
|
|
||||||
def parse_data(self, data, raw_data):
|
def parse_data(self, data, raw_data):
|
||||||
"""Parse data sent by gateway."""
|
"""Parse data sent by gateway."""
|
||||||
self._should_poll = False
|
self._attr_should_poll = False
|
||||||
if NO_CLOSE in data: # handle push from the hub
|
if NO_CLOSE in data: # handle push from the hub
|
||||||
self._open_since = data[NO_CLOSE]
|
self._open_since = data[NO_CLOSE]
|
||||||
return True
|
return True
|
||||||
@ -350,7 +344,7 @@ class XiaomiDoorSensor(XiaomiBinarySensor, RestoreEntity):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
if value == "open":
|
if value == "open":
|
||||||
self._should_poll = True
|
self._attr_should_poll = True
|
||||||
if self._state:
|
if self._state:
|
||||||
return False
|
return False
|
||||||
self._state = True
|
self._state = True
|
||||||
@ -388,14 +382,14 @@ class XiaomiWaterLeakSensor(XiaomiBinarySensor):
|
|||||||
|
|
||||||
def parse_data(self, data, raw_data):
|
def parse_data(self, data, raw_data):
|
||||||
"""Parse data sent by gateway."""
|
"""Parse data sent by gateway."""
|
||||||
self._should_poll = False
|
self._attr_should_poll = False
|
||||||
|
|
||||||
value = data.get(self._data_key)
|
value = data.get(self._data_key)
|
||||||
if value is None:
|
if value is None:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if value == "leak":
|
if value == "leak":
|
||||||
self._should_poll = True
|
self._attr_should_poll = True
|
||||||
if self._state:
|
if self._state:
|
||||||
return False
|
return False
|
||||||
self._state = True
|
self._state = True
|
||||||
|
@ -149,6 +149,8 @@ class XiaomiGenericSwitch(XiaomiDevice, SwitchEntity):
|
|||||||
self._load_power = None
|
self._load_power = None
|
||||||
self._power_consumed = None
|
self._power_consumed = None
|
||||||
self._supports_power_consumption = supports_power_consumption
|
self._supports_power_consumption = supports_power_consumption
|
||||||
|
# Polling needed for Zigbee plug only.
|
||||||
|
self._attr_should_poll = supports_power_consumption
|
||||||
super().__init__(device, name, xiaomi_hub, config_entry)
|
super().__init__(device, name, xiaomi_hub, config_entry)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -177,11 +179,6 @@ class XiaomiGenericSwitch(XiaomiDevice, SwitchEntity):
|
|||||||
attrs.update(super().extra_state_attributes)
|
attrs.update(super().extra_state_attributes)
|
||||||
return attrs
|
return attrs
|
||||||
|
|
||||||
@property
|
|
||||||
def should_poll(self):
|
|
||||||
"""Return the polling state. Polling needed for Zigbee plug only."""
|
|
||||||
return self._supports_power_consumption
|
|
||||||
|
|
||||||
def turn_on(self, **kwargs):
|
def turn_on(self, **kwargs):
|
||||||
"""Turn the switch on."""
|
"""Turn the switch on."""
|
||||||
if self._write_to_hub(self._sid, **{self._data_key: "on"}):
|
if self._write_to_hub(self._sid, **{self._data_key: "on"}):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user