8000 Added super attributes to Wink binary sensors by w1ll1am23 · Pull Request #9824 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Added super attributes to Wink binary sensors #9824

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
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
44 changes: 24 additions & 20 deletions homeassistant/components/binary_sensor/wink.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

from homeassistant.components.binary_sensor import BinarySensorDevice
from homeassistant.components.wink import WinkDevice, DOMAIN
from homeassistant.helpers.entity import Entity

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -87,7 +86,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
_LOGGER.info("Device isn't a sensor, skipping")


class WinkBinarySensorDevice(WinkDevice, BinarySensorDevice, Entity):
class WinkBinarySensorDevice(WinkDevice, BinarySensorDevice):
"""Representation of a Wink binary sensor."""

def __init__(self, wink, hass):
Expand Down Expand Up @@ -117,16 +116,21 @@ def device_class(self):
"""Return the class of this sensor, from DEVICE_CLASSES."""
return SENSOR_TYPES.get(self.capability)

@property
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this happens automatically - you don't need to define it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I tried that and got some error from the other sensor that inherit from this about super not having that property.

Copy link
Member

Choose a reason for hiding this comment

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

Was it a lint error? In that case you can disable that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No it caused a stack trace. The subsensor that inherit from WinkBinarySensorDevice were blowing up on the call to super stating WinkBinarySensorDevice doesn't have a device_state_attributes property. Is it possible to call the supers super method because that is basically what I need.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, sorry, of course. Every target of the super call needs to have the method/property in question. Target is defined in the method resolution order of the class.

def device_state_attributes(self):
"""Return the state attributes."""
return super().device_state_attributes


class WinkSmokeDetector(WinkBinarySensorDevice):
"""Representation of a Wink Smoke detector."""

@property
def device_state_attributes(self):
"""Return the state attributes."""
return {
'test_activated': self.wink.test_activated()
}
_attributes = super().device_state_attributes
_attributes['test_activated'] = self.wink.test_activated()
return _attributes


class WinkHub(WinkBinarySensorDevice):
Expand All @@ -135,11 +139,11 @@ class WinkHub(WinkBinarySensorDevice):
@property
def device_state_attributes(self):
"""Return the state attributes."""
return {
'update_needed': self.wink.update_needed(),
'firmware_version': self.wink.firmware_version(),
'pairing_mode': self.wink.pairing_mode()
}
_attributes = super().device_state_attributes
_attributes['update_needed'] = self.wink.update_needed()
_attributes['firmware_version'] = self.wink.firmware_version()
_attributes['pairing_mode'] = self.wink.pairing_mode()
return _attributes


class WinkRemote(WinkBinarySensorDevice):
Expand All @@ -148,12 +152,12 @@ class WinkRemote(WinkBinarySensorDevice):
@property
def device_state_attributes(self):
"""Return the state attributes."""
return {
'button_on_pressed': self.wink.button_on_pressed(),
'button_off_pressed': self.wink.button_off_pressed(),
'button_up_pressed': self.wink.button_up_pressed(),
'button_down_pressed': self.wink.button_down_pressed()
}
_attributes = super().device_state_attributes
_attributes['button_on_pressed'] = self.wink.button_on_pressed()
_attributes['button_off_pressed'] = self.wink.button_off_pressed()
_attributes['button_up_pressed'] = self.wink.button_up_pressed()
_attributes['button_down_pressed'] = self.wink.button_down_pressed()
return _attributes

@property
def device_class(self):
Expand All @@ -167,10 +171,10 @@ class WinkButton(WinkBinarySensorDevice):
@property
def device_state_attributes(self):
"""Return the state attributes."""
return {
'pressed': self.wink.pressed(),
'long_pressed': self.wink.long_pressed()
}
_attributes = super().device_state_attributes
_attributes['pressed'] = self.wink.pressed()
_attributes['long_pressed'] = self.wink.long_pressed()
return _attributes


class WinkGang(WinkBinarySensorDevice):
Expand Down
0