From e42b9e6c4c7a85847d3de25e4b40093b2917c3c0 Mon Sep 17 00:00:00 2001 From: jan iversen Date: Fri, 18 Aug 2023 10:52:57 +0200 Subject: [PATCH] Modbus: set state_class etc in slaves. (#98332) --- homeassistant/components/modbus/sensor.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/homeassistant/components/modbus/sensor.py b/homeassistant/components/modbus/sensor.py index e4f4f9b8d66..97794729ab2 100644 --- a/homeassistant/components/modbus/sensor.py +++ b/homeassistant/components/modbus/sensor.py @@ -11,6 +11,7 @@ from homeassistant.components.sensor import ( SensorEntity, ) from homeassistant.const import ( + CONF_DEVICE_CLASS, CONF_NAME, CONF_SENSORS, CONF_UNIQUE_ID, @@ -72,6 +73,7 @@ class ModbusRegisterSensor(BaseStructPlatform, RestoreSensor, SensorEntity): self._coordinator: DataUpdateCoordinator[list[int] | None] | None = None self._attr_native_unit_of_measurement = entry.get(CONF_UNIT_OF_MEASUREMENT) self._attr_state_class = entry.get(CONF_STATE_CLASS) + self._attr_device_class = entry.get(CONF_DEVICE_CLASS) async def async_setup_slaves( self, hass: HomeAssistant, slave_count: int, entry: dict[str, Any] @@ -160,6 +162,8 @@ class SlaveSensor( self._attr_unique_id = entry.get(CONF_UNIQUE_ID) if self._attr_unique_id: self._attr_unique_id = f"{self._attr_unique_id}_{idx}" + self._attr_native_unit_of_measurement = entry.get(CONF_UNIT_OF_MEASUREMENT) + self._attr_state_class = entry.get(CONF_STATE_CLASS) self._attr_available = False super().__init__(coordinator)