208 files

This commit is contained in:
Home Assistant Version Control
2026-10-07 02:49:21 +00:00
parent a7107ecbe1
commit cfd0d40c8e
208 changed files with 5434 additions and 901 deletions
@@ -13,13 +13,47 @@ from homeassistant.components.homeassistant.exposed_entities import (
async_expose_entity,
)
from homeassistant.const import ATTR_ENTITY_ID
from homeassistant.exceptions import HomeAssistantError
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
from homeassistant.helpers import config_validation as cv, entity_registry as er
if TYPE_CHECKING:
from homeassistant.core import HomeAssistant, ServiceCall
CONF_ASSISTANTS = "assistants"
CONF_CONFIG_ENTRY_ID = "config_entry_id"
CONF_DOMAIN = "domain"
CONFIG_ENTRY_SERVICE_SCHEMA = {
vol.Optional(CONF_CONFIG_ENTRY_ID): vol.All(cv.ensure_list, [cv.string]),
# Every entry of these integrations: the ones added later included, which
# a list of entry IDs written down today would miss.
vol.Optional(CONF_DOMAIN): vol.All(cv.ensure_list, [cv.string]),
}
def async_config_entry_ids(hass: HomeAssistant, call: ServiceCall) -> list[str]:
"""Return the integration entries an action asks for, by ID and by domain.
A domain without any entries is refused rather than skipped: a typo in it
would otherwise do nothing, and say nothing about it either.
"""
entry_ids: list[str] = list(call.data.get(CONF_CONFIG_ENTRY_ID, []))
domains: list[str] = call.data.get(CONF_DOMAIN, [])
if not entry_ids and not domains:
msg = "Name the integration entries to change, or their integration"
raise ServiceValidationError(msg)
for domain in domains:
if not (entries := hass.config_entries.async_entries(domain)):
msg = f"The {domain} integration has no entries"
raise ServiceValidationError(msg)
entry_ids.extend(
entry.entry_id for entry in entries if entry.entry_id not in entry_ids
)
return entry_ids
EXPOSURE_SERVICE_SCHEMA = {
vol.Required(ATTR_ENTITY_ID): cv.entity_ids,
@@ -4,13 +4,11 @@ from __future__ import annotations
from typing import TYPE_CHECKING
import voluptuous as vol
from homeassistant.components.homeassistant import DOMAIN
from homeassistant.config_entries import ConfigEntryDisabler
from homeassistant.helpers import config_validation as cv
from ....services import AbstractSpookAdminService
from . import CONFIG_ENTRY_SERVICE_SCHEMA, async_config_entry_ids
if TYPE_CHECKING:
from homeassistant.core import ServiceCall
@@ -21,11 +19,11 @@ class SpookService(AbstractSpookAdminService):
domain = DOMAIN
service = "disable_config_entry"
schema = {vol.Required("config_entry_id"): vol.All(cv.ensure_list, [cv.string])}
schema = CONFIG_ENTRY_SERVICE_SCHEMA
async def async_handle_service(self, call: ServiceCall) -> None:
"""Handle the service call."""
for config_entry_id in call.data["config_entry_id"]:
for config_entry_id in async_config_entry_ids(self.hass, call):
await self.hass.config_entries.async_set_disabled_by(
config_entry_id,
disabled_by=ConfigEntryDisabler.USER,
@@ -4,12 +4,10 @@ from __future__ import annotations
from typing import TYPE_CHECKING
import voluptuous as vol
from homeassistant.components.homeassistant import DOMAIN
from homeassistant.helpers import config_validation as cv
from ....services import AbstractSpookAdminService
from . import CONFIG_ENTRY_SERVICE_SCHEMA, async_config_entry_ids
if TYPE_CHECKING:
from homeassistant.core import ServiceCall
@@ -20,11 +18,11 @@ class SpookService(AbstractSpookAdminService):
domain = DOMAIN
service = "enable_config_entry"
schema = {vol.Required("config_entry_id"): vol.All(cv.ensure_list, [cv.string])}
schema = CONFIG_ENTRY_SERVICE_SCHEMA
async def async_handle_service(self, call: ServiceCall) -> None:
"""Handle the service call."""
for config_entry_id in call.data["config_entry_id"]:
for config_entry_id in async_config_entry_ids(self.hass, call):
await self.hass.config_entries.async_set_disabled_by(
config_entry_id,
disabled_by=None,