1 """Support for Qwikswitch Sensors."""
3 from __future__
import annotations
8 from pyqwikswitch.qwikswitch
import SENSORS
15 from .
import DOMAIN
as QWIKSWITCH
16 from .entity
import QSEntity
18 _LOGGER = logging.getLogger(__name__)
24 add_entities: AddEntitiesCallback,
25 discovery_info: DiscoveryInfoType |
None =
None,
27 """Add sensor from the main Qwikswitch component."""
28 if discovery_info
is None:
31 qsusb = hass.data[QWIKSWITCH]
32 _LOGGER.debug(
"Setup qwikswitch.sensor %s, %s", qsusb, discovery_info)
33 devs = [
QSSensor(sensor)
for sensor
in discovery_info[QWIKSWITCH]]
38 """Sensor based on a Qwikswitch relay/dimmer module."""
40 _val: Any |
None =
None
43 """Initialize the sensor."""
45 super().
__init__(sensor[
"id"], sensor[
"name"])
47 sensor_type = sensor[
"type"]
49 self._decode, self.
unitunit = SENSORS[sensor_type]
51 assert not isinstance(
53 ), f
"boolean sensor id={sensor['id']} name={sensor['name']}"
57 """Receive update packet from QSUSB."""
58 val = self._decode(packet, channel=self.
channelchannel)
60 "Update %s (%s:%s) decoded as %s: %s",
73 """Return the value of the sensor."""
74 return None if self.
_val_val
is None else str(self.
_val_val)
78 """Return a unique identifier for this sensor."""
79 return f
"qs{self.qsid}:{self.channel}"
83 """Return the unit the value is expressed in."""
def __init__(self, sensor)
def native_unit_of_measurement(self)
def update_packet(self, packet)
None async_write_ha_state(self)
def add_entities(account, async_add_entities, tracked)
None async_setup_platform(HomeAssistant hass, ConfigType _, AddEntitiesCallback add_entities, DiscoveryInfoType|None discovery_info=None)