D-link switch library bump and error handling for W110 devices (#3386) (#3425)

pull/3456/merge
Christian Brædstrup 2016-09-20 09:10:15 +02:00 committed by Paulus Schoutsen
parent de5bd26050
commit 81ebdadcec
2 changed files with 22 additions and 8 deletions

View File

@ -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,

View File

@ -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