From ddfdbd3e2b904d448d03fef203a4718de47afcd7 Mon Sep 17 00:00:00 2001 From: jan iversen Date: Tue, 12 Sep 2023 08:47:52 +0200 Subject: [PATCH] Review comments. --- homeassistant/components/modbus/base_platform.py | 4 +++- homeassistant/components/modbus/sensor.py | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/modbus/base_platform.py b/homeassistant/components/modbus/base_platform.py index 3d8f87462737ae..0db716c3403b8f 100644 --- a/homeassistant/components/modbus/base_platform.py +++ b/homeassistant/components/modbus/base_platform.py @@ -115,7 +115,9 @@ async def async_update(self, now: datetime | None = None) -> None: def async_run(self) -> None: """Remote start entity.""" self.async_hold(update=False) - async_call_later(self.hass, timedelta(milliseconds=100), self.async_update) + self._cancel_call = async_call_later( + self.hass, timedelta(milliseconds=100), self.async_update + ) if self._scan_interval > 0: self._cancel_timer = async_track_time_interval( self.hass, self.async_update, timedelta(seconds=self._scan_interval) diff --git a/homeassistant/components/modbus/sensor.py b/homeassistant/components/modbus/sensor.py index e9d0160237d37e..f2ed504b41b5e5 100644 --- a/homeassistant/components/modbus/sensor.py +++ b/homeassistant/components/modbus/sensor.py @@ -107,13 +107,16 @@ async def async_update(self, now: datetime | None = None) -> None: """Update the state of the sensor.""" # remark "now" is a dummy parameter to avoid problems with # async_track_time_interval + self._cancel_call = None raw_result = await self._hub.async_pb_call( self._slave, self._address, self._count, self._input_type ) if raw_result is None: if self._lazy_errors: self._lazy_errors -= 1 - async_call_later(self.hass, timedelta(seconds=1), self.async_update) + self._cancel_call = async_call_later( + self.hass, timedelta(seconds=1), self.async_update + ) return self._lazy_errors = self._lazy_error_count self._attr_available = False