Decrease timeout and update_interval in Xiaomi Miio integration (#57339)

* Decrease timeout and update_interval

* Improve UPDATE_INTERVAL const

* Update values after testing
This commit is contained in:
Maciej Bieniek 2021-10-17 03:13:12 +02:00 committed by GitHub
parent c76e15149c
commit 276345e20a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -73,6 +73,9 @@ from .gateway import ConnectXiaomiGateway
_LOGGER = logging.getLogger(__name__)
POLLING_TIMEOUT_SEC = 10
UPDATE_INTERVAL = timedelta(seconds=15)
GATEWAY_PLATFORMS = ["alarm_control_panel", "light", "sensor", "switch"]
SWITCH_PLATFORMS = ["switch"]
FAN_PLATFORMS = ["binary_sensor", "fan", "number", "select", "sensor", "switch"]
@ -151,7 +154,7 @@ def _async_update_data_default(hass, device):
async def _async_fetch_data():
"""Fetch data from the device."""
async with async_timeout.timeout(10):
async with async_timeout.timeout(POLLING_TIMEOUT_SEC):
state = await hass.async_add_executor_job(device.status)
_LOGGER.debug("Got new state: %s", state)
return state
@ -239,7 +242,7 @@ def _async_update_data_vacuum(hass, device: Vacuum):
"""Fetch data from the device using async_add_executor_job."""
async def execute_update():
async with async_timeout.timeout(10):
async with async_timeout.timeout(POLLING_TIMEOUT_SEC):
state = await hass.async_add_executor_job(update)
_LOGGER.debug("Got new vacuum state: %s", state)
return state
@ -336,7 +339,7 @@ async def async_create_miio_device_and_coordinator(
name=name,
update_method=update_method(hass, device),
# Polling interval. Will only be polled if there are subscribers.
update_interval=timedelta(seconds=60),
update_interval=UPDATE_INTERVAL,
)
hass.data[DOMAIN][entry.entry_id] = {
KEY_DEVICE: device,
@ -409,7 +412,7 @@ async def async_setup_gateway_entry(
name=name,
update_method=async_update_data,
# Polling interval. Will only be polled if there are subscribers.
update_interval=timedelta(seconds=10),
update_interval=UPDATE_INTERVAL,
)
hass.data[DOMAIN][entry.entry_id] = {