Clean up state_attributes vs device_state_attributes
This commit is contained in:
parent
681b84e1bd
commit
f08b77dc4c
23 changed files with 66 additions and 138 deletions
|
@ -300,11 +300,6 @@ class Light(ToggleEntity):
|
||||||
""" CT color value in mirads. """
|
""" CT color value in mirads. """
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
|
||||||
def device_state_attributes(self):
|
|
||||||
""" Returns device specific state attributes. """
|
|
||||||
return None
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state_attributes(self):
|
def state_attributes(self):
|
||||||
""" Returns optional state attributes. """
|
""" Returns optional state attributes. """
|
||||||
|
@ -322,9 +317,4 @@ class Light(ToggleEntity):
|
||||||
data[ATTR_XY_COLOR][0], data[ATTR_XY_COLOR][1],
|
data[ATTR_XY_COLOR][0], data[ATTR_XY_COLOR][1],
|
||||||
data[ATTR_BRIGHTNESS])
|
data[ATTR_BRIGHTNESS])
|
||||||
|
|
||||||
device_attr = self.device_state_attributes
|
|
||||||
|
|
||||||
if device_attr is not None:
|
|
||||||
data.update(device_attr)
|
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
|
@ -71,13 +71,9 @@ class VeraLight(VeraSwitch):
|
||||||
""" Represents a Vera Light, including dimmable. """
|
""" Represents a Vera Light, including dimmable. """
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state_attributes(self):
|
def brightness(self):
|
||||||
attr = super().state_attributes or {}
|
"""Brightness of the light."""
|
||||||
|
return self.vera_device.get_brightness()
|
||||||
if self.vera_device.is_dimmable:
|
|
||||||
attr[ATTR_BRIGHTNESS] = self.vera_device.get_brightness()
|
|
||||||
|
|
||||||
return attr
|
|
||||||
|
|
||||||
def turn_on(self, **kwargs):
|
def turn_on(self, **kwargs):
|
||||||
if ATTR_BRIGHTNESS in kwargs and self.vera_device.is_dimmable:
|
if ATTR_BRIGHTNESS in kwargs and self.vera_device.is_dimmable:
|
||||||
|
|
|
@ -37,6 +37,11 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||||
class WinkLight(WinkToggleDevice):
|
class WinkLight(WinkToggleDevice):
|
||||||
""" Represents a Wink light. """
|
""" Represents a Wink light. """
|
||||||
|
|
||||||
|
@property
|
||||||
|
def brightness(self):
|
||||||
|
"""Brightness of the light."""
|
||||||
|
return int(self.wink.brightness() * 255)
|
||||||
|
|
||||||
# pylint: disable=too-few-public-methods
|
# pylint: disable=too-few-public-methods
|
||||||
def turn_on(self, **kwargs):
|
def turn_on(self, **kwargs):
|
||||||
""" Turns the switch on. """
|
""" Turns the switch on. """
|
||||||
|
@ -47,15 +52,3 @@ class WinkLight(WinkToggleDevice):
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.wink.set_state(True)
|
self.wink.set_state(True)
|
||||||
|
|
||||||
@property
|
|
||||||
def state_attributes(self):
|
|
||||||
attr = super().state_attributes
|
|
||||||
|
|
||||||
if self.is_on:
|
|
||||||
brightness = self.wink.brightness()
|
|
||||||
|
|
||||||
if brightness is not None:
|
|
||||||
attr[ATTR_BRIGHTNESS] = int(brightness * 255)
|
|
||||||
|
|
||||||
return attr
|
|
||||||
|
|
|
@ -425,11 +425,6 @@ class MediaPlayerDevice(Entity):
|
||||||
""" Flags of media commands that are supported. """
|
""" Flags of media commands that are supported. """
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
@property
|
|
||||||
def device_state_attributes(self):
|
|
||||||
""" Extra attributes a device wants to expose. """
|
|
||||||
return None
|
|
||||||
|
|
||||||
def turn_on(self):
|
def turn_on(self):
|
||||||
""" turn the media player on. """
|
""" turn the media player on. """
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
@ -546,9 +541,4 @@ class MediaPlayerDevice(Entity):
|
||||||
if self.media_image_url:
|
if self.media_image_url:
|
||||||
state_attr[ATTR_ENTITY_PICTURE] = self.media_image_url
|
state_attr[ATTR_ENTITY_PICTURE] = self.media_image_url
|
||||||
|
|
||||||
device_attr = self.device_state_attributes
|
|
||||||
|
|
||||||
if device_attr:
|
|
||||||
state_attr.update(device_attr)
|
|
||||||
|
|
||||||
return state_attr
|
return state_attr
|
||||||
|
|
|
@ -54,7 +54,7 @@ class CpuSpeedSensor(Entity):
|
||||||
return self._unit_of_measurement
|
return self._unit_of_measurement
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state_attributes(self):
|
def device_state_attributes(self):
|
||||||
""" Returns the state attributes. """
|
""" Returns the state attributes. """
|
||||||
if self.info is not None:
|
if self.info is not None:
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -46,7 +46,7 @@ class DemoSensor(Entity):
|
||||||
return self._unit_of_measurement
|
return self._unit_of_measurement
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state_attributes(self):
|
def device_state_attributes(self):
|
||||||
""" Returns the state attributes. """
|
""" Returns the state attributes. """
|
||||||
if self._battery:
|
if self._battery:
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -161,34 +161,24 @@ class MySensorsSensor(Entity):
|
||||||
@property
|
@property
|
||||||
def device_state_attributes(self):
|
def device_state_attributes(self):
|
||||||
"""Return device specific state attributes."""
|
"""Return device specific state attributes."""
|
||||||
set_req = self.gateway.const.SetReq
|
attr = {
|
||||||
device_attr = {}
|
|
||||||
for value_type, value in self._values.items():
|
|
||||||
if value_type != self.value_type:
|
|
||||||
try:
|
|
||||||
device_attr[set_req(value_type).name] = value
|
|
||||||
except ValueError:
|
|
||||||
_LOGGER.error('value_type %s is not valid for mysensors '
|
|
||||||
'version %s', value_type,
|
|
||||||
self.gateway.version)
|
|
||||||
return device_attr
|
|
||||||
|
|
||||||
@property
|
|
||||||
def state_attributes(self):
|
|
||||||
"""Return the state attributes."""
|
|
||||||
data = {
|
|
||||||
mysensors.ATTR_PORT: self.gateway.port,
|
mysensors.ATTR_PORT: self.gateway.port,
|
||||||
mysensors.ATTR_NODE_ID: self.node_id,
|
mysensors.ATTR_NODE_ID: self.node_id,
|
||||||
mysensors.ATTR_CHILD_ID: self.child_id,
|
mysensors.ATTR_CHILD_ID: self.child_id,
|
||||||
ATTR_BATTERY_LEVEL: self.battery_level,
|
ATTR_BATTERY_LEVEL: self.battery_level,
|
||||||
}
|
}
|
||||||
|
|
||||||
device_attr = self.device_state_attributes
|
set_req = self.gateway.const.SetReq
|
||||||
|
|
||||||
if device_attr is not None:
|
for value_type, value in self._values.items():
|
||||||
data.update(device_attr)
|
if value_type != self.value_type:
|
||||||
|
try:
|
||||||
return data
|
attr[set_req(value_type).name] = value
|
||||||
|
except ValueError:
|
||||||
|
_LOGGER.error('value_type %s is not valid for mysensors '
|
||||||
|
'version %s', value_type,
|
||||||
|
self.gateway.version)
|
||||||
|
return attr
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Update the controller with the latest values from a sensor."""
|
"""Update the controller with the latest values from a sensor."""
|
||||||
|
|
|
@ -87,7 +87,7 @@ class RfxtrxSensor(Entity):
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state_attributes(self):
|
def device_state_attributes(self):
|
||||||
return self.event.values
|
return self.event.values
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
@ -75,7 +75,7 @@ class SwissPublicTransportSensor(Entity):
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state_attributes(self):
|
def device_state_attributes(self):
|
||||||
""" Returns the state attributes. """
|
""" Returns the state attributes. """
|
||||||
if self._times is not None:
|
if self._times is not None:
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -113,8 +113,8 @@ class TelldusLiveSensor(Entity):
|
||||||
return self._value_as_humidity
|
return self._value_as_humidity
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state_attributes(self):
|
def device_state_attributes(self):
|
||||||
attrs = dict()
|
attrs = {}
|
||||||
if self._battery_level is not None:
|
if self._battery_level is not None:
|
||||||
attrs[ATTR_BATTERY_LEVEL] = self._battery_level
|
attrs[ATTR_BATTERY_LEVEL] = self._battery_level
|
||||||
if self._last_updated is not None:
|
if self._last_updated is not None:
|
||||||
|
|
|
@ -67,7 +67,7 @@ class TwitchSensor(Entity):
|
||||||
self._state = STATE_OFFLINE
|
self._state = STATE_OFFLINE
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state_attributes(self):
|
def device_state_attributes(self):
|
||||||
""" Returns the state attributes. """
|
""" Returns the state attributes. """
|
||||||
if self._state == STATE_STREAMING:
|
if self._state == STATE_STREAMING:
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -118,7 +118,7 @@ class VeraSensor(Entity):
|
||||||
return '%'
|
return '%'
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state_attributes(self):
|
def device_state_attributes(self):
|
||||||
attr = {}
|
attr = {}
|
||||||
if self.vera_device.has_battery:
|
if self.vera_device.has_battery:
|
||||||
attr[ATTR_BATTERY_LEVEL] = self.vera_device.battery_level + '%'
|
attr[ATTR_BATTERY_LEVEL] = self.vera_device.battery_level + '%'
|
||||||
|
|
|
@ -100,7 +100,7 @@ class YrSensor(Entity):
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state_attributes(self):
|
def device_state_attributes(self):
|
||||||
""" Returns state attributes. """
|
""" Returns state attributes. """
|
||||||
data = {
|
data = {
|
||||||
'about': "Weather forecast from yr.no, delivered by the"
|
'about': "Weather forecast from yr.no, delivered by the"
|
||||||
|
|
|
@ -111,11 +111,6 @@ class ZWaveSensor(ZWaveDeviceEntity, Entity):
|
||||||
""" Returns the state of the sensor. """
|
""" Returns the state of the sensor. """
|
||||||
return self._value.data
|
return self._value.data
|
||||||
|
|
||||||
@property
|
|
||||||
def state_attributes(self):
|
|
||||||
""" Returns optional state attributes. """
|
|
||||||
return self.device_state_attributes
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
return self._value.units
|
return self._value.units
|
||||||
|
|
|
@ -129,11 +129,6 @@ class SwitchDevice(ToggleEntity):
|
||||||
""" Is the device in standby. """
|
""" Is the device in standby. """
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
|
||||||
def device_state_attributes(self):
|
|
||||||
""" Returns device specific state attributes. """
|
|
||||||
return None
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state_attributes(self):
|
def state_attributes(self):
|
||||||
""" Returns optional state attributes. """
|
""" Returns optional state attributes. """
|
||||||
|
@ -144,9 +139,4 @@ class SwitchDevice(ToggleEntity):
|
||||||
if value:
|
if value:
|
||||||
data[attr] = value
|
data[attr] = value
|
||||||
|
|
||||||
device_attr = self.device_state_attributes
|
|
||||||
|
|
||||||
if device_attr is not None:
|
|
||||||
data.update(device_attr)
|
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
|
@ -114,8 +114,8 @@ class MfiSwitch(SwitchDevice):
|
||||||
return int(self._port.data.get('active_pwr', 0) * 1000)
|
return int(self._port.data.get('active_pwr', 0) * 1000)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state_attributes(self):
|
def device_state_attributes(self):
|
||||||
attr = super().state_attributes or {}
|
attr = {}
|
||||||
attr['volts'] = self._port.data.get('v_rms', 0)
|
attr['volts'] = self._port.data.get('v_rms', 0)
|
||||||
attr['amps'] = self._port.data.get('i_rms', 0)
|
attr['amps'] = self._port.data.get('i_rms', 0)
|
||||||
return attr
|
return attr
|
||||||
|
|
|
@ -100,34 +100,24 @@ class MySensorsSwitch(SwitchDevice):
|
||||||
@property
|
@property
|
||||||
def device_state_attributes(self):
|
def device_state_attributes(self):
|
||||||
"""Return device specific state attributes."""
|
"""Return device specific state attributes."""
|
||||||
set_req = self.gateway.const.SetReq
|
attr = {
|
||||||
device_attr = {}
|
|
||||||
for value_type, value in self._values.items():
|
|
||||||
if value_type != self.value_type:
|
|
||||||
try:
|
|
||||||
device_attr[set_req(value_type).name] = value
|
|
||||||
except ValueError:
|
|
||||||
_LOGGER.error('value_type %s is not valid for mysensors '
|
|
||||||
'version %s', value_type,
|
|
||||||
self.gateway.version)
|
|
||||||
return device_attr
|
|
||||||
|
|
||||||
@property
|
|
||||||
def state_attributes(self):
|
|
||||||
"""Return the state attributes."""
|
|
||||||
data = {
|
|
||||||
mysensors.ATTR_PORT: self.gateway.port,
|
mysensors.ATTR_PORT: self.gateway.port,
|
||||||
mysensors.ATTR_NODE_ID: self.node_id,
|
mysensors.ATTR_NODE_ID: self.node_id,
|
||||||
mysensors.ATTR_CHILD_ID: self.child_id,
|
mysensors.ATTR_CHILD_ID: self.child_id,
|
||||||
ATTR_BATTERY_LEVEL: self.battery_level,
|
ATTR_BATTERY_LEVEL: self.battery_level,
|
||||||
}
|
}
|
||||||
|
|
||||||
device_attr = self.device_state_attributes
|
set_req = self.gateway.const.SetReq
|
||||||
|
|
||||||
if device_attr is not None:
|
for value_type, value in self._values.items():
|
||||||
data.update(device_attr)
|
if value_type != self.value_type:
|
||||||
|
try:
|
||||||
return data
|
attr[set_req(value_type).name] = value
|
||||||
|
except ValueError:
|
||||||
|
_LOGGER.error('value_type %s is not valid for mysensors '
|
||||||
|
'version %s', value_type,
|
||||||
|
self.gateway.version)
|
||||||
|
return attr
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
|
|
|
@ -8,8 +8,7 @@ https://home-assistant.io/components/switch.tellstick/
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from homeassistant.const import (EVENT_HOMEASSISTANT_STOP,
|
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
|
||||||
ATTR_FRIENDLY_NAME)
|
|
||||||
from homeassistant.helpers.entity import ToggleEntity
|
from homeassistant.helpers.entity import ToggleEntity
|
||||||
|
|
||||||
SIGNAL_REPETITIONS = 1
|
SIGNAL_REPETITIONS = 1
|
||||||
|
@ -63,7 +62,6 @@ class TellstickSwitchDevice(ToggleEntity):
|
||||||
import tellcore.constants as tellcore_constants
|
import tellcore.constants as tellcore_constants
|
||||||
|
|
||||||
self.tellstick_device = tellstick_device
|
self.tellstick_device = tellstick_device
|
||||||
self.state_attr = {ATTR_FRIENDLY_NAME: tellstick_device.name}
|
|
||||||
self.signal_repetitions = signal_repetitions
|
self.signal_repetitions = signal_repetitions
|
||||||
|
|
||||||
self.last_sent_command_mask = (tellcore_constants.TELLSTICK_TURNON |
|
self.last_sent_command_mask = (tellcore_constants.TELLSTICK_TURNON |
|
||||||
|
@ -79,11 +77,6 @@ class TellstickSwitchDevice(ToggleEntity):
|
||||||
""" Returns the name of the switch if any. """
|
""" Returns the name of the switch if any. """
|
||||||
return self.tellstick_device.name
|
return self.tellstick_device.name
|
||||||
|
|
||||||
@property
|
|
||||||
def state_attributes(self):
|
|
||||||
""" Returns optional state attributes. """
|
|
||||||
return self.state_attr
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
""" True if switch is on. """
|
""" True if switch is on. """
|
||||||
|
|
|
@ -102,8 +102,8 @@ class VeraSwitch(SwitchDevice):
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state_attributes(self):
|
def device_state_attributes(self):
|
||||||
attr = super().state_attributes or {}
|
attr = {}
|
||||||
|
|
||||||
if self.vera_device.has_battery:
|
if self.vera_device.has_battery:
|
||||||
attr[ATTR_BATTERY_LEVEL] = self.vera_device.battery_level + '%'
|
attr[ATTR_BATTERY_LEVEL] = self.vera_device.battery_level + '%'
|
||||||
|
|
|
@ -95,8 +95,8 @@ class WemoSwitch(SwitchDevice):
|
||||||
return self.wemo.name
|
return self.wemo.name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state_attributes(self):
|
def device_state_attributes(self):
|
||||||
attr = super().state_attributes or {}
|
attr = {}
|
||||||
if self.maker_params:
|
if self.maker_params:
|
||||||
# Is the maker sensor on or off.
|
# Is the maker sensor on or off.
|
||||||
if self.maker_params['hassensor']:
|
if self.maker_params['hassensor']:
|
||||||
|
|
|
@ -178,11 +178,6 @@ class ThermostatDevice(Entity):
|
||||||
""" Returns the current state. """
|
""" Returns the current state. """
|
||||||
return self.target_temperature or STATE_UNKNOWN
|
return self.target_temperature or STATE_UNKNOWN
|
||||||
|
|
||||||
@property
|
|
||||||
def device_state_attributes(self):
|
|
||||||
""" Returns device specific state attributes. """
|
|
||||||
return None
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state_attributes(self):
|
def state_attributes(self):
|
||||||
""" Returns optional state attributes. """
|
""" Returns optional state attributes. """
|
||||||
|
@ -211,11 +206,6 @@ class ThermostatDevice(Entity):
|
||||||
if is_fan_on is not None:
|
if is_fan_on is not None:
|
||||||
data[ATTR_FAN] = STATE_ON if is_fan_on else STATE_OFF
|
data[ATTR_FAN] = STATE_ON if is_fan_on else STATE_OFF
|
||||||
|
|
||||||
device_attr = self.device_state_attributes
|
|
||||||
|
|
||||||
if device_attr is not None:
|
|
||||||
data.update(device_attr)
|
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
@ -13,7 +13,7 @@ from homeassistant.helpers import validate_config
|
||||||
from homeassistant.helpers.entity import ToggleEntity
|
from homeassistant.helpers.entity import ToggleEntity
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
EVENT_PLATFORM_DISCOVERED, CONF_ACCESS_TOKEN,
|
EVENT_PLATFORM_DISCOVERED, CONF_ACCESS_TOKEN,
|
||||||
ATTR_SERVICE, ATTR_DISCOVERED, ATTR_FRIENDLY_NAME)
|
ATTR_SERVICE, ATTR_DISCOVERED)
|
||||||
|
|
||||||
DOMAIN = "wink"
|
DOMAIN = "wink"
|
||||||
REQUIREMENTS = ['python-wink==0.5.0']
|
REQUIREMENTS = ['python-wink==0.5.0']
|
||||||
|
@ -80,13 +80,6 @@ class WinkToggleDevice(ToggleEntity):
|
||||||
""" True if light is on. """
|
""" True if light is on. """
|
||||||
return self.wink.state()
|
return self.wink.state()
|
||||||
|
|
||||||
@property
|
|
||||||
def state_attributes(self):
|
|
||||||
""" Returns optional state attributes. """
|
|
||||||
return {
|
|
||||||
ATTR_FRIENDLY_NAME: self.wink.name()
|
|
||||||
}
|
|
||||||
|
|
||||||
def turn_on(self, **kwargs):
|
def turn_on(self, **kwargs):
|
||||||
""" Turns the switch on. """
|
""" Turns the switch on. """
|
||||||
self.wink.set_state(True)
|
self.wink.set_state(True)
|
||||||
|
|
|
@ -80,7 +80,20 @@ class Entity(object):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state_attributes(self):
|
def state_attributes(self):
|
||||||
"""Return the state attributes."""
|
"""
|
||||||
|
Return the state attributes.
|
||||||
|
|
||||||
|
Implemented by component base class.
|
||||||
|
"""
|
||||||
|
return None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_state_attributes(self):
|
||||||
|
"""
|
||||||
|
Return device specific state attributes.
|
||||||
|
|
||||||
|
Implemented by platform classes.
|
||||||
|
"""
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -135,6 +148,11 @@ class Entity(object):
|
||||||
state = str(self.state)
|
state = str(self.state)
|
||||||
attr = self.state_attributes or {}
|
attr = self.state_attributes or {}
|
||||||
|
|
||||||
|
device_attr = self.device_state_attributes
|
||||||
|
|
||||||
|
if device_attr is not None:
|
||||||
|
attr.update(device_attr)
|
||||||
|
|
||||||
if ATTR_UNIT_OF_MEASUREMENT not in attr and \
|
if ATTR_UNIT_OF_MEASUREMENT not in attr and \
|
||||||
self.unit_of_measurement is not None:
|
self.unit_of_measurement is not None:
|
||||||
attr[ATTR_UNIT_OF_MEASUREMENT] = str(self.unit_of_measurement)
|
attr[ATTR_UNIT_OF_MEASUREMENT] = str(self.unit_of_measurement)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue