Skip to content

Commit 6c85ad1

Browse files
committed
Branch p8.
1 parent 6041ea0 commit 6c85ad1

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

custom_components/modbus/entity.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from homeassistant.core import HomeAssistant, callback
2929
from homeassistant.helpers.dispatcher import async_dispatcher_connect
3030
from homeassistant.helpers.entity import Entity, ToggleEntity
31-
from homeassistant.helpers.event import async_call_later, async_track_time_interval
31+
from homeassistant.helpers.event import async_call_later
3232
from homeassistant.helpers.restore_state import RestoreEntity
3333

3434
from .const import (
@@ -117,13 +117,19 @@ async def _async_update(self) -> None:
117117

118118
async def async_update(self, now: datetime | None = None) -> None:
119119
"""Update the entity state."""
120-
async with self._update_lock:
121-
await self._async_update()
120+
await self._async_update()
121+
self.async_write_ha_state()
122+
if self._scan_interval > 0:
123+
self._cancel_call = async_call_later(
124+
self.hass, timedelta(seconds=self._scan_interval), self.async_update
125+
)
122126

123127
async def _async_update_write_state(self) -> None:
124128
"""Update the entity state and write it to the state machine."""
129+
if self._cancel_call:
130+
self._cancel_call()
131+
self._cancel_call = None
125132
await self.async_update()
126-
self.async_write_ha_state()
127133

128134
async def _async_update_if_not_in_progress(
129135
self, now: datetime | None = None
@@ -139,12 +145,9 @@ def async_run(self) -> None:
139145
"""Remote start entity."""
140146
self._async_cancel_update_polling()
141147
self._async_schedule_future_update(0.1)
142-
if self._scan_interval > 0:
143-
self._cancel_timer = async_track_time_interval(
144-
self.hass,
145-
self._async_update_if_not_in_progress,
146-
timedelta(seconds=self._scan_interval),
147-
)
148+
self._cancel_call = async_call_later(
149+
self.hass, timedelta(seconds=0.1), self.async_update
150+
)
148151
self._attr_available = True
149152
self.async_write_ha_state()
150153

custom_components/modbus/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
"iot_class": "local_polling",
77
"loggers": ["pymodbus"],
88
"requirements": ["pymodbus==3.9.2"],
9-
"version": "1.7.0"
9+
"version": "1.8.0"
1010
}

0 commit comments

Comments
 (0)