1 """Sensors on Zigbee Home Automation networks."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
22 from .entity
import ZHAEntity
23 from .helpers
import (
26 async_add_entities
as zha_async_add_entities,
31 _LOGGER = logging.getLogger(__name__)
37 _EXTRA_STATE_ATTRIBUTES: set[str] = {
53 "zcl_unit_of_measurement",
56 "Valve_characteristic_found",
57 "Valve_characteristic_lost",
58 "Top_pcb_sensor_error",
59 "Side_pcb_sensor_error",
60 "Non_volatile_memory_error",
63 "Invalid_internal_communication",
64 "Invalid_clock_information",
65 "Radio_communication_error",
68 "Critical_low_battery",
74 config_entry: ConfigEntry,
75 async_add_entities: AddEntitiesCallback,
77 """Set up the Zigbee Home Automation sensor from config entry."""
79 entities_to_create = zha_data.platforms[Platform.SENSOR]
85 zha_async_add_entities, async_add_entities, Sensor, entities_to_create
88 config_entry.async_on_unload(unsub)
95 def __init__(self, entity_data: EntityData, **kwargs: Any) ->
None:
96 """Initialize the ZHA select entity."""
97 super().
__init__(entity_data, **kwargs)
98 entity = self.entity_data.entity
100 if entity.device_class
is not None:
103 if entity.state_class
is not None:
106 if hasattr(entity.info_object,
"unit")
and entity.info_object.unit
is not None:
110 hasattr(entity,
"entity_description")
111 and entity.entity_description
is not None
113 entity_description = entity.entity_description
115 if entity_description.state_class
is not None:
117 entity_description.state_class.value
120 if entity_description.scale
is not None:
123 if entity_description.native_unit_of_measurement
is not None:
125 entity_description.native_unit_of_measurement
128 if entity_description.device_class
is not None:
130 entity_description.device_class.value
135 """Return the state of the entity."""
136 return self.entity_data.entity.native_value
140 """Return entity specific state attributes."""
141 entity = self.entity_data.entity
142 if entity.extra_state_attribute_names
is None:
145 if not entity.extra_state_attribute_names <= _EXTRA_STATE_ATTRIBUTES:
147 "Unexpected extra state attributes found for sensor %s: %s",
149 entity.extra_state_attribute_names - _EXTRA_STATE_ATTRIBUTES,
154 name: entity.state.get(name)
155 for name
in entity.extra_state_attribute_names
None __init__(self, EntityData entity_data, **Any kwargs)
StateType native_value(self)
Mapping[str, Any]|None extra_state_attributes(self)
_attr_native_unit_of_measurement
HAZHAData get_zha_data(HomeAssistant hass)
dict[str, Any] exclude_none_values(Mapping[str, Any] obj)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)