mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 17:27:52 +00:00
Align Shelly sleeping devices timeout with non-sleeping (#118969)
This commit is contained in:
parent
d8ab2debfd
commit
4c6cbadc11
@ -83,11 +83,9 @@ REST_SENSORS_UPDATE_INTERVAL: Final = 60
|
||||
# Refresh interval for RPC polling sensors
|
||||
RPC_SENSORS_POLLING_INTERVAL: Final = 60
|
||||
|
||||
# Multiplier used to calculate the "update_interval" for sleeping devices.
|
||||
SLEEP_PERIOD_MULTIPLIER: Final = 1.2
|
||||
CONF_SLEEP_PERIOD: Final = "sleep_period"
|
||||
|
||||
# Multiplier used to calculate the "update_interval" for non-sleeping devices.
|
||||
# Multiplier used to calculate the "update_interval" for shelly devices.
|
||||
UPDATE_PERIOD_MULTIPLIER: Final = 2.2
|
||||
|
||||
# Reconnect interval for GEN2 devices
|
||||
|
@ -54,7 +54,6 @@ from .const import (
|
||||
RPC_RECONNECT_INTERVAL,
|
||||
RPC_SENSORS_POLLING_INTERVAL,
|
||||
SHBTN_MODELS,
|
||||
SLEEP_PERIOD_MULTIPLIER,
|
||||
UPDATE_PERIOD_MULTIPLIER,
|
||||
BLEScannerMode,
|
||||
)
|
||||
@ -229,7 +228,7 @@ class ShellyBlockCoordinator(ShellyCoordinatorBase[BlockDevice]):
|
||||
"""Initialize the Shelly block device coordinator."""
|
||||
self.entry = entry
|
||||
if self.sleep_period:
|
||||
update_interval = SLEEP_PERIOD_MULTIPLIER * self.sleep_period
|
||||
update_interval = UPDATE_PERIOD_MULTIPLIER * self.sleep_period
|
||||
else:
|
||||
update_interval = (
|
||||
UPDATE_PERIOD_MULTIPLIER * device.settings["coiot"]["update_period"]
|
||||
@ -429,7 +428,7 @@ class ShellyRestCoordinator(ShellyCoordinatorBase[BlockDevice]):
|
||||
in BATTERY_DEVICES_WITH_PERMANENT_CONNECTION
|
||||
):
|
||||
update_interval = (
|
||||
SLEEP_PERIOD_MULTIPLIER * device.settings["coiot"]["update_period"]
|
||||
UPDATE_PERIOD_MULTIPLIER * device.settings["coiot"]["update_period"]
|
||||
)
|
||||
super().__init__(hass, entry, device, update_interval)
|
||||
|
||||
@ -459,7 +458,7 @@ class ShellyRpcCoordinator(ShellyCoordinatorBase[RpcDevice]):
|
||||
"""Initialize the Shelly RPC device coordinator."""
|
||||
self.entry = entry
|
||||
if self.sleep_period:
|
||||
update_interval = SLEEP_PERIOD_MULTIPLIER * self.sleep_period
|
||||
update_interval = UPDATE_PERIOD_MULTIPLIER * self.sleep_period
|
||||
else:
|
||||
update_interval = RPC_RECONNECT_INTERVAL
|
||||
super().__init__(hass, entry, device, update_interval)
|
||||
@ -486,7 +485,7 @@ class ShellyRpcCoordinator(ShellyCoordinatorBase[RpcDevice]):
|
||||
data[CONF_SLEEP_PERIOD] = wakeup_period
|
||||
self.hass.config_entries.async_update_entry(self.entry, data=data)
|
||||
|
||||
update_interval = SLEEP_PERIOD_MULTIPLIER * wakeup_period
|
||||
update_interval = UPDATE_PERIOD_MULTIPLIER * wakeup_period
|
||||
self.update_interval = timedelta(seconds=update_interval)
|
||||
|
||||
return True
|
||||
|
@ -7,7 +7,7 @@ from freezegun.api import FrozenDateTimeFactory
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN
|
||||
from homeassistant.components.shelly.const import SLEEP_PERIOD_MULTIPLIER
|
||||
from homeassistant.components.shelly.const import UPDATE_PERIOD_MULTIPLIER
|
||||
from homeassistant.const import STATE_OFF, STATE_ON, STATE_UNKNOWN
|
||||
from homeassistant.core import HomeAssistant, State
|
||||
from homeassistant.helpers.device_registry import DeviceRegistry
|
||||
@ -122,7 +122,7 @@ async def test_block_rest_binary_sensor_connected_battery_devices(
|
||||
assert hass.states.get(entity_id).state == STATE_OFF
|
||||
|
||||
# Verify update on slow intervals
|
||||
await mock_rest_update(hass, freezer, seconds=SLEEP_PERIOD_MULTIPLIER * 3600)
|
||||
await mock_rest_update(hass, freezer, seconds=UPDATE_PERIOD_MULTIPLIER * 3600)
|
||||
assert hass.states.get(entity_id).state == STATE_ON
|
||||
|
||||
entry = entity_registry.async_get(entity_id)
|
||||
|
@ -20,7 +20,6 @@ from homeassistant.components.shelly.const import (
|
||||
ENTRY_RELOAD_COOLDOWN,
|
||||
MAX_PUSH_UPDATE_FAILURES,
|
||||
RPC_RECONNECT_INTERVAL,
|
||||
SLEEP_PERIOD_MULTIPLIER,
|
||||
UPDATE_PERIOD_MULTIPLIER,
|
||||
BLEScannerMode,
|
||||
)
|
||||
@ -564,7 +563,7 @@ async def test_rpc_update_entry_sleep_period(
|
||||
|
||||
# Move time to generate sleep period update
|
||||
monkeypatch.setitem(mock_rpc_device.status["sys"], "wakeup_period", 3600)
|
||||
freezer.tick(timedelta(seconds=600 * SLEEP_PERIOD_MULTIPLIER))
|
||||
freezer.tick(timedelta(seconds=600 * UPDATE_PERIOD_MULTIPLIER))
|
||||
async_fire_time_changed(hass)
|
||||
await hass.async_block_till_done(wait_background_tasks=True)
|
||||
|
||||
@ -596,7 +595,7 @@ async def test_rpc_sleeping_device_no_periodic_updates(
|
||||
assert get_entity_state(hass, entity_id) == "22.9"
|
||||
|
||||
# Move time to generate polling
|
||||
freezer.tick(timedelta(seconds=SLEEP_PERIOD_MULTIPLIER * 1000))
|
||||
freezer.tick(timedelta(seconds=UPDATE_PERIOD_MULTIPLIER * 1000))
|
||||
async_fire_time_changed(hass)
|
||||
await hass.async_block_till_done(wait_background_tasks=True)
|
||||
|
||||
@ -889,7 +888,7 @@ async def test_block_sleeping_device_connection_error(
|
||||
assert get_entity_state(hass, entity_id) == STATE_ON
|
||||
|
||||
# Move time to generate sleep period update
|
||||
freezer.tick(timedelta(seconds=sleep_period * SLEEP_PERIOD_MULTIPLIER))
|
||||
freezer.tick(timedelta(seconds=sleep_period * UPDATE_PERIOD_MULTIPLIER))
|
||||
async_fire_time_changed(hass)
|
||||
await hass.async_block_till_done(wait_background_tasks=True)
|
||||
|
||||
@ -934,7 +933,7 @@ async def test_rpc_sleeping_device_connection_error(
|
||||
assert get_entity_state(hass, entity_id) == STATE_ON
|
||||
|
||||
# Move time to generate sleep period update
|
||||
freezer.tick(timedelta(seconds=sleep_period * SLEEP_PERIOD_MULTIPLIER))
|
||||
freezer.tick(timedelta(seconds=sleep_period * UPDATE_PERIOD_MULTIPLIER))
|
||||
async_fire_time_changed(hass)
|
||||
await hass.async_block_till_done(wait_background_tasks=True)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user