8000 Remove sensor state by pavoni · Pull Request #940 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Remove sensor state #940

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions homeassistant/components/switch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

ATTR_TODAY_MWH = "today_mwh"
ATTR_CURRENT_POWER_MWH = "current_power_mwh"
ATTR_SENSOR_STATE = "sensor_state"

MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10)

Expand All @@ -48,7 +47,6 @@
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__)
Expand Down Expand Up @@ -131,11 +129,6 @@ 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. """
Expand Down
48 changes: 26 additions & 22 deletions homeassistant/components/switch/wemo.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@

_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):
Expand Down Expand Up @@ -88,6 +94,26 @@ def name(self):
""" 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonder if boolean would me more appropriate? (although backwards incompatible)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very happy to switch if you wish.

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. """
Expand Down Expand Up @@ -122,28 +148,6 @@ def is_standby(self):
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. """
Expand Down
0