1 """Support for LCN sensors."""
3 from collections.abc
import Iterable
4 from functools
import partial
5 from itertools
import chain
6 from typing
import cast
11 DOMAIN
as DOMAIN_SENSOR,
20 CONF_UNIT_OF_MEASUREMENT,
27 ADD_ENTITIES_CALLBACKS,
36 from .entity
import LcnEntity
37 from .helpers
import InputType
39 DEVICE_CLASS_MAPPING = {
40 pypck.lcn_defs.VarUnit.CELSIUS: SensorDeviceClass.TEMPERATURE,
41 pypck.lcn_defs.VarUnit.KELVIN: SensorDeviceClass.TEMPERATURE,
42 pypck.lcn_defs.VarUnit.FAHRENHEIT: SensorDeviceClass.TEMPERATURE,
43 pypck.lcn_defs.VarUnit.LUX_T: SensorDeviceClass.ILLUMINANCE,
44 pypck.lcn_defs.VarUnit.LUX_I: SensorDeviceClass.ILLUMINANCE,
45 pypck.lcn_defs.VarUnit.METERPERSECOND: SensorDeviceClass.SPEED,
46 pypck.lcn_defs.VarUnit.VOLT: SensorDeviceClass.VOLTAGE,
47 pypck.lcn_defs.VarUnit.AMPERE: SensorDeviceClass.CURRENT,
52 config_entry: ConfigEntry,
53 async_add_entities: AddEntitiesCallback,
54 entity_configs: Iterable[ConfigType],
56 """Add entities for this domain."""
57 entities: list[LcnVariableSensor | LcnLedLogicSensor] = []
58 for entity_config
in entity_configs:
59 if entity_config[CONF_DOMAIN_DATA][CONF_SOURCE]
in chain(
60 VARIABLES, SETPOINTS, THRESHOLDS, S0_INPUTS
71 config_entry: ConfigEntry,
72 async_add_entities: AddEntitiesCallback,
74 """Set up LCN switch entities from a config entry."""
75 add_entities = partial(
81 hass.data[DOMAIN][config_entry.entry_id][ADD_ENTITIES_CALLBACKS].
update(
82 {DOMAIN_SENSOR: add_entities}
88 for entity_config
in config_entry.data[CONF_ENTITIES]
89 if entity_config[CONF_DOMAIN] == DOMAIN_SENSOR
95 """Representation of a LCN sensor for variables."""
97 def __init__(self, config: ConfigType, config_entry: ConfigEntry) ->
None:
98 """Initialize the LCN sensor."""
99 super().
__init__(config, config_entry)
101 self.
variablevariable = pypck.lcn_defs.Var[config[CONF_DOMAIN_DATA][CONF_SOURCE]]
102 self.
unitunit = pypck.lcn_defs.VarUnit.parse(
103 config[CONF_DOMAIN_DATA][CONF_UNIT_OF_MEASUREMENT]
110 """Run when entity about to be added to hass."""
116 """Run when entity will be removed from hass."""
122 """Set sensor value when LCN input object (command) is received."""
124 not isinstance(input_obj, pypck.inputs.ModStatusVar)
125 or input_obj.get_var() != self.
variablevariable
129 is_regulator = self.
variablevariable.name
in SETPOINTS
131 self.
unitunit, is_regulator
138 """Representation of a LCN sensor for leds and logicops."""
140 def __init__(self, config: ConfigType, config_entry: ConfigEntry) ->
None:
141 """Initialize the LCN sensor."""
142 super().
__init__(config, config_entry)
144 if config[CONF_DOMAIN_DATA][CONF_SOURCE]
in LED_PORTS:
145 self.
sourcesource = pypck.lcn_defs.LedPort[config[CONF_DOMAIN_DATA][CONF_SOURCE]]
147 self.
sourcesource = pypck.lcn_defs.LogicOpPort[
148 config[CONF_DOMAIN_DATA][CONF_SOURCE]
152 """Run when entity about to be added to hass."""
158 """Run when entity will be removed from hass."""
164 """Set sensor value when LCN input object (command) is received."""
165 if not isinstance(input_obj, pypck.inputs.ModStatusLedsAndLogicOps):
168 if self.
sourcesource
in pypck.lcn_defs.LedPort:
172 elif self.
sourcesource
in pypck.lcn_defs.LogicOpPort:
None async_added_to_hass(self)
None __init__(self, ConfigType config, ConfigEntry config_entry)
None async_will_remove_from_hass(self)
None input_received(self, InputType input_obj)
_attr_native_unit_of_measurement
None async_will_remove_from_hass(self)
None __init__(self, ConfigType config, ConfigEntry config_entry)
None input_received(self, InputType input_obj)
None async_added_to_hass(self)
None async_write_ha_state(self)
def add_entities(account, async_add_entities, tracked)
IssData update(pyiss.ISS iss)
None add_lcn_entities(ConfigEntry config_entry, AddEntitiesCallback async_add_entities, Iterable[ConfigType] entity_configs)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)