Skip to content

Commit f725a37

Browse files
committed
Branch p9.
1 parent 6c85ad1 commit f725a37

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

custom_components/modbus/entity.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ def __init__(
9090
self._address = int(entry[CONF_ADDRESS])
9191
self._input_type = entry[CONF_INPUT_TYPE]
9292
self._scan_interval = int(entry[CONF_SCAN_INTERVAL])
93-
self._cancel_timer: Callable[[], None] | None = None
9493
self._cancel_call: Callable[[], None] | None = None
9594

9695
self._attr_unique_id = entry.get(CONF_UNIQUE_ID)
@@ -124,6 +123,21 @@ async def async_update(self, now: datetime | None = None) -> None:
124123
self.hass, timedelta(seconds=self._scan_interval), self.async_update
125124
)
126125

126+
async def async_will_remove_from_hass(self) -> None:
127+
"""Remove entity from hass."""
128+
_LOGGER.info(f"Removing entity {self._attr_name}")
129+
if self._cancel_call:
130+
self._cancel_call()
131+
self._cancel_call = None
132+
133+
@callback
134+
def async_hold(self) -> None:
135+
"""Remote stop entity."""
136+
_LOGGER.info(f"hold entity {self._attr_name}")
137+
self._async_cancel_future_pending_update()
138+
self._attr_available = False
139+
self.async_write_ha_state()
140+
127141
async def _async_update_write_state(self) -> None:
128142
"""Update the entity state and write it to the state machine."""
129143
if self._cancel_call:
@@ -143,7 +157,7 @@ async def _async_update_if_not_in_progress(
143157
@callback
144158
def async_run(self) -> None:
145159
"""Remote start entity."""
146-
self._async_cancel_update_polling()
160+
_LOGGER.info(f"start entity {self._attr_name}")
147161
self._async_schedule_future_update(0.1)
148162
self._cancel_call = async_call_later(
149163
self.hass, timedelta(seconds=0.1), self.async_update
@@ -166,20 +180,6 @@ def _async_cancel_future_pending_update(self) -> None:
166180
self._cancel_call()
167181
self._cancel_call = None
168182

169-
def _async_cancel_update_polling(self) -> None:
170-
"""Cancel the polling."""
171-
if self._cancel_timer:
172-
self._cancel_timer()
173-
self._cancel_timer = None
174-
175-
@callback
176-
def async_hold(self) -> None:
177-
"""Remote stop entity."""
178-
self._async_cancel_future_pending_update()
179-
self._async_cancel_update_polling()
180-
self._attr_available = False
181-
self.async_write_ha_state()
182-
183183
async def async_await_connection(self, _now: Any) -> None:
184184
"""Wait for first connect."""
185185
await self._hub.event_connected.wait()

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.8.0"
9+
"version": "1.9.0"
1010
}

0 commit comments

Comments
 (0)