Update Wemo state when changing state (#36647)

This commit is contained in:
Adam Belebczuk authored and GitHub committed 2020-06-16 21:14:04 +02:00
1 parent a6a6a7b69c
commit fe03c9da68
5 files changed
+42 -9

No files matched your search

+22 -5
View File
@@ -32,6 +32,10 @@ SUPPORT_WEMO = (
SUPPORT_BRIGHTNESS | SUPPORT_COLOR_TEMP | SUPPORT_COLOR | SUPPORT_TRANSITION
)
# The WEMO_ constants below come from pywemo itself
WEMO_ON = 1
WEMO_OFF = 0
async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up WeMo lights."""
@@ -175,21 +179,27 @@ class WemoLight(LightEntity):
if color_temp is not None:
self.wemo.set_temperature(mireds=color_temp, transition=transition_time)
self.wemo.turn_on(**turn_on_kwargs)
if self.wemo.turn_on(**turn_on_kwargs):
self._state["onoff"] = WEMO_ON
except ActionException as err:
_LOGGER.warning("Error while turning on device %s (%s)", self.name, err)
self._available = False
self.schedule_update_ha_state()
def turn_off(self, **kwargs):
"""Turn the light off."""
transition_time = int(kwargs.get(ATTR_TRANSITION, 0))
try:
self.wemo.turn_off(transition=transition_time)
if self.wemo.turn_off(transition=transition_time):
self._state["onoff"] = WEMO_OFF
except ActionException as err:
_LOGGER.warning("Error while turning off device %s (%s)", self.name, err)
self._available = False
self.schedule_update_ha_state()
def _update(self, force_update=True):
"""Synchronize state with bridge."""
try:
@@ -200,7 +210,7 @@ class WemoLight(LightEntity):
self._available = False
self.wemo.reconnect_with_device()
else:
self._is_on = self._state.get("onoff") != 0
self._is_on = self._state.get("onoff") != WEMO_OFF
self._brightness = self._state.get("level", 255)
self._color_temp = self._state.get("temperature_mireds")
self._available = True
@@ -355,20 +365,27 @@ class WemoDimmer(LightEntity):
brightness = 255
try:
self.wemo.on()
if self.wemo.on():
self._state = WEMO_ON
self.wemo.set_brightness(brightness)
except ActionException as err:
_LOGGER.warning("Error while turning on device %s (%s)", self.name, err)
self._available = False
self.schedule_update_ha_state()
def turn_off(self, **kwargs):
"""Turn the dimmer off."""
try:
self.wemo.off()
if self.wemo.off():
self._state = WEMO_OFF
except ActionException as err:
_LOGGER.warning("Error while turning on device %s (%s)", self.name, err)
self._available = False
self.schedule_update_ha_state()
@property
def available(self):
"""Return if dimmer is available."""