diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1d60150..6c27cbc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -15,9 +15,9 @@ repos: hooks: - id: mypy additional_dependencies: - - aiovantage==0.12.8 + - aiovantage==0.13.0b2 - voluptuous-stubs==0.1.1 - - homeassistant-stubs==2023.9.0 + - homeassistant-stubs==2023.9.2 args: [] - repo: https://github.com/thlorenz/doctoc diff --git a/custom_components/vantage/__init__.py b/custom_components/vantage/__init__.py index e14975a..d0cd946 100644 --- a/custom_components/vantage/__init__.py +++ b/custom_components/vantage/__init__.py @@ -1,11 +1,15 @@ """The Vantage InFusion Controller integration.""" -from aiovantage import Vantage +import asyncio +from typing import Any + +from aiovantage import Vantage, VantageEvent from aiovantage.errors import ( ClientConnectionError, LoginFailedError, LoginRequiredError, ) +from aiovantage.models import Master from homeassistant.config_entries import ( ConfigEntry, @@ -38,6 +42,9 @@ Platform.TEXT, ] +# How long to wait after receiving a system programming event before refreshing +SYSTEM_PROGRAMMING_DELAY = 30 + async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up Vantage integration from a config entry.""" @@ -71,6 +78,25 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: # Clean up any orphaned entities async_cleanup_entities(hass, entry) + # Subscribe to system programming events + async def handle_system_program_event( + event: VantageEvent, obj: Master, data: dict[str, Any] + ) -> None: + # Return early if the last_updated attribute did not change + if "last_updated" not in data.get("attrs_changed", []): + return + + # The last_updated attribute changes at the start of system programming. + # Unfortunately, the Vantage controller does not send an event when + # programming ends, so we must wait for a short time before refreshing + # controllers to avoid fetching incomplete data. + await asyncio.sleep(SYSTEM_PROGRAMMING_DELAY) + await vantage.initialize() + + vantage.masters.subscribe( + handle_system_program_event, event_filter=VantageEvent.OBJECT_UPDATED + ) + except (LoginFailedError, LoginRequiredError) as err: # Handle expired or invalid credentials. This will prompt the user to # reconfigure the integration. diff --git a/custom_components/vantage/climate.py b/custom_components/vantage/climate.py index 47ea52d..b8f1be3 100644 --- a/custom_components/vantage/climate.py +++ b/custom_components/vantage/climate.py @@ -46,7 +46,7 @@ } VANTAGE_FAN_MODE_MAP = { - Thermostat.FanMode.OFF: FAN_AUTO, + Thermostat.FanMode.AUTO: FAN_AUTO, Thermostat.FanMode.ON: FAN_ON, } diff --git a/custom_components/vantage/manifest.json b/custom_components/vantage/manifest.json index cf36601..c092c4e 100644 --- a/custom_components/vantage/manifest.json +++ b/custom_components/vantage/manifest.json @@ -17,7 +17,7 @@ "custom_components.vantage" ], "requirements": [ - "aiovantage==0.12.8" + "aiovantage==0.13.0b2" ], "version": "0.10.1", "zeroconf": [ diff --git a/requirements.txt b/requirements.txt index 6de7c45..94a237d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,16 +1,16 @@ # Home assistant -homeassistant==2023.9.0 +homeassistant==2023.9.2 colorlog==6.7.0 # Use a specific version of aiovantage -aiovantage==0.12.8 +aiovantage==0.13.0b2 # Use a local version of aiovantage # -e ../aiovantage # Type stubs voluptuous-stubs==0.1.1 -homeassistant-stubs==2023.9.1 +homeassistant-stubs==2023.9.2 # Linting, etc black==23.9.1