28
28
from homeassistant .core import HomeAssistant , callback
29
29
from homeassistant .helpers .dispatcher import async_dispatcher_connect
30
30
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
32
32
from homeassistant .helpers .restore_state import RestoreEntity
33
33
34
34
from .const import (
@@ -117,13 +117,19 @@ async def _async_update(self) -> None:
117
117
118
118
async def async_update (self , now : datetime | None = None ) -> None :
119
119
"""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
+ )
122
126
123
127
async def _async_update_write_state (self ) -> None :
124
128
"""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
125
132
await self .async_update ()
126
- self .async_write_ha_state ()
127
133
128
134
async def _async_update_if_not_in_progress (
129
135
self , now : datetime | None = None
@@ -139,12 +145,9 @@ def async_run(self) -> None:
139
145
"""Remote start entity."""
140
146
self ._async_cancel_update_polling ()
141
147
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
+ )
148
151
self ._attr_available = True
149
152
self .async_write_ha_state ()
150
153
0 commit comments