Skip to content

Commit 712042f

Browse files
committed
Modernize to Home Assistant 2025.2+ standards
- Update manifest.json with homeassistant: "2025.2.0", integration_type: "device", iot_class: "local_polling" - Add DataUpdateCoordinator pattern for centralized data management - Modernize config_flow.py with SelectSelector, TextSelector, and options flow - Add diagnostics.py for troubleshooting support - Update strings.json and translations/en.json with UX-focused labels and descriptions - Update Python code with modern type hints (| unions, lowercase dict/list) - Add comprehensive test suite with pytest fixtures - Fix all ruff lint errors - Bump version to 0.3.0 and require Python 3.13+
1 parent f0c44f7 commit 712042f

24 files changed

+1776
-710
lines changed
Lines changed: 29 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,63 @@
1-
"""
2-
The McIntosh A/V integration.
3-
"""
1+
"""The McIntosh A/V integration."""
2+
3+
from __future__ import annotations
44

55
import logging
6-
from dataclasses import dataclass
7-
from typing import Any
8-
from collections.abc import Mapping
96

107
from homeassistant.config_entries import ConfigEntry
118
from homeassistant.const import Platform
129
from homeassistant.core import HomeAssistant
1310
from homeassistant.exceptions import ConfigEntryNotReady
1411

15-
from .pymcintosh import async_get_mcintosh, McIntoshAsync
16-
1712
from .const import CONF_MODEL, CONF_URL, DOMAIN
13+
from .coordinator import McIntoshCoordinator
14+
from .pymcintosh import async_get_mcintosh
1815
from .utils import get_connection_overrides
1916

2017
LOG = logging.getLogger(__name__)
2118

2219
PLATFORMS = [Platform.MEDIA_PLAYER, Platform.SWITCH, Platform.NUMBER]
2320

24-
25-
@dataclass
26-
class DeviceClientDetails:
27-
client: McIntoshAsync
28-
config: Mapping[str, Any]
21+
type McIntoshConfigEntry = ConfigEntry[McIntoshCoordinator]
2922

3023

31-
async def connect_to_device(hass: HomeAssistant, entry: ConfigEntry):
24+
async def async_setup_entry(hass: HomeAssistant, entry: McIntoshConfigEntry) -> bool:
25+
"""Set up McIntosh from a config entry."""
3226
config = entry.data
3327
url = config[CONF_URL]
3428
model_id = config[CONF_MODEL]
3529

3630
try:
37-
# connect to the device to confirm everything works
3831
client = await async_get_mcintosh(
3932
model_id, url, hass.loop, **get_connection_overrides(config)
4033
)
41-
except Exception as e:
42-
raise ConfigEntryNotReady(f'Connection failed to {model_id} @ {url}') from e
34+
except Exception as err:
35+
raise ConfigEntryNotReady(f'Connection failed to {model_id} @ {url}') from err
4336

44-
# save under the entry id so multiple devices can be added to a single HASS
45-
hass.data[DOMAIN][entry.entry_id] = DeviceClientDetails(client, config)
37+
coordinator = McIntoshCoordinator(hass, client, model_id)
38+
coordinator.config_entry = entry
4639

40+
await coordinator.async_config_entry_first_refresh()
4741

48-
async def config_update_listener(hass: HomeAssistant, config_entry: ConfigEntry):
49-
"""Handle options update."""
50-
LOG.info(f'Reconnecting to device after reconfiguration: {config_entry}')
51-
await connect_to_device(hass, config_entry)
42+
hass.data.setdefault(DOMAIN, {})
43+
hass.data[DOMAIN][entry.entry_id] = coordinator
5244

45+
entry.async_on_unload(entry.add_update_listener(_async_update_listener))
5346

54-
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry):
55-
"""Set up from a config entry."""
56-
assert config_entry.unique_id, 'Config entry must have a unique_id set'
57-
hass.data.setdefault(DOMAIN, {})
47+
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
5848

59-
await connect_to_device(hass, config_entry)
49+
return True
6050

61-
# register listener to handle config options changes
62-
config_entry.async_on_unload(
63-
config_entry.add_update_listener(config_update_listener)
64-
)
6551

66-
# forward the setup to the media_player platform
67-
# hass.async_create_task(
68-
# hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
69-
# )
70-
await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS)
52+
async def _async_update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
53+
"""Handle options update."""
54+
LOG.info(f'Reloading after configuration change: {entry.title}')
55+
await hass.config_entries.async_reload(entry.entry_id)
7156

72-
return True
57+
58+
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
59+
"""Unload a config entry."""
60+
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
61+
if unload_ok:
62+
hass.data[DOMAIN].pop(entry.entry_id, None)
63+
return unload_ok

0 commit comments

Comments
 (0)