diff --git a/homeassistant/components/switch/__init__.py b/homeassistant/components/switch/__init__.py index 424d4505d39..b6dd31b48c2 100644 --- a/homeassistant/components/switch/__init__.py +++ b/homeassistant/components/switch/__init__.py @@ -24,6 +24,7 @@ ENTITY_ID_FORMAT = DOMAIN + '.{}' ATTR_TODAY_MWH = "today_mwh" ATTR_CURRENT_POWER_MWH = "current_power_mwh" +ATTR_SENSOR_STATE = "sensor_state" MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10) @@ -38,6 +39,7 @@ DISCOVERY_PLATFORMS = { PROP_TO_ATTR = { 'current_power_mwh': ATTR_CURRENT_POWER_MWH, 'today_power_mw': ATTR_TODAY_MWH, + 'sensor_state': ATTR_SENSOR_STATE } _LOGGER = logging.getLogger(__name__) @@ -101,6 +103,16 @@ class SwitchDevice(ToggleEntity): """ Today total power usage in mw. """ return None + @property + def is_standby(self): + """ Is the device in standby. """ + return None + + @property + def sensor_state(self): + """ Is the sensor on or off. """ + return None + @property def device_state_attributes(self): """ Returns device specific state attributes. """ diff --git a/homeassistant/components/switch/wemo.py b/homeassistant/components/switch/wemo.py index 2d6e25b296b..98c6ed5aa01 100644 --- a/homeassistant/components/switch/wemo.py +++ b/homeassistant/components/switch/wemo.py @@ -7,8 +7,9 @@ Support for WeMo switches. import logging from homeassistant.components.switch import SwitchDevice +from homeassistant.const import STATE_ON, STATE_OFF, STATE_STANDBY -REQUIREMENTS = ['pywemo==0.2'] +REQUIREMENTS = ['pywemo==0.3'] # pylint: disable=unused-argument @@ -39,6 +40,7 @@ class WemoSwitch(SwitchDevice): def __init__(self, wemo): self.wemo = wemo self.insight_params = None + self.maker_params = None @property def unique_id(self): @@ -50,6 +52,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. """ @@ -62,6 +74,40 @@ class WemoSwitch(SwitchDevice): if self.insight_params: return self.insight_params['todaymw'] + @property + def is_standby(self): + """ Is the device on - or in standby. """ + if self.insight_params: + standby_state = self.insight_params['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): + """ Is the sensor on or off. """ + if self.maker_params and self.has_sensor: + # Note a state of 1 matches the WeMo app 'not triggered'! + if self.maker_params['sensorstate']: + return STATE_OFF + else: + return STATE_ON + + @property + def switch_mode(self): + """ Is the switch configured as toggle(0) or momentary (1). """ + if self.maker_params: + return self.maker_params['switchmode'] + + @property + def has_sensor(self): + """ Is the sensor present? """ + if self.maker_params: + return self.maker_params['hassensor'] + @property def is_on(self): """ True if switch is on. """ @@ -78,5 +124,8 @@ class WemoSwitch(SwitchDevice): def update(self): """ Update WeMo state. """ self.wemo.get_state(True) - if self.wemo.model.startswith('Belkin Insight'): + if self.wemo.model_name == 'Insight': self.insight_params = self.wemo.insight_params + self.insight_params['standby_state'] = self.wemo.get_standby_state + elif self.wemo.model_name == 'Maker': + self.maker_params = self.wemo.maker_params 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 diff --git a/requirements_all.txt b/requirements_all.txt index 9798a95f030..ce74a8475cd 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -89,7 +89,7 @@ pynetgear==0.3 netdisco==0.3 # Wemo (switch.wemo) -pywemo==0.2 +pywemo==0.3 # Wink (*.wink) https://github.com/balloob/python-wink/archive/c2b700e8ca866159566ecf5e644d9c297f69f257.zip