mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Zha switch schedule update state (#16621)
* switch.zha: Schedule state update. if turning switch On or Off operation was successful, then schedule state update * switch.zha: Update debug logging.
This commit is contained in:
parent
aeaf694552
commit
9fdf123a2f
@ -44,7 +44,10 @@ class Switch(zha.Entity, SwitchDevice):
|
|||||||
|
|
||||||
def attribute_updated(self, attribute, value):
|
def attribute_updated(self, attribute, value):
|
||||||
"""Handle attribute update from device."""
|
"""Handle attribute update from device."""
|
||||||
_LOGGER.debug("Attribute updated: %s %s %s", self, attribute, value)
|
cluster = self._endpoint.on_off
|
||||||
|
attr_name = cluster.attributes.get(attribute, [attribute])[0]
|
||||||
|
_LOGGER.debug("%s: Attribute '%s' on cluster '%s' updated to %s",
|
||||||
|
self.entity_id, attr_name, cluster.ep_attribute, value)
|
||||||
if attribute == self.value_attribute:
|
if attribute == self.value_attribute:
|
||||||
self._state = value
|
self._state = value
|
||||||
self.async_schedule_update_ha_state()
|
self.async_schedule_update_ha_state()
|
||||||
@ -65,23 +68,29 @@ class Switch(zha.Entity, SwitchDevice):
|
|||||||
"""Turn the entity on."""
|
"""Turn the entity on."""
|
||||||
from zigpy.exceptions import DeliveryError
|
from zigpy.exceptions import DeliveryError
|
||||||
try:
|
try:
|
||||||
await self._endpoint.on_off.on()
|
res = await self._endpoint.on_off.on()
|
||||||
|
_LOGGER.debug("%s: turned 'on': %s", self.entity_id, res[1])
|
||||||
except DeliveryError as ex:
|
except DeliveryError as ex:
|
||||||
_LOGGER.error("Unable to turn the switch on: %s", ex)
|
_LOGGER.error("%s: Unable to turn the switch on: %s",
|
||||||
|
self.entity_id, ex)
|
||||||
return
|
return
|
||||||
|
|
||||||
self._state = 1
|
self._state = 1
|
||||||
|
self.async_schedule_update_ha_state()
|
||||||
|
|
||||||
async def async_turn_off(self, **kwargs):
|
async def async_turn_off(self, **kwargs):
|
||||||
"""Turn the entity off."""
|
"""Turn the entity off."""
|
||||||
from zigpy.exceptions import DeliveryError
|
from zigpy.exceptions import DeliveryError
|
||||||
try:
|
try:
|
||||||
await self._endpoint.on_off.off()
|
res = await self._endpoint.on_off.off()
|
||||||
|
_LOGGER.debug("%s: turned 'off': %s", self.entity_id, res[1])
|
||||||
except DeliveryError as ex:
|
except DeliveryError as ex:
|
||||||
_LOGGER.error("Unable to turn the switch off: %s", ex)
|
_LOGGER.error("%s: Unable to turn the switch off: %s",
|
||||||
|
self.entity_id, ex)
|
||||||
return
|
return
|
||||||
|
|
||||||
self._state = 0
|
self._state = 0
|
||||||
|
self.async_schedule_update_ha_state()
|
||||||
|
|
||||||
async def async_update(self):
|
async def async_update(self):
|
||||||
"""Retrieve latest state."""
|
"""Retrieve latest state."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user