diff --git a/zha/application/platforms/sensor/__init__.py b/zha/application/platforms/sensor/__init__.py index d46dcbb7..c9d3cd6e 100644 --- a/zha/application/platforms/sensor/__init__.py +++ b/zha/application/platforms/sensor/__init__.py @@ -29,6 +29,7 @@ ) from zha.application.platforms.climate.const import HVACAction from zha.application.platforms.helpers import validate_device_class +from zha.application.platforms.number.const import UNITS from zha.application.platforms.sensor.const import SensorDeviceClass, SensorStateClass from zha.application.registries import PLATFORM_ENTITIES from zha.decorators import periodic @@ -476,16 +477,36 @@ def formatter(self, value: int) -> str | None: return self._enum(value).name -@MULTI_MATCH( - cluster_handler_names=CLUSTER_HANDLER_ANALOG_INPUT, - manufacturers="Digi", - stop_on_match_group=CLUSTER_HANDLER_ANALOG_INPUT, -) -class AnalogInput(Sensor): +@CONFIG_DIAGNOSTIC_MATCH(cluster_handler_names=CLUSTER_HANDLER_ANALOG_INPUT) +class AnalogInputSensor(Sensor): """Sensor that displays analog input values.""" _attribute_name = "present_value" _attr_translation_key: str = "analog_input" + _attr_entity_registry_enabled_default = False + _attr_extra_state_attribute_names: set[str] = { + "description", + "max_present_value", + "min_present_value", + "out_of_service", + "reliability", + "resolution", + "status_flags", + "application_type", + } + + def __init__( + self, + unique_id: str, + cluster_handlers: list[ClusterHandler], + endpoint: Endpoint, + device: Device, + **kwargs: Any, + ) -> None: + """Init this sensor.""" + super().__init__(unique_id, cluster_handlers, endpoint, device, **kwargs) + engineering_units = self._cluster_handler.engineering_units + self._attr_native_unit_of_measurement = UNITS.get(engineering_units) @MULTI_MATCH(cluster_handler_names=CLUSTER_HANDLER_POWER_CONFIGURATION) diff --git a/zha/zigbee/cluster_handlers/general.py b/zha/zigbee/cluster_handlers/general.py index 858046fd..711261c3 100644 --- a/zha/zigbee/cluster_handlers/general.py +++ b/zha/zigbee/cluster_handlers/general.py @@ -93,7 +93,77 @@ class AnalogInputClusterHandler(ClusterHandler): attr=AnalogInput.AttributeDefs.present_value.name, config=REPORT_CONFIG_DEFAULT, ), + AttrReportConfig( + attr=AnalogInput.AttributeDefs.status_flags.name, + config=REPORT_CONFIG_DEFAULT, + ), ) + ZCL_INIT_ATTRS = { + AnalogInput.AttributeDefs.description.name: True, + AnalogInput.AttributeDefs.max_present_value.name: True, + AnalogInput.AttributeDefs.min_present_value.name: True, + AnalogInput.AttributeDefs.out_of_service.name: True, + AnalogInput.AttributeDefs.reliability.name: True, + AnalogInput.AttributeDefs.resolution.name: True, + AnalogInput.AttributeDefs.engineering_units.name: True, + AnalogInput.AttributeDefs.application_type.name: True, + } + + @property + def present_value(self) -> float | None: + """Return cached value of present_value.""" + return self.cluster.get(AnalogInput.AttributeDefs.present_value.name) + + @property + def description(self) -> str | None: + """Return cached value of description.""" + return self.cluster.get(AnalogInput.AttributeDefs.description.name) + + @property + def max_present_value(self) -> float | None: + """Return cached value of max_present_value.""" + return self.cluster.get(AnalogInput.AttributeDefs.max_present_value.name) + + @property + def min_present_value(self) -> float | None: + """Return cached value of min_present_value.""" + return self.cluster.get(AnalogInput.AttributeDefs.min_present_value.name) + + @property + def out_of_service(self) -> bool | None: + """Return cached value of out_of_service.""" + return self.cluster.get(AnalogInput.AttributeDefs.out_of_service.name) + + @property + def reliability(self) -> int | None: + """Return cached value of reliability.""" + return self.cluster.get(AnalogInput.AttributeDefs.reliability.name) + + @property + def resolution(self) -> float | None: + """Return cached value of resolution.""" + return self.cluster.get(AnalogInput.AttributeDefs.resolution.name) + + @property + def status_flags(self) -> int | None: + """Return cached value of status_flags.""" + return self.cluster.get(AnalogInput.AttributeDefs.status_flags.name) + + @property + def engineering_units(self) -> int | None: + """Return cached value of engineering_units.""" + return self.cluster.get(AnalogInput.AttributeDefs.engineering_units.name) + + @property + def application_type(self) -> int | None: + """Return cached value of application_type.""" + return self.cluster.get(AnalogInput.AttributeDefs.application_type.name) + + async def async_update(self): + """Update cluster value attribute.""" + await self.get_attribute_value( + AnalogInput.AttributeDefs.present_value.name, from_cache=False + ) @registries.BINDABLE_CLUSTERS.register(AnalogOutput.cluster_id)