mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Add Mutesync dynamic update interval and catch invalid response values (#50764)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
parent
927b5361a3
commit
0327d0b6db
@ -1,7 +1,6 @@
|
|||||||
"""The mütesync integration."""
|
"""The mütesync integration."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from datetime import timedelta
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import async_timeout
|
import async_timeout
|
||||||
@ -11,7 +10,7 @@ from homeassistant.config_entries import ConfigEntry
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import update_coordinator
|
from homeassistant.helpers import update_coordinator
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN, UPDATE_INTERVAL_IN_MEETING, UPDATE_INTERVAL_NOT_IN_MEETING
|
||||||
|
|
||||||
PLATFORMS = ["binary_sensor"]
|
PLATFORMS = ["binary_sensor"]
|
||||||
|
|
||||||
@ -27,7 +26,17 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
async def update_data():
|
async def update_data():
|
||||||
"""Update the data."""
|
"""Update the data."""
|
||||||
async with async_timeout.timeout(2.5):
|
async with async_timeout.timeout(2.5):
|
||||||
return await client.get_state()
|
state = await client.get_state()
|
||||||
|
|
||||||
|
if state["muted"] is None or state["in_meeting"] is None:
|
||||||
|
raise update_coordinator.UpdateFailed("Got invalid response")
|
||||||
|
|
||||||
|
if state["in_meeting"]:
|
||||||
|
coordinator.update_interval = UPDATE_INTERVAL_IN_MEETING
|
||||||
|
else:
|
||||||
|
coordinator.update_interval = UPDATE_INTERVAL_NOT_IN_MEETING
|
||||||
|
|
||||||
|
return state
|
||||||
|
|
||||||
coordinator = hass.data.setdefault(DOMAIN, {})[
|
coordinator = hass.data.setdefault(DOMAIN, {})[
|
||||||
entry.entry_id
|
entry.entry_id
|
||||||
@ -35,7 +44,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
hass,
|
hass,
|
||||||
logging.getLogger(__name__),
|
logging.getLogger(__name__),
|
||||||
name=DOMAIN,
|
name=DOMAIN,
|
||||||
update_interval=timedelta(seconds=5),
|
update_interval=UPDATE_INTERVAL_NOT_IN_MEETING,
|
||||||
update_method=update_data,
|
update_method=update_data,
|
||||||
)
|
)
|
||||||
await coordinator.async_config_entry_first_refresh()
|
await coordinator.async_config_entry_first_refresh()
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
"""Constants for the mütesync integration."""
|
"""Constants for the mütesync integration."""
|
||||||
|
from datetime import timedelta
|
||||||
|
from typing import Final
|
||||||
|
|
||||||
DOMAIN = "mutesync"
|
DOMAIN: Final = "mutesync"
|
||||||
|
|
||||||
|
UPDATE_INTERVAL_NOT_IN_MEETING: Final = timedelta(seconds=10)
|
||||||
|
UPDATE_INTERVAL_IN_MEETING: Final = timedelta(seconds=5)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user