Modbus: set state_class etc in slaves. (#98332)
This commit is contained in:
parent
9be532cea9
commit
e42b9e6c4c
1 changed files with 4 additions and 0 deletions
|
@ -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)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue