1 """Support for DHT and DS18B20 sensors attached to a Konnected device."""
3 from __future__
import annotations
8 SensorEntityDescription,
25 from .const
import DOMAIN
as KONNECTED_DOMAIN, SIGNAL_DS18B20_NEW
27 SENSOR_TYPES: dict[str, SensorEntityDescription] = {
31 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
32 device_class=SensorDeviceClass.TEMPERATURE,
37 native_unit_of_measurement=PERCENTAGE,
38 device_class=SensorDeviceClass.HUMIDITY,
45 config_entry: ConfigEntry,
46 async_add_entities: AddEntitiesCallback,
48 """Set up sensors attached to a Konnected device from a config entry."""
49 data = hass.data[KONNECTED_DOMAIN]
50 device_id = config_entry.data[
"id"]
55 for sensor
in data[CONF_DEVICES][device_id][CONF_SENSORS]
56 if sensor[CONF_TYPE] ==
"dht"
60 for sensor_config
in dht_sensors
61 for description
in SENSOR_TYPES.values()
68 """Add new KonnectedSensor representing a ds18b20 sensor."""
72 for s
in data[CONF_DEVICES][device_id][CONF_SENSORS]
73 if s[CONF_TYPE] ==
"ds18b20" and s[CONF_ZONE] == attrs.get(CONF_ZONE)
83 SENSOR_TYPES[
"temperature"],
84 addr=attrs.get(
"addr"),
85 initial_state=attrs.get(
"temp"),
97 """Represents a Konnected DHT Sensor."""
103 description: SensorEntityDescription,
107 """Initialize the entity for a single sensor_type."""
112 self.
_attr_unique_id_attr_unique_id = addr
or f
"{device_id}-{self._zone_num}-{description.key}"
120 if name := self.
_data_data.
get(CONF_NAME):
121 name += f
" {description.name}"
127 """Store entity_id and register state change callback."""
136 """Update the sensor's state."""
None async_added_to_hass(self)
def async_set_state(self, state)
None __init__(self, device_id, data, SensorEntityDescription description, addr=None, initial_state=None)
None async_write_ha_state(self)
web.Response get(self, web.Request request, str config_key)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
def async_add_ds18b20(attrs)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)