diff --git a/homeassistant/components/mutesync/__init__.py b/homeassistant/components/mutesync/__init__.py index 7bee5ff5a9b..af14725a3b4 100644 --- a/homeassistant/components/mutesync/__init__.py +++ b/homeassistant/components/mutesync/__init__.py @@ -1,7 +1,6 @@ """The mütesync integration.""" from __future__ import annotations -from datetime import timedelta import logging import async_timeout @@ -11,7 +10,7 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant 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"] @@ -27,7 +26,17 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: async def update_data(): """Update the data.""" 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, {})[ entry.entry_id @@ -35,7 +44,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: hass, logging.getLogger(__name__), name=DOMAIN, - update_interval=timedelta(seconds=5), + update_interval=UPDATE_INTERVAL_NOT_IN_MEETING, update_method=update_data, ) await coordinator.async_config_entry_first_refresh() diff --git a/homeassistant/components/mutesync/const.py b/homeassistant/components/mutesync/const.py index fcf05584f42..5e288b405af 100644 --- a/homeassistant/components/mutesync/const.py +++ b/homeassistant/components/mutesync/const.py @@ -1,3 +1,8 @@ """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)