Bump PyWeMo version to 0.4.43 (#35693)
* PyWeMo version bump to 0.4.43 Changes necessary to safely upgrade to pyWeMo 0.4.43. This includes catching ActionExceptions that may be thrown by pyWeMo when it is unable to interact with a physical device. * Black formatting fix * Fix isort issues * Code review changes * More code review fixes * Linting fix * Undo dict.get change * Change a couple instances of dict[key] to dict.get
This commit is contained in:
1 parent
b42a197293
commit
5104b79b4b
6 files changed
+144
-62
No files matched your search
@@ -4,6 +4,7 @@ from datetime import datetime, timedelta
|
||||
import logging
|
||||
|
||||
import async_timeout
|
||||
from pywemo.ouimeaux_device.api.service import ActionException
|
||||
|
||||
from homeassistant.components.switch import SwitchEntity
|
||||
from homeassistant.const import STATE_OFF, STATE_ON, STATE_STANDBY, STATE_UNKNOWN
|
||||
@@ -93,9 +94,9 @@ class WemoSwitch(SwitchEntity):
|
||||
def device_info(self):
|
||||
"""Return the device info."""
|
||||
return {
|
||||
"name": self.wemo.name,
|
||||
"identifiers": {(WEMO_DOMAIN, self.wemo.serialnumber)},
|
||||
"model": self.wemo.model_name,
|
||||
"name": self._name,
|
||||
"identifiers": {(WEMO_DOMAIN, self._serialnumber)},
|
||||
"model": self._model_name,
|
||||
"manufacturer": "Belkin",
|
||||
}
|
||||
|
||||
@@ -189,11 +190,19 @@ class WemoSwitch(SwitchEntity):
|
||||
|
||||
def turn_on(self, **kwargs):
|
||||
"""Turn the switch on."""
|
||||
self.wemo.on()
|
||||
try:
|
||||
self.wemo.on()
|
||||
except ActionException as err:
|
||||
_LOGGER.warning("Error while turning on device %s (%s)", self.name, err)
|
||||
self._available = False
|
||||
|
||||
def turn_off(self, **kwargs):
|
||||
"""Turn the switch off."""
|
||||
self.wemo.off()
|
||||
try:
|
||||
self.wemo.off()
|
||||
except ActionException as err:
|
||||
_LOGGER.warning("Error while turning off device %s (%s)", self.name, err)
|
||||
self._available = False
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
"""Wemo switch added to Home Assistant."""
|
||||
@@ -245,6 +254,7 @@ class WemoSwitch(SwitchEntity):
|
||||
if not self._available:
|
||||
_LOGGER.info("Reconnected to %s", self.name)
|
||||
self._available = True
|
||||
except AttributeError as err:
|
||||
except (AttributeError, ActionException) as err:
|
||||
_LOGGER.warning("Could not update status for %s (%s)", self.name, err)
|
||||
self._available = False
|
||||
self.wemo.reconnect_with_device()
|
||||
Reference in new issue
Block a user