|
4 | 4 |
|
5 | 5 | from pyvlx import PyVLX, PyVLXException |
6 | 6 |
|
7 | | -from homeassistant.config_entries import ConfigEntry |
| 7 | +from homeassistant.config_entries import ConfigEntry, ConfigEntryState |
8 | 8 | from homeassistant.const import ( |
9 | 9 | CONF_HOST, |
10 | 10 | CONF_MAC, |
11 | 11 | CONF_PASSWORD, |
12 | 12 | EVENT_HOMEASSISTANT_STOP, |
13 | 13 | ) |
14 | 14 | from homeassistant.core import HomeAssistant, ServiceCall |
15 | | -from homeassistant.exceptions import ConfigEntryNotReady |
16 | | -from homeassistant.helpers import device_registry as dr, issue_registry as ir |
| 15 | +from homeassistant.exceptions import ConfigEntryNotReady, ServiceValidationError |
| 16 | +from homeassistant.helpers import ( |
| 17 | + config_validation as cv, |
| 18 | + device_registry as dr, |
| 19 | + issue_registry as ir, |
| 20 | +) |
| 21 | +from homeassistant.helpers.typing import ConfigType |
17 | 22 |
|
18 | 23 | from .const import DOMAIN, LOGGER, PLATFORMS |
19 | 24 |
|
20 | 25 | type VeluxConfigEntry = ConfigEntry[PyVLX] |
21 | 26 |
|
| 27 | +CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN) |
| 28 | + |
| 29 | + |
| 30 | +async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: |
| 31 | + """Set up the Velux component.""" |
| 32 | + |
| 33 | + async def async_reboot_gateway(service_call: ServiceCall) -> None: |
| 34 | + """Reboot the gateway (deprecated - use button entity instead).""" |
| 35 | + ir.async_create_issue( |
| 36 | + hass, |
| 37 | + DOMAIN, |
| 38 | + "deprecated_reboot_service", |
| 39 | + is_fixable=False, |
| 40 | + issue_domain=DOMAIN, |
| 41 | + severity=ir.IssueSeverity.WARNING, |
| 42 | + translation_key="deprecated_reboot_service", |
| 43 | + breaks_in_ha_version="2026.6.0", |
| 44 | + ) |
| 45 | + |
| 46 | + # Find a loaded config entry to get the PyVLX instance |
| 47 | + # We assume only one gateway is set up or we just reboot the first one found |
| 48 | + # (this is no change to the previous behavior, the alternative would be to reboot all) |
| 49 | + for entry in hass.config_entries.async_entries(DOMAIN): |
| 50 | + if entry.state is ConfigEntryState.LOADED: |
| 51 | + await entry.runtime_data.reboot_gateway() |
| 52 | + return |
| 53 | + |
| 54 | + raise ServiceValidationError( |
| 55 | + translation_domain=DOMAIN, |
| 56 | + translation_key="no_gateway_loaded", |
| 57 | + ) |
| 58 | + |
| 59 | + hass.services.async_register(DOMAIN, "reboot_gateway", async_reboot_gateway) |
| 60 | + |
| 61 | + return True |
| 62 | + |
22 | 63 |
|
23 | 64 | async def async_setup_entry(hass: HomeAssistant, entry: VeluxConfigEntry) -> bool: |
24 | 65 | """Set up the velux component.""" |
@@ -67,27 +108,10 @@ async def on_hass_stop(event): |
67 | 108 | LOGGER.debug("Velux interface terminated") |
68 | 109 | await pyvlx.disconnect() |
69 | 110 |
|
70 | | - async def async_reboot_gateway(service_call: ServiceCall) -> None: |
71 | | - """Reboot the gateway (deprecated - use button entity instead).""" |
72 | | - ir.async_create_issue( |
73 | | - hass, |
74 | | - DOMAIN, |
75 | | - "deprecated_reboot_service", |
76 | | - is_fixable=False, |
77 | | - issue_domain=DOMAIN, |
78 | | - severity=ir.IssueSeverity.WARNING, |
79 | | - translation_key="deprecated_reboot_service", |
80 | | - breaks_in_ha_version="2026.6.0", |
81 | | - ) |
82 | | - |
83 | | - await pyvlx.reboot_gateway() |
84 | | - |
85 | 111 | entry.async_on_unload( |
86 | 112 | hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, on_hass_stop) |
87 | 113 | ) |
88 | 114 |
|
89 | | - hass.services.async_register(DOMAIN, "reboot_gateway", async_reboot_gateway) |
90 | | - |
91 | 115 | await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) |
92 | 116 |
|
93 | 117 | return True |
|
0 commit comments