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

+9 -2
View File
@@ -18,6 +18,7 @@ PARALLEL_UPDATES = 0
_LOGGER = logging.getLogger(__name__)
# The WEMO_ constants below come from pywemo itself
ATTR_SENSOR_STATE = "sensor_state"
ATTR_SWITCH_MODE = "switch_mode"
ATTR_CURRENT_STATE_DETAIL = "state_detail"
@@ -191,19 +192,25 @@ class WemoSwitch(SwitchEntity):
def turn_on(self, **kwargs):
"""Turn the switch on."""
try:
self.wemo.on()
if self.wemo.on():
self._state = 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 switch off."""
try:
self.wemo.off()
if self.wemo.off():
self._state = 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()
async def async_added_to_hass(self):
"""Wemo switch added to Home Assistant."""
# Define inside async context so we know our event loop