From 20ecb05a231c4b0b27c5bf48aae2a3adf09cf9a2 Mon Sep 17 00:00:00 2001 From: Jonny Bergdahl Date: Fri, 31 May 2024 09:50:27 +0200 Subject: [PATCH] Add updated files --- custom_components/growcube/__init__.py | 4 +- custom_components/growcube/binary_sensor.py | 115 +++++++++++--------- custom_components/growcube/button.py | 4 +- custom_components/growcube/coordinator.py | 109 ++++--------------- custom_components/growcube/sensor.py | 73 ++++++------- 5 files changed, 122 insertions(+), 183 deletions(-) diff --git a/custom_components/growcube/__init__.py b/custom_components/growcube/__init__.py index 9fb42cf..f524d87 100644 --- a/custom_components/growcube/__init__.py +++ b/custom_components/growcube/__init__.py @@ -38,11 +38,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: dict): registry = device_registry.async_get(hass) device_entry = registry.async_get_or_create( config_entry_id=entry.entry_id, - identifiers={(DOMAIN, data_coordinator.model.device_id)}, + identifiers={(DOMAIN, data_coordinator.data.device_id)}, name=f"GrowCube " + data_coordinator.device_id, manufacturer="Elecrow", model="GrowCube", - sw_version=data_coordinator.model.version + sw_version=data_coordinator.data.version ) await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) diff --git a/custom_components/growcube/binary_sensor.py b/custom_components/growcube/binary_sensor.py index 8102cbb..69d589f 100644 --- a/custom_components/growcube/binary_sensor.py +++ b/custom_components/growcube/binary_sensor.py @@ -12,52 +12,65 @@ async def async_setup_entry(hass, entry, async_add_entities): """Set up the Growcube sensors.""" coordinator = hass.data[DOMAIN][entry.entry_id] - async_add_entities(coordinator.binary_sensors, True) + async_add_entities([LockedStateSensor(coordinator), + WaterStateSensor(coordinator), + PumpOpenStateSensor(coordinator, 0), + PumpOpenStateSensor(coordinator, 1), + PumpOpenStateSensor(coordinator, 2), + PumpOpenStateSensor(coordinator, 3), + PumpLockedStateSensor(coordinator, 0), + PumpLockedStateSensor(coordinator, 1), + PumpLockedStateSensor(coordinator, 2), + PumpLockedStateSensor(coordinator, 3), + SensorFaultStateSensor(coordinator, 0), + SensorFaultStateSensor(coordinator, 1), + SensorFaultStateSensor(coordinator, 2), + SensorFaultStateSensor(coordinator, 3) + ], True) class LockedStateSensor(BinarySensorEntity): def __init__(self, coordinator: GrowcubeDataCoordinator): self._coordinator = coordinator self._coordinator.entities.append(self) - self._attr_unique_id = f"{coordinator.model.device_id}_locked" + self._attr_unique_id = f"{coordinator.data.device_id}_locked" self.entity_id = f"{Platform.SENSOR}.{self._attr_unique_id}" self._attr_name = f"Device locked" self._attr_device_class = BinarySensorDeviceClass.LOCK self._attr_entity_category = EntityCategory.DIAGNOSTIC - self._attr_native_value = coordinator.model.device_lock_state + self._attr_native_value = coordinator.data.device_lock_state @property def device_info(self) -> DeviceInfo | None: - return self._coordinator.model.device_info + return self._coordinator.data.device_info @property def is_on(self): """Return True if the binary sensor is on.""" - return not self._coordinator.model.device_lock_state + return not self._coordinator.data.device_lock_state @callback - def update(self, state: bool) -> None: - _LOGGER.debug("Update device_lock_state %s", state) - if self._coordinator.model.device_lock_state != state: - self._coordinator.model.device_lock_state = state - self._attr_native_value = state - self.async_write_ha_state() + def update(self) -> None: + _LOGGER.debug("Update device_lock_state %s", self._coordinator.data.device_lock_state) + if self._coordinator.data.device_lock_state != self._attr_native_value: + self._attr_native_value = self._coordinator.data.device_lock_state + self.schedule_update_ha_state() class WaterStateSensor(BinarySensorEntity): def __init__(self, coordinator: GrowcubeDataCoordinator): self._coordinator = coordinator self._coordinator.entities.append(self) - self._attr_unique_id = f"{coordinator.model.device_id}_water_level" + self._attr_unique_id = f"{coordinator.data.device_id}_water_level" self.entity_id = f"{Platform.SENSOR}.{self._attr_unique_id}" self._attr_name = f"Water level" self._attr_device_class = BinarySensorDeviceClass.PROBLEM self._attr_entity_category = EntityCategory.DIAGNOSTIC - self._attr_native_value = coordinator.model.device_lock_state + self._attr_native_value = coordinator.data.device_lock_state @property def device_info(self) -> DeviceInfo | None: - return self._coordinator.model.device_info + return self._coordinator.data.device_info @property def icon(self): @@ -68,18 +81,17 @@ def icon(self): @property def is_on(self): - return self._coordinator.model.water_state + return self._coordinator.data.water_state @callback - def update(self, state: bool) -> None: - _LOGGER.debug("Update water_state %s", state) - if self._coordinator.model.water_state != state: - self._coordinator.model.water_state = state - self._attr_native_value = state - self.async_write_ha_state() + def update(self) -> None: + _LOGGER.debug("Update water_state %s", self._coordinator.data.water_state) + if self._coordinator.data.water_state != self._attr_native_value: + self._attr_native_value = self._coordinator.data.water_state + self.schedule_update_ha_state() - async def async_added_to_hass(self): - self.async_on_remove(self._coordinator.async_add_listener(self._handle_coordinator_update)) + #async def async_added_to_hass(self): + # self.async_on_remove(self._coordinator.async_add_listener(self._handle_coordinator_update)) class PumpOpenStateSensor(BinarySensorEntity): @@ -90,16 +102,16 @@ def __init__(self, coordinator: GrowcubeDataCoordinator, channel: int) -> None: self._coordinator = coordinator self._coordinator.entities.append(self) self._channel = channel - self._attr_unique_id = f"{coordinator.model.device_id}_pump_" + self._channel_id[channel] + "_open" + self._attr_unique_id = f"{coordinator.data.device_id}_pump_" + self._channel_id[channel] + "_open" self.entity_id = f"{Platform.SENSOR}.{self._attr_unique_id}" self._attr_name = f"Pump " + self._channel_name[channel] + " open" self._attr_device_class = BinarySensorDeviceClass.OPENING - self._attr_native_value = coordinator.model.pump_open[self._channel] + self._attr_native_value = coordinator.data.pump_open[self._channel] self._attr_entity_registry_enabled_default = False @property def device_info(self) -> DeviceInfo | None: - return self._coordinator.model.device_info + return self._coordinator.data.device_info @property def icon(self): @@ -111,17 +123,16 @@ def icon(self): @property def is_on(self): """Return True if the binary sensor is on.""" - return self._coordinator.model.pump_open[self._channel] + return self._coordinator.data.pump_open[self._channel] @callback - def update(self, state: bool) -> None: + def update(self) -> None: _LOGGER.debug("Update pump_state[%s] %s", self._channel, - state) - if self._coordinator.model.pump_open[self._channel] != state: - self._coordinator.model.pump_open[self._channel] = state - self._attr_native_value = state - self.async_write_ha_state() + self._coordinator.data.pump_open[self._channel]) + if self._coordinator.data.pump_open[self._channel] != self._attr_native_value: + self._attr_native_value = self._coordinator.data.pump_open[self._channel] + self.schedule_update_ha_state() class PumpLockedStateSensor(BinarySensorEntity): @@ -132,16 +143,16 @@ def __init__(self, coordinator: GrowcubeDataCoordinator, channel: int) -> None: self._coordinator = coordinator self._coordinator.entities.append(self) self._channel = channel - self._attr_unique_id = f"{coordinator.model.device_id}_pump_" + self._channel_id[channel] + "_locked" + self._attr_unique_id = f"{coordinator.data.device_id}_pump_" + self._channel_id[channel] + "_locked" self.entity_id = f"{Platform.SENSOR}.{self._attr_unique_id}" self._attr_name = f"Pump " + self._channel_name[channel] + "lock state" self._attr_device_class = BinarySensorDeviceClass.PROBLEM self._attr_entity_category = EntityCategory.DIAGNOSTIC - self._attr_native_value = coordinator.model.pump_lock_state[self._channel] + self._attr_native_value = coordinator.data.pump_lock_state[self._channel] @property def device_info(self) -> DeviceInfo | None: - return self._coordinator.model.device_info + return self._coordinator.data.device_info @property def icon(self): @@ -153,17 +164,16 @@ def icon(self): @property def is_on(self): """Return True if the binary sensor is on.""" - return self._coordinator.model.pump_lock_state[self._channel] + return self._coordinator.data.pump_lock_state[self._channel] @callback - def update(self, state: bool) -> None: + def update(self) -> None: _LOGGER.debug("Update pump_lock_state[%s] %s", self._channel, - self._coordinator.model.pump_lock_state[self._channel]) - if self._coordinator.model.pump_lock_state[self._channel] != state: - self._coordinator.model.pump_lock_state[self._channel] = state - self._attr_native_value = state - self.async_write_ha_state() + self._coordinator.data.pump_lock_state[self._channel]) + if self._coordinator.data.pump_lock_state[self._channel] != self._attr_native_value: + self._attr_native_value = self._coordinator.data.pump_lock_state[self._channel] + self.schedule_update_ha_state() class SensorFaultStateSensor(BinarySensorEntity): @@ -174,16 +184,16 @@ def __init__(self, coordinator: GrowcubeDataCoordinator, channel: int) -> None: self._coordinator = coordinator self._coordinator.entities.append(self) self._channel = channel - self._attr_unique_id = f"{coordinator.model.device_id}_sensor_" + self._channel_id[channel] + "_locked" + self._attr_unique_id = f"{coordinator.data.device_id}_sensor_" + self._channel_id[channel] + "_locked" self.entity_id = f"{Platform.SENSOR}.{self._attr_unique_id}" self._attr_name = f"Sensor " + self._channel_name[channel] + " state" self._attr_device_class = BinarySensorDeviceClass.PROBLEM self._attr_entity_category = EntityCategory.DIAGNOSTIC - self._attr_native_value = coordinator.model.sensor_state[self._channel] + self._attr_native_value = coordinator.data.sensor_state[self._channel] @property def device_info(self) -> DeviceInfo | None: - return self._coordinator.model.device_info + return self._coordinator.data.device_info @property def icon(self): @@ -195,15 +205,14 @@ def icon(self): @property def is_on(self): """Return True if the binary sensor is on.""" - return self._coordinator.model.sensor_state[self._channel] + return self._coordinator.data.sensor_state[self._channel] @callback - def update(self, state: bool) -> None: + def update(self) -> None: _LOGGER.debug("Update sensor_state[%s] %s", self._channel, - self._coordinator.model.sensor_state[self._channel]) - if self._coordinator.model.sensor_state[self._channel] != state: - self._coordinator.model.sensor_state[self._channel] = state - self._attr_native_value = state - self.async_write_ha_state() + self._coordinator.data.sensor_state[self._channel]) + if self._coordinator.data.sensor_state[self._channel] != self._attr_native_value: + self._attr_native_value = self._coordinator.data.sensor_state[self._channel] + self.schedule_update_ha_state() diff --git a/custom_components/growcube/button.py b/custom_components/growcube/button.py index faea735..ebbf3c4 100644 --- a/custom_components/growcube/button.py +++ b/custom_components/growcube/button.py @@ -25,12 +25,12 @@ def __init__(self, coordinator, channel: int): self._coordinator = coordinator self._channel = channel self._attr_name = "Water plant " + self._channel_name[channel] - self._attr_unique_id = f"{coordinator.model.device_id}_water_plant_" + self._channel_id[channel] + self._attr_unique_id = f"{coordinator.data.device_id}_water_plant_" + self._channel_id[channel] self.entity_id = f"{Platform.SENSOR}.{self._attr_unique_id}" @property def device_info(self) -> DeviceInfo | None: - return self._coordinator.model.device_info + return self._coordinator.data.device_info @property def icon(self): diff --git a/custom_components/growcube/coordinator.py b/custom_components/growcube/coordinator.py index 15962d5..e754161 100644 --- a/custom_components/growcube/coordinator.py +++ b/custom_components/growcube/coordinator.py @@ -18,10 +18,7 @@ from homeassistant.helpers.device_registry import DeviceInfo from homeassistant.helpers.update_coordinator import DataUpdateCoordinator -from .binary_sensor import LockedStateSensor, WaterStateSensor, SensorFaultStateSensor, PumpLockedStateSensor, \ - PumpOpenStateSensor from .const import DOMAIN -from .sensor import TemperatureSensor, HumiditySensor, MoistureSensor _LOGGER = logging.getLogger(__name__) @@ -53,75 +50,21 @@ def __init__(self, host: str, hass: HomeAssistant): super().__init__(hass, _LOGGER, name=DOMAIN) self.entities = [] self.device_id = None - self.model: GrowcubeDataModel = GrowcubeDataModel(host) - - self.locked_state_sensor = LockedStateSensor(self) - self.water_state_sensor = WaterStateSensor(self) - self.pump_open_sensors = [ - PumpOpenStateSensor(self, 0), - PumpOpenStateSensor(self, 1), - PumpOpenStateSensor(self, 2), - PumpOpenStateSensor(self, 3) - ] - self.sensor_fault_state_sensors = [ - SensorFaultStateSensor(self, 0), - SensorFaultStateSensor(self, 1), - SensorFaultStateSensor(self, 2), - SensorFaultStateSensor(self, 3) - ] - self.pump_locked_state_sensors = [ - PumpLockedStateSensor(self, 0), - PumpLockedStateSensor(self, 1), - PumpLockedStateSensor(self, 2), - PumpLockedStateSensor(self, 3) - ] - self.binary_sensors = [ - self.locked_state_sensor, - self.water_state_sensor, - self.pump_open_sensors[0], - self.pump_open_sensors[1], - self.pump_open_sensors[2], - self.pump_open_sensors[3], - self.sensor_fault_state_sensors[0], - self.sensor_fault_state_sensors[1], - self.sensor_fault_state_sensors[2], - self.sensor_fault_state_sensors[3], - self.pump_locked_state_sensors[0], - self.pump_locked_state_sensors[1], - self.pump_locked_state_sensors[2], - self.pump_locked_state_sensors[3], - ] - - self.temperature_sensor = TemperatureSensor(self) - self.humidity_sensor = HumiditySensor(self) - self.moisture_sensors = [ - MoistureSensor(self, 0), - MoistureSensor(self, 1), - MoistureSensor(self, 2), - MoistureSensor(self, 3), - ] - self.sensors = [ - self.temperature_sensor, - self.humidity_sensor, - self.moisture_sensors[0], - self.moisture_sensors[1], - self.moisture_sensors[2], - self.moisture_sensors[3], - ] + self.data: GrowcubeDataModel = GrowcubeDataModel(host) def set_device_id(self, device_id: str) -> None: self.device_id = hex(int(device_id))[2:] - self.model.device_id = f"growcube_{self.device_id}" - self.model.device_info = { + self.data.device_id = f"growcube_{self.device_id}" + self.data.device_info = { "name": "GrowCube " + self.device_id, - "identifiers": {(DOMAIN, self.model.device_id)}, + "identifiers": {(DOMAIN, self.data.device_id)}, "manufacturer": "Elecrow", "model": "Growcube", - "sw_version": self.model.version + "sw_version": self.data.version } async def _async_update_data(self): - return self.model + return self.data async def connect(self) -> Tuple[bool, str]: result, error = await self.client.connect() @@ -129,9 +72,9 @@ async def connect(self) -> Tuple[bool, str]: return False, error # Wait for the device to send back the DeviceVersionGrowcubeReport - while not self.model.device_id: + while not self.data.device_id: await asyncio.sleep(0.1) - _LOGGER.debug("Growcube device id: %s", self.model.device_id) + _LOGGER.debug("Growcube device id: %s", self.data.device_id) return True, "" @staticmethod @@ -168,7 +111,7 @@ def on_connected(self, host: str) -> None: def on_disconnected(self, host: str) -> None: _LOGGER.debug(f"Connection to {host} lost") - self.hass.states.async_set(self.model.entity_id, STATE_UNAVAILABLE) + self.hass.states.async_set(DOMAIN + '.' + self.entity_id, STATE_UNAVAILABLE) def disconnect(self) -> None: """Disconnect from the Growcube device.""" @@ -178,50 +121,40 @@ def handle_report(self, report: GrowcubeReport): """Handle a report from the Growcube.""" if isinstance(report, DeviceVersionGrowcubeReport): _LOGGER.debug(f"Device device_id: {report.device_id}, version {report.version}") - self.model.version = report.version + self.data.version = report.version self.set_device_id(report.device_id) elif isinstance(report, WaterStateGrowcubeReport): _LOGGER.debug(f"Water state {report.water_warning}") - self.water_state_sensor.update(not report.water_warning) + self.data.water_state = report.water_warning elif isinstance(report, MoistureHumidityStateGrowcubeReport): _LOGGER.debug(f"Sensor reading, channel %s, humidity %s, temperature %s, moisture %s", report.channel, report.humidity, report.temperature, report.moisture) - self.humidity_sensor.update(report.humidity) - self.temperature_sensor.update(report.temperature) - self.moisture_sensors[report.channel.value].update(report.moisture) + self.data.humidity = report.humidity + self.data.temperature = report.temperature + self.data.moisture[report.channel.value] = report.moisture elif isinstance(report, PumpOpenGrowcubeReport): _LOGGER.debug(f"Pump open, channel {report.channel}") - self.pump_open_sensors[report.channel.value].update(True) + self.data.pump_open[report.channel.value] = True elif isinstance(report, PumpCloseGrowcubeReport): _LOGGER.debug(f"Pump closed, channel {report.channel}") - self.pump_open_sensors[report.channel.value].update(False) + self.data.pump_open[report.channel.value] = False elif isinstance(report, CheckSensorGrowcubeReport): # Investigate this one pass elif isinstance(report, CheckPumpBlockedGrowcubeReport): _LOGGER.debug(f"Pump blocked, channel {report.channel}") - self.pump_locked_state_sensors[report.channel].update(True) + self.data.pump_lock_state[report.channel] = True elif isinstance(report, CheckSensorNotConnectedGrowcubeReport): _LOGGER.debug(f"Check sensor, channel {report.channel}") - self.sensor_fault_state_sensors[report.channel.value].update(True) - self.moisture_sensors[report.channel.value].update(None) + self.data.sensor_state_sensors[report.channel.value] = True + #self.moisture_sensors[report.channel.value].update(None) elif isinstance(report, LockStateGrowcubeReport): _LOGGER.debug(f"Lock state, {report.lock_state}") - self.locked_state_sensor.update(report.lock_state) - self.model.device_lock_state = report.lock_state - if not report.lock_state: - # Reset all lock states - self.model.sensor_state[0].update(False) - self.model.sensor_state[1].update(False) - self.model.sensor_state[2].update(False) - self.model.sensor_state[3].update(False) - self.model.pump_lock_state[0].update(False) - self.model.pump_lock_state[1].update(False) - self.model.pump_lock_state[2].update(False) - self.model.pump_lock_state[3].update(False) + self.data.device_lock_state = report.lock_state + #self.async_set_updated_data(self.model) async def water_plant(self, channel: int) -> None: await self.client.water_plant(Channel(channel), 5) diff --git a/custom_components/growcube/sensor.py b/custom_components/growcube/sensor.py index 46c90ca..be2efdd 100644 --- a/custom_components/growcube/sensor.py +++ b/custom_components/growcube/sensor.py @@ -1,5 +1,5 @@ """Support for Growcube sensors.""" -from homeassistant.const import TEMP_CELSIUS, PERCENTAGE, UnitOfTemperature, Platform +from homeassistant.const import PERCENTAGE, UnitOfTemperature, Platform from homeassistant.components.sensor import SensorEntity, SensorDeviceClass from homeassistant.core import callback from homeassistant.helpers.device_registry import DeviceInfo @@ -15,62 +15,60 @@ async def async_setup_entry(hass, entry, async_add_entities): """Set up the Growcube sensors.""" coordinator = hass.data[DOMAIN][entry.entry_id] - async_add_entities(coordinator.sensors, True) + async_add_entities([TemperatureSensor(coordinator), + HumiditySensor(coordinator), + MoistureSensor(coordinator, 0), + MoistureSensor(coordinator, 1), + MoistureSensor(coordinator, 2), + MoistureSensor(coordinator, 3)], True) -class TemperatureSensor(CoordinatorEntity, SensorEntity): - def __init__(self, coordinator: GrowcubeDataCoordinator): - super().__init__(coordinator) +class TemperatureSensor(SensorEntity): + def __init__(self, coordinator: GrowcubeDataCoordinator) -> None: + #super.__init__(coordinator) self._coordinator = coordinator self._coordinator.entities.append(self) - self._attr_unique_id = f"{coordinator.model.device_id}" + "_temperature" + self._attr_unique_id = f"{coordinator.data.device_id}" + "_temperature" self.entity_id = f"{Platform.SENSOR}.{self._attr_unique_id}" - self._attr_native_value = coordinator.model.temperature + self._attr_native_value = coordinator.data.temperature self._attr_name = "Temperature" self._attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS self._attr_device_class = SensorDeviceClass.TEMPERATURE + self.temperature = coordinator.data.temperature @property def device_info(self) -> DeviceInfo | None: - return self._coordinator.model.device_info + return self._coordinator.data.device_info @callback - def update(self, temperature: int) -> None: - _LOGGER.debug("Update temperature %s", temperature) - if self._coordinator.model.temperature != temperature: - self._coordinator.model.temperature = temperature - self._attr_native_value = self._coordinator.model.temperature - self.async_write_ha_state() + def update(self) -> None: + _LOGGER.debug("Update temperature %s", self._coordinator.data.temperature) + if self._coordinator.data.temperature != self.temperature: + self._attr_native_value = self._coordinator.data.temperature + self.schedule_update_ha_state() class HumiditySensor(SensorEntity): def __init__(self, coordinator: GrowcubeDataCoordinator) -> None: self._coordinator = coordinator self._coordinator.entities.append(self) - self._attr_unique_id = f"{coordinator.model.device_id}" + "_humidity" + self._attr_unique_id = f"{coordinator.data.device_id}" + "_humidity" self.entity_id = f"{Platform.SENSOR}.{self._attr_unique_id}" - self._attr_native_value = coordinator.model.humidity + self._attr_native_value = coordinator.data.humidity self._attr_name = "Humidity" self._attr_native_unit_of_measurement = PERCENTAGE self._attr_device_class = SensorDeviceClass.HUMIDITY @property def device_info(self) -> DeviceInfo | None: - return self._coordinator.model.device_info - - @callback - def _handle_coordinator_update(self) -> None: - _LOGGER.debug("Update humidity %s", self._coordinator.model.humidity) - self._attr_native_value = self._coordinator.model.humidity - self.async_write_ha_state() + return self._coordinator.data.device_info @callback - def update(self, humidity: int) -> None: - _LOGGER.debug("Update humidity %s", humidity) - if self._coordinator.model.humidity != humidity: - self._coordinator.model.humidity = humidity - self._attr_native_value = humidity - self.async_write_ha_state() + def update(self) -> None: + _LOGGER.debug("Update humidity %s", self._coordinator.data.humidity) + if self._coordinator.data.humidity != self._attr_native_value: + self._attr_native_value = self._coordinator.data.humidity + self.schedule_update_ha_state() class MoistureSensor(SensorEntity): _channel_name = ['A', 'B', 'C', 'D'] @@ -81,25 +79,24 @@ def __init__(self, coordinator: GrowcubeDataCoordinator, channel: int) -> None: self._coordinator = coordinator self._coordinator.entities.append(self) self._channel = channel - self._attr_unique_id = f"{coordinator.model.device_id}" + "_moisture_" + self._channel_id[self._channel] + self._attr_unique_id = f"{coordinator.data.device_id}" + "_moisture_" + self._channel_id[self._channel] self.entity_id = f"{Platform.SENSOR}.{self._attr_unique_id}" self._attr_name = "Moisture " + self._channel_name[self._channel] self._attr_native_unit_of_measurement = PERCENTAGE self._attr_device_class = SensorDeviceClass.MOISTURE - self._attr_native_value = coordinator.model.moisture[self._channel] + self._attr_native_value = coordinator.data.moisture[self._channel] @property def device_info(self) -> DeviceInfo | None: - return self._coordinator.model.device_info + return self._coordinator.data.device_info @property def icon(self): return "mdi:cup-water" @callback - def update(self, moisture: int) -> None: - _LOGGER.debug("Update moisture[%s] %s", self._channel, moisture) - if self._coordinator.model.moisture[self._channel] != moisture: - self._coordinator.model.moisture[self._channel] = moisture - self._attr_native_value = moisture - self.async_write_ha_state() \ No newline at end of file + def update(self) -> None: + _LOGGER.debug("Update moisture[%s] %s", self._channel, self._coordinator.data.moisture[self._channel]) + if self._coordinator.data.moisture[self._channel] != self._attr_native_value: + self._attr_native_value = self._coordinator.data.moisture[self._channel] + self.schedule_update_ha_state() \ No newline at end of file