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..d828e23464c 100644 --- a/homeassistant/components/switch/wemo.py +++ b/homeassistant/components/switch/wemo.py @@ -17,6 +17,12 @@ _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 +94,26 @@ 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']: + 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']: + 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 +148,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. """