Skip to content

Commit 7dc9084

Browse files
authored
Velux action setup (home-assistant#159502)
1 parent 39ba36d commit 7dc9084

File tree

3 files changed

+48
-23
lines changed

3 files changed

+48
-23
lines changed

homeassistant/components/velux/__init__.py

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,62 @@
44

55
from pyvlx import PyVLX, PyVLXException
66

7-
from homeassistant.config_entries import ConfigEntry
7+
from homeassistant.config_entries import ConfigEntry, ConfigEntryState
88
from homeassistant.const import (
99
CONF_HOST,
1010
CONF_MAC,
1111
CONF_PASSWORD,
1212
EVENT_HOMEASSISTANT_STOP,
1313
)
1414
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
1722

1823
from .const import DOMAIN, LOGGER, PLATFORMS
1924

2025
type VeluxConfigEntry = ConfigEntry[PyVLX]
2126

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+
2263

2364
async def async_setup_entry(hass: HomeAssistant, entry: VeluxConfigEntry) -> bool:
2465
"""Set up the velux component."""
@@ -67,27 +108,10 @@ async def on_hass_stop(event):
67108
LOGGER.debug("Velux interface terminated")
68109
await pyvlx.disconnect()
69110

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-
85111
entry.async_on_unload(
86112
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, on_hass_stop)
87113
)
88114

89-
hass.services.async_register(DOMAIN, "reboot_gateway", async_reboot_gateway)
90-
91115
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
92116

93117
return True

homeassistant/components/velux/quality_scale.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
rules:
22
# Bronze
3-
action-setup:
4-
status: todo
5-
comment: needs to move to async_setup
3+
action-setup: done
64
appropriate-polling: done
75
brands: done
86
common-modules: done

homeassistant/components/velux/strings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
}
3838
},
3939
"exceptions": {
40+
"no_gateway_loaded": {
41+
"message": "No loaded Velux gateway found"
42+
},
4043
"reboot_failed": {
4144
"message": "Failed to reboot gateway. Try again in a few moments or power cycle the device manually"
4245
}

0 commit comments

Comments
 (0)