From 81ebdadcecffa55e132316393210cdfc53d00614 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Br=C3=A6dstrup?= Date: Tue, 20 Sep 2016 09:10:15 +0200 Subject: [PATCH] D-link switch library bump and error handling for W110 devices (#3386) (#3425) --- homeassistant/components/switch/dlink.py | 28 ++++++++++++++++++------ requirements_all.txt | 2 +- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/switch/dlink.py b/homeassistant/components/switch/dlink.py index 377826695a3..31b63db7f79 100644 --- a/homeassistant/components/switch/dlink.py +++ b/homeassistant/components/switch/dlink.py @@ -12,10 +12,10 @@ from homeassistant.components.switch import (SwitchDevice, PLATFORM_SCHEMA) from homeassistant.const import ( CONF_HOST, CONF_NAME, CONF_PASSWORD, CONF_USERNAME) import homeassistant.helpers.config_validation as cv -from homeassistant.const import TEMP_CELSIUS +from homeassistant.const import TEMP_CELSIUS, STATE_UNKNOWN REQUIREMENTS = ['https://github.com/LinuxChristian/pyW215/archive/' - 'v0.3.4.zip#pyW215==0.3.4'] + 'v0.3.5.zip#pyW215==0.3.5'] _LOGGER = logging.getLogger(__name__) @@ -72,11 +72,25 @@ class SmartPlugSwitch(SwitchDevice): @property def device_state_attributes(self): """Return the state attributes of the device.""" - ui_temp = self.units.temperature(int(self.smartplug.temperature), - TEMP_CELSIUS) - temperature = "{} {}".format(ui_temp, self.units.temperature_unit) - current_consumption = "{} W".format(self.smartplug.current_consumption) - total_consumption = "{} W".format(self.smartplug.total_consumption) + try: + ui_temp = self.units.temperature(int(self.smartplug.temperature), + TEMP_CELSIUS) + temperature = "%i %s" % \ + (ui_temp, self.units.temperature_unit) + except ValueError: + temperature = STATE_UNKNOWN + + try: + current_consumption = "%.2f W" % \ + float(self.smartplug.current_consumption) + except ValueError: + current_consumption = STATE_UNKNOWN + + try: + total_consumption = "%.1f W" % \ + float(self.smartplug.total_consumption) + except ValueError: + total_consumption = STATE_UNKNOWN attrs = { ATTR_CURRENT_CONSUMPTION: current_consumption, diff --git a/requirements_all.txt b/requirements_all.txt index 75d48828771..ae89ee793a1 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -137,7 +137,7 @@ hikvision==0.4 https://github.com/Danielhiversen/flux_led/archive/0.6.zip#flux_led==0.6 # homeassistant.components.switch.dlink -https://github.com/LinuxChristian/pyW215/archive/v0.3.4.zip#pyW215==0.3.4 +https://github.com/LinuxChristian/pyW215/archive/v0.3.5.zip#pyW215==0.3.5 # homeassistant.components.media_player.webostv # homeassistant.components.notify.webostv