From 6c5ceaf6863963486883521e749fa5f79c21b840 Mon Sep 17 00:00:00 2001 From: pavoni Date: Wed, 20 Jan 2016 11:06:08 +0000 Subject: [PATCH 1/5] Remove sensor state from switch and wemo --- homeassistant/components/switch/__init__.py | 7 --- homeassistant/components/switch/wemo.py | 49 ++++++++++++--------- 2 files changed, 27 insertions(+), 29 deletions(-) diff --git a/homeassistant/components/switch/__init__.py b/homeassistant/components/switch/__init__.py index 8fb930b6a59..944d16cf40b 100644 --- a/homeassistant/components/switch/__init__.py +++ b/homeassistant/components/switch/__init__.py @@ -30,7 +30,6 @@ 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) @@ -48,7 +47,6 @@ 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__) @@ -131,11 +129,6 @@ class SwitchDevice(ToggleEntity): """ 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 ed56305542d..c3b6d434b73 100644 --- a/homeassistant/components/switch/wemo.py +++ b/homeassistant/components/switch/wemo.py @@ -17,6 +17,11 @@ _LOGGER = logging.getLogger(__name__) _WEMO_SUBSCRIPTION_REGISTRY = None +ATTR_SENSOR_STATE = "sensor_state" +ATTR_SWITCH_MODE = "switch_mode" + +MAKER_SWITCH_MOMENTARY = "momentary" +MAKER_SWITCH_TOGGLE = "toggle" # pylint: disable=unused-argument, too-many-function-args def setup_platform(hass, config, add_devices_callback, discovery_info=None): @@ -88,6 +93,28 @@ class WemoSwitch(SwitchDevice): """ Returns the name of the switch if any. """ return self.wemo.name + @property + def state_attributes(self): + attr = super().state_attributes or {} + + if self.maker_params: + # Is the maker sensor on or off. + if self.maker_params['hassensor']: + # Note a state of 1 matches the WeMo app 'not triggered'! + if self.maker_params['sensorstate'] == '1': + attr[ATTR_SENSOR_STATE] = STATE_OFF + else: + attr[ATTR_SENSOR_STATE] = STATE_ON + + # Is the maker switch configured as toggle(0) or momentary (1). + if self.maker_params['switchmode']: + if self.maker_params['switchmode'] == '1': + attr[ATTR_SWITCH_MODE] = MAKER_SWITCH_MOMENTARY + else: + attr[ATTR_SWITCH_MODE] = MAKER_SWITCH_TOGGLE + + return attr + @property def state(self): """ Returns the state. """ @@ -122,28 +149,6 @@ class WemoSwitch(SwitchDevice): 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. """ From f4c3ac2a628b8d5b048facb455ff309c2daee37b Mon Sep 17 00:00:00 2001 From: pavoni Date: Wed, 20 Jan 2016 11:19:00 +0000 Subject: [PATCH 2/5] Tidy --- homeassistant/components/switch/wemo.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/switch/wemo.py b/homeassistant/components/switch/wemo.py index c3b6d434b73..f476cdd980b 100644 --- a/homeassistant/components/switch/wemo.py +++ b/homeassistant/components/switch/wemo.py @@ -109,9 +109,9 @@ class WemoSwitch(SwitchDevice): # Is the maker switch configured as toggle(0) or momentary (1). if self.maker_params['switchmode']: if self.maker_params['switchmode'] == '1': - attr[ATTR_SWITCH_MODE] = MAKER_SWITCH_MOMENTARY + attr[ATTR_SWITCH_MODE] = MAKER_SWITCH_MOMENTARY else: - attr[ATTR_SWITCH_MODE] = MAKER_SWITCH_TOGGLE + attr[ATTR_SWITCH_MODE] = MAKER_SWITCH_TOGGLE return attr From 0de9229d75491ee64663820da44bacc3b3e8c6a7 Mon Sep 17 00:00:00 2001 From: pavoni Date: Wed, 20 Jan 2016 11:25:20 +0000 Subject: [PATCH 3/5] More tidying. --- homeassistant/components/switch/wemo.py | 1 + 1 file changed, 1 insertion(+) diff --git a/homeassistant/components/switch/wemo.py b/homeassistant/components/switch/wemo.py index f476cdd980b..b44a21279ba 100644 --- a/homeassistant/components/switch/wemo.py +++ b/homeassistant/components/switch/wemo.py @@ -23,6 +23,7 @@ ATTR_SWITCH_MODE = "switch_mode" MAKER_SWITCH_MOMENTARY = "momentary" MAKER_SWITCH_TOGGLE = "toggle" + # pylint: disable=unused-argument, too-many-function-args def setup_platform(hass, config, add_devices_callback, discovery_info=None): """ Find and return WeMo switches. """ From 7ad5b3a17b02ca96f8872ee3470845082dae0b9c Mon Sep 17 00:00:00 2001 From: pavoni Date: Wed, 20 Jan 2016 19:13:29 +0000 Subject: [PATCH 4/5] Fix bug related to maker_param types --- homeassistant/components/switch/wemo.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/switch/wemo.py b/homeassistant/components/switch/wemo.py index b44a21279ba..72631244ea1 100644 --- a/homeassistant/components/switch/wemo.py +++ b/homeassistant/components/switch/wemo.py @@ -97,22 +97,21 @@ class WemoSwitch(SwitchDevice): @property def state_attributes(self): attr = super().state_attributes or {} - if self.maker_params: # Is the maker sensor on or off. + if self.entity_id == 'switch.hi_fi_systemline_sensor': if self.maker_params['hassensor']: # Note a state of 1 matches the WeMo app 'not triggered'! - if self.maker_params['sensorstate'] == '1': + if self.maker_params['sensorstate']: attr[ATTR_SENSOR_STATE] = STATE_OFF else: attr[ATTR_SENSOR_STATE] = STATE_ON # Is the maker switch configured as toggle(0) or momentary (1). if self.maker_params['switchmode']: - if self.maker_params['switchmode'] == '1': - attr[ATTR_SWITCH_MODE] = MAKER_SWITCH_MOMENTARY - else: - attr[ATTR_SWITCH_MODE] = MAKER_SWITCH_TOGGLE + attr[ATTR_SWITCH_MODE] = MAKER_SWITCH_MOMENTARY + else: + attr[ATTR_SWITCH_MODE] = MAKER_SWITCH_TOGGLE return attr From d2d421ca8ffbcbb015a7f2d3c1cd18e5ae576da4 Mon Sep 17 00:00:00 2001 From: pavoni Date: Wed, 20 Jan 2016 20:02:03 +0000 Subject: [PATCH 5/5] Remove ghost debug code. --- homeassistant/components/switch/wemo.py | 1 - 1 file changed, 1 deletion(-) diff --git a/homeassistant/components/switch/wemo.py b/homeassistant/components/switch/wemo.py index 72631244ea1..d828e23464c 100644 --- a/homeassistant/components/switch/wemo.py +++ b/homeassistant/components/switch/wemo.py @@ -99,7 +99,6 @@ class WemoSwitch(SwitchDevice): attr = super().state_attributes or {} if self.maker_params: # Is the maker sensor on or off. - if self.entity_id == 'switch.hi_fi_systemline_sensor': if self.maker_params['hassensor']: # Note a state of 1 matches the WeMo app 'not triggered'! if self.maker_params['sensorstate']: