Read modbus data before scan_interval (#99243)

Read before scan_interval.
pull/99545/head
jan iversen 2023-09-03 17:13:49 +02:00 committed by GitHub
parent c297eecb68
commit c94d4f501b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 3 additions and 8 deletions

View File

@ -30,7 +30,6 @@ from homeassistant.helpers.event import async_call_later, async_track_time_inter
from homeassistant.helpers.restore_state import RestoreEntity
from .const import (
ACTIVE_SCAN_INTERVAL,
CALL_TYPE_COIL,
CALL_TYPE_DISCRETE,
CALL_TYPE_REGISTER_HOLDING,
@ -115,8 +114,7 @@ class BasePlatform(Entity):
def async_run(self) -> None:
"""Remote start entity."""
self.async_hold(update=False)
if self._scan_interval == 0 or self._scan_interval > ACTIVE_SCAN_INTERVAL:
self._cancel_call = async_call_later(self.hass, 1, self.async_update)
self._cancel_call = async_call_later(self.hass, 1, 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)

View File

@ -149,7 +149,7 @@ async def mock_do_cycle_fixture(
mock_pymodbus_return,
) -> FrozenDateTimeFactory:
"""Trigger update call with time_changed event."""
freezer.tick(timedelta(seconds=90))
freezer.tick(timedelta(seconds=1))
async_fire_time_changed(hass)
await hass.async_block_till_done()
return freezer

View File

@ -267,7 +267,6 @@ async def test_config_wrong_struct_sensor(
{
CONF_NAME: TEST_ENTITY_NAME,
CONF_ADDRESS: 51,
CONF_SCAN_INTERVAL: 1,
},
],
},
@ -710,7 +709,6 @@ async def test_slave_sensor(hass: HomeAssistant, mock_do_cycle, expected) -> Non
CONF_NAME: TEST_ENTITY_NAME,
CONF_ADDRESS: 51,
CONF_INPUT_TYPE: CALL_TYPE_REGISTER_HOLDING,
CONF_SCAN_INTERVAL: 1,
},
],
},
@ -935,7 +933,7 @@ async def test_lazy_error_sensor(
hass.states.async_set(ENTITY_ID, 17)
await hass.async_block_till_done()
assert hass.states.get(ENTITY_ID).state == start_expect
await do_next_cycle(hass, mock_do_cycle, 11)
await do_next_cycle(hass, mock_do_cycle, 5)
assert hass.states.get(ENTITY_ID).state == start_expect
await do_next_cycle(hass, mock_do_cycle, 11)
assert hass.states.get(ENTITY_ID).state == end_expect
@ -1003,7 +1001,6 @@ async def test_struct_sensor(hass: HomeAssistant, mock_do_cycle, expected) -> No
{
CONF_NAME: TEST_ENTITY_NAME,
CONF_ADDRESS: 201,
CONF_SCAN_INTERVAL: 1,
},
],
},