1 """Support for Wireless Sensor Tags."""
9 SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
10 UnitOfElectricPotential,
14 _LOGGER = logging.getLogger(__name__)
18 ATTR_TAG_SIGNAL_STRENGTH =
"signal_strength"
20 ATTR_TAG_OUT_OF_RANGE =
"out_of_range"
22 ATTR_TAG_POWER_CONSUMPTION =
"power_consumption"
26 """Base class for HA implementation for Wireless Sensor Tag."""
29 """Initialize a base sensor for Wireless Sensor Tag platform."""
40 """Return the name of the sensor."""
41 return self.
_name_name
47 Subclasses need override based on type of sensor.
52 """Return formatted value.
54 The default implementation formats principal value.
59 """Decorate input value to be well presented for end user."""
64 """Return True if entity is available."""
65 return self.
_tag_tag.is_alive
72 updated_tags = self.
_api_api.load_tags()
73 if (updated_tag := updated_tags[self.
_uuid_uuid])
is None:
74 _LOGGER.error(
'Unable to update tag: "%s"', self.
namenamename)
77 self.
_tag_tag = updated_tag
82 """Return the state attributes."""
84 ATTR_BATTERY_LEVEL:
int(self.
_tag_tag.battery_remaining * 100),
86 f
"{self._tag.battery_volts:.2f}{UnitOfElectricPotential.VOLT}"
88 ATTR_TAG_SIGNAL_STRENGTH: (
89 f
"{self._tag.signal_strength}{SIGNAL_STRENGTH_DECIBELS_MILLIWATT}"
91 ATTR_TAG_OUT_OF_RANGE:
not self.
_tag_tag.is_in_range,
92 ATTR_TAG_POWER_CONSUMPTION: (
93 f
"{self._tag.power_consumption:.2f}{PERCENTAGE}"
def __init__(self, api, tag)
def principal_value(self)
def updated_state_value(self)
def decorate_value(self, value)
def extra_state_attributes(self)
str|UndefinedType|None name(self)