mirror of
https://github.com/home-assistant/core.git
synced 2025-11-14 13:30:43 +00:00
* Implemented coordinator (for Cloud integration) * Optimized coordinator updates * Finalizing * Running ruff and ruff format * Raise error if trying to instantiate coordinator for a AdaxLocal config * Re-added data-handler for AdaxLocal integrations * Added a coordinator for Local integrations * mypy warnings * Update homeassistant/components/adax/manifest.json Co-authored-by: Daniel Hjelseth Høyer <mail@dahoiv.net> * Resolve mypy issues * PR comments - Explicit passing of config_entry to Coordinator base type - Avoid duplicate storing of Coordinator data. Instead use self.data - Remove try-catch and wrapping to UpdateFailed in _async_update_data - Custom ConfigEntry type for passing coordinator via entry.runtime_data * When changing HVAC_MODE update data via Coordinator to optimize * Apply already loaded data for Climate entity directly in __init__ * Moved SCAN_INTERVAL into const.py * Removed logging statements * Remove unnecessary get_rooms() / get_status() functions * Resolvning mypy issues * Adding tests for coordinators * Resolving review comments by joostlek * Setup of Cloud devices with device_id * Implement Climate tests for Adax * Implementing assertions of UNAVAILABLE state * Removed no longer needed method * Apply suggestions from code review Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Mock Adax class instead of individual methods * Mock config entry via fixture * Load config entry data from .json fixture * Hard code config_entry_data instead of .json file * Removed obsolete .json-files * Fix * Fix --------- Co-authored-by: Daniel Hjelseth Høyer <mail@dahoiv.net> Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
48 lines
1.5 KiB
Python
48 lines
1.5 KiB
Python
"""The Adax integration."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from homeassistant.const import Platform
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from .const import CONNECTION_TYPE, LOCAL
|
|
from .coordinator import AdaxCloudCoordinator, AdaxConfigEntry, AdaxLocalCoordinator
|
|
|
|
PLATFORMS = [Platform.CLIMATE]
|
|
|
|
|
|
async def async_setup_entry(hass: HomeAssistant, entry: AdaxConfigEntry) -> bool:
|
|
"""Set up Adax from a config entry."""
|
|
if entry.data.get(CONNECTION_TYPE) == LOCAL:
|
|
local_coordinator = AdaxLocalCoordinator(hass, entry)
|
|
entry.runtime_data = local_coordinator
|
|
else:
|
|
cloud_coordinator = AdaxCloudCoordinator(hass, entry)
|
|
entry.runtime_data = cloud_coordinator
|
|
|
|
await entry.runtime_data.async_config_entry_first_refresh()
|
|
|
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
|
return True
|
|
|
|
|
|
async def async_unload_entry(hass: HomeAssistant, entry: AdaxConfigEntry) -> bool:
|
|
"""Unload a config entry."""
|
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
|
|
|
|
|
async def async_migrate_entry(
|
|
hass: HomeAssistant, config_entry: AdaxConfigEntry
|
|
) -> bool:
|
|
"""Migrate old entry."""
|
|
# convert title and unique_id to string
|
|
if config_entry.version == 1:
|
|
if isinstance(config_entry.unique_id, int):
|
|
hass.config_entries.async_update_entry( # type: ignore[unreachable]
|
|
config_entry,
|
|
unique_id=str(config_entry.unique_id),
|
|
title=str(config_entry.title),
|
|
)
|
|
|
|
return True
|