Merge pull request #1157 from balloob/device-state-attributes
Clean up state_attributes vs device_state_attributes
This commit is contained in:
commit
64611ab2be
23 files changed
+66
-138
No files matched your search
@@ -129,11 +129,6 @@ class SwitchDevice(ToggleEntity):
|
||||
""" Is the device in standby. """
|
||||
return None
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
""" Returns device specific state attributes. """
|
||||
return None
|
||||
|
||||
@property
|
||||
def state_attributes(self):
|
||||
""" Returns optional state attributes. """
|
||||
@@ -144,9 +139,4 @@ class SwitchDevice(ToggleEntity):
|
||||
if value:
|
||||
data[attr] = value
|
||||
|
||||
device_attr = self.device_state_attributes
|
||||
|
||||
if device_attr is not None:
|
||||
data.update(device_attr)
|
||||
|
||||
return data
|
||||
@@ -89,8 +89,8 @@ class MfiSwitch(SwitchDevice):
|
||||
return int(self._port.data.get('active_pwr', 0) * 1000)
|
||||
|
||||
@property
|
||||
def state_attributes(self):
|
||||
attr = super().state_attributes or {}
|
||||
def device_state_attributes(self):
|
||||
attr = {}
|
||||
attr['volts'] = self._port.data.get('v_rms', 0)
|
||||
attr['amps'] = self._port.data.get('i_rms', 0)
|
||||
return attr
|
||||
@@ -100,34 +100,24 @@ class MySensorsSwitch(SwitchDevice):
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return device specific state attributes."""
|
||||
set_req = self.gateway.const.SetReq
|
||||
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 = {
|
||||
attr = {
|
||||
mysensors.ATTR_PORT: self.gateway.port,
|
||||
mysensors.ATTR_NODE_ID: self.node_id,
|
||||
mysensors.ATTR_CHILD_ID: self.child_id,
|
||||
ATTR_BATTERY_LEVEL: self.battery_level,
|
||||
}
|
||||
|
||||
device_attr = self.device_state_attributes
|
||||
set_req = self.gateway.const.SetReq
|
||||
|
||||
if device_attr is not None:
|
||||
data.update(device_attr)
|
||||
|
||||
return data
|
||||
for value_type, value in self._values.items():
|
||||
if value_type != self.value_type:
|
||||
try:
|
||||
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
|
||||
def is_on(self):
|
||||
|
||||
@@ -8,8 +8,7 @@ https://home-assistant.io/components/switch.tellstick/
|
||||
"""
|
||||
import logging
|
||||
|
||||
from homeassistant.const import (EVENT_HOMEASSISTANT_STOP,
|
||||
ATTR_FRIENDLY_NAME)
|
||||
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
|
||||
from homeassistant.helpers.entity import ToggleEntity
|
||||
|
||||
SIGNAL_REPETITIONS = 1
|
||||
@@ -63,7 +62,6 @@ class TellstickSwitchDevice(ToggleEntity):
|
||||
import tellcore.constants as tellcore_constants
|
||||
|
||||
self.tellstick_device = tellstick_device
|
||||
self.state_attr = {ATTR_FRIENDLY_NAME: tellstick_device.name}
|
||||
self.signal_repetitions = signal_repetitions
|
||||
|
||||
self.last_sent_command_mask = (tellcore_constants.TELLSTICK_TURNON |
|
||||
@@ -79,11 +77,6 @@ class TellstickSwitchDevice(ToggleEntity):
|
||||
""" Returns the name of the switch if any. """
|
||||
return self.tellstick_device.name
|
||||
|
||||
@property
|
||||
def state_attributes(self):
|
||||
""" Returns optional state attributes. """
|
||||
return self.state_attr
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
""" True if switch is on. """
|
||||
|
||||
@@ -102,8 +102,8 @@ class VeraSwitch(SwitchDevice):
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def state_attributes(self):
|
||||
attr = super().state_attributes or {}
|
||||
def device_state_attributes(self):
|
||||
attr = {}
|
||||
|
||||
if self.vera_device.has_battery:
|
||||
attr[ATTR_BATTERY_LEVEL] = self.vera_device.battery_level + '%'
|
||||
|
||||
@@ -95,8 +95,8 @@ class WemoSwitch(SwitchDevice):
|
||||
return self.wemo.name
|
||||
|
||||
@property
|
||||
def state_attributes(self):
|
||||
attr = super().state_attributes or {}
|
||||
def device_state_attributes(self):
|
||||
attr = {}
|
||||
if self.maker_params:
|
||||
# Is the maker sensor on or off.
|
||||
if self.maker_params['hassensor']:
|
||||
|
||||
Reference in new issue
Block a user