From 5ed69870677a7a4366c69e37b0077b9c8b455107 Mon Sep 17 00:00:00 2001 From: pavoni Date: Mon, 31 Aug 2015 11:07:52 +0100 Subject: [PATCH] Refactor wemo standby state slightly --- homeassistant/components/switch/__init__.py | 6 ++---- homeassistant/components/switch/wemo.py | 19 +++++++++++++++++-- homeassistant/const.py | 1 + 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/switch/__init__.py b/homeassistant/components/switch/__init__.py index 48d3e31e9b5..b6dd31b48c2 100644 --- a/homeassistant/components/switch/__init__.py +++ b/homeassistant/components/switch/__init__.py @@ -24,7 +24,6 @@ ENTITY_ID_FORMAT = DOMAIN + '.{}' ATTR_TODAY_MWH = "today_mwh" ATTR_CURRENT_POWER_MWH = "current_power_mwh" -ATTR_STANDBY_STATE = "standby_state" ATTR_SENSOR_STATE = "sensor_state" MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10) @@ -40,7 +39,6 @@ DISCOVERY_PLATFORMS = { PROP_TO_ATTR = { 'current_power_mwh': ATTR_CURRENT_POWER_MWH, 'today_power_mw': ATTR_TODAY_MWH, - 'standby_state': ATTR_STANDBY_STATE, 'sensor_state': ATTR_SENSOR_STATE } @@ -106,8 +104,8 @@ class SwitchDevice(ToggleEntity): return None @property - def standby_state(self): - """ Is the device on - or in standby. """ + def is_standby(self): + """ Is the device in standby. """ return None @property diff --git a/homeassistant/components/switch/wemo.py b/homeassistant/components/switch/wemo.py index 45e2fb19fd6..4c6cd2ed4d8 100644 --- a/homeassistant/components/switch/wemo.py +++ b/homeassistant/components/switch/wemo.py @@ -51,6 +51,16 @@ class WemoSwitch(SwitchDevice): """ Returns the name of the switch if any. """ return self.wemo.name + @property + def state(self): + """ Returns the state. """ + is_on = self.is_on + if not is_on: + return STATE_OFF + elif self.is_standby: + return STATE_STANDBY + return STATE_ON + @property def current_power_mwh(self): """ Current power usage in mwh. """ @@ -64,10 +74,15 @@ class WemoSwitch(SwitchDevice): return self.insight_params['todaymw'] @property - def standby_state(self): + def is_standby(self): """ Is the device on - or in standby. """ if self.insight_params: - return self.insight_params['standby_state'] + standby_state = self.insight_params['standby_state'] + # Standby is actually '8' but seems more defensive to check for the On and Off states + if standby_state == '1' or standby_state == '0' + return False + else + return True @property def sensor_state(self): diff --git a/homeassistant/const.py b/homeassistant/const.py index a3b9cc8d396..4ed110dcd93 100644 --- a/homeassistant/const.py +++ b/homeassistant/const.py @@ -46,6 +46,7 @@ STATE_CLOSED = 'closed' STATE_PLAYING = 'playing' STATE_PAUSED = 'paused' STATE_IDLE = 'idle' +STATE_STANDBY = 'standby' # #### STATE AND EVENT ATTRIBUTES #### # Contains current time for a TIME_CHANGED event