1 """Services for Fritz integration."""
3 from __future__
import annotations
7 import voluptuous
as vol
14 from .const
import DOMAIN, FRITZ_SERVICES, SERVICE_SET_GUEST_WIFI_PW
15 from .coordinator
import AvmWrapper
17 _LOGGER = logging.getLogger(__name__)
19 SERVICE_SCHEMA_SET_GUEST_WIFI_PW = vol.Schema(
21 vol.Required(
"device_id"): str,
22 vol.Optional(
"password"): vol.Length(min=8, max=63),
23 vol.Optional(
"length"): vol.Range(min=8, max=63),
27 SERVICE_LIST: list[tuple[str, vol.Schema |
None]] = [
28 (SERVICE_SET_GUEST_WIFI_PW, SERVICE_SCHEMA_SET_GUEST_WIFI_PW),
33 """Set up services for Fritz integration."""
35 for service, _
in SERVICE_LIST:
36 if hass.services.has_service(DOMAIN, service):
39 async
def async_call_fritz_service(service_call: ServiceCall) ->
None:
40 """Call correct Fritz service."""
48 translation_domain=DOMAIN,
49 translation_key=
"config_entry_not_found",
50 translation_placeholders={
"service": service_call.service},
53 for entry_id
in fritzbox_entry_ids:
54 _LOGGER.debug(
"Executing service %s", service_call.service)
55 avm_wrapper: AvmWrapper = hass.data[DOMAIN][entry_id]
56 if config_entry := hass.config_entries.async_get_entry(entry_id):
57 await avm_wrapper.service_fritzbox(service_call, config_entry)
60 "Executing service %s failed, no config entry found",
64 for service, schema
in SERVICE_LIST:
65 hass.services.async_register(DOMAIN, service, async_call_fritz_service, schema)
69 hass: HomeAssistant, service_call: ServiceCall
71 """Get FritzBoxTools class from config entry."""
73 list_entry_id: list = []
75 config_entry = hass.config_entries.async_get_entry(entry_id)
78 and config_entry.domain == DOMAIN
79 and config_entry.state == ConfigEntryState.LOADED
81 list_entry_id.append(entry_id)
86 """Unload services for Fritz integration."""
88 if not hass.data.get(FRITZ_SERVICES):
91 hass.data[FRITZ_SERVICES] =
False
93 for service, _
in SERVICE_LIST:
94 hass.services.async_remove(DOMAIN, service)
None async_setup_services(HomeAssistant hass)
list _async_get_configured_avm_device(HomeAssistant hass, ServiceCall service_call)
None async_unload_services(HomeAssistant hass)
set[str] async_extract_config_entry_ids(HomeAssistant hass, ServiceCall service_call, bool expand_group=True)