221 files

This commit is contained in:
Home Assistant Version Control
2026-10-10 15:24:58 +00:00
parent ae12b88c7d
commit bfafb4c28a
221 changed files with 73725 additions and 3277 deletions
@@ -11,6 +11,8 @@ from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.entity_component import DATA_INSTANCES, EntityComponent
from ....const import DOMAIN as SPOOK_DOMAIN
from ....errors import entity_not_found
from ....services import AbstractSpookAdminService
if TYPE_CHECKING:
@@ -46,13 +48,17 @@ class SpookService(AbstractSpookAdminService):
zone_ids = []
for entity_id in call.data["entity_id"]:
if not (entity := entity_component.get_entity(entity_id)):
message = f"Could not find entity_id: {entity_id}"
raise HomeAssistantError(message)
raise entity_not_found(entity_id)
# pylint: disable-next=protected-access
if not entity.editable or "id" not in entity._config: # noqa: SLF001
message = f"This zone is not editable: {entity_id}"
raise HomeAssistantError(message)
raise HomeAssistantError(
translation_domain=SPOOK_DOMAIN,
translation_key="zone_not_editable",
translation_placeholders={
"entity_id": entity_id,
},
)
# pylint: disable-next=protected-access
zone_ids.append(entity._config["id"]) # noqa: SLF001
@@ -18,6 +18,8 @@ from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.entity_component import DATA_INSTANCES, EntityComponent
from ....const import DOMAIN as SPOOK_DOMAIN
from ....errors import entity_not_found
from ....services import AbstractSpookAdminService
if TYPE_CHECKING:
@@ -65,8 +67,7 @@ class SpookService(AbstractSpookAdminService):
].__self__.storage_collection
if not (entity := entity_component.get_entity(call.data["entity_id"])):
message = f"Could not find entity_id: {call.data['entity_id']}"
raise HomeAssistantError(message)
raise entity_not_found(call.data["entity_id"])
if _is_the_house(entity):
await self._async_update_home(call)
@@ -74,8 +75,13 @@ class SpookService(AbstractSpookAdminService):
# pylint: disable-next=protected-access
if not entity.editable or "id" not in entity._config: # noqa: SLF001
message = f"This zone is not editable: {call.data['entity_id']}"
raise HomeAssistantError(message)
raise HomeAssistantError(
translation_domain=SPOOK_DOMAIN,
translation_key="zone_not_editable",
translation_placeholders={
"entity_id": call.data["entity_id"],
},
)
data = call.data.copy()
data.pop("entity_id")
@@ -98,11 +104,11 @@ class SpookService(AbstractSpookAdminService):
data.pop("entity_id")
if unsupported := set(data) - {CONF_LATITUDE, CONF_LONGITUDE, CONF_RADIUS}:
message = (
"The home zone only takes a latitude, longitude and radius, "
f"not: {', '.join(sorted(unsupported))}"
raise HomeAssistantError(
translation_domain=SPOOK_DOMAIN,
translation_key="home_zone_unsupported",
translation_placeholders={"fields": ", ".join(sorted(unsupported))},
)
raise HomeAssistantError(message)
# Home Assistant keeps the radius of the house in whole meters, and
# never below zero. Cutting a fraction off quietly would be a
@@ -111,8 +117,10 @@ class SpookService(AbstractSpookAdminService):
if CONF_RADIUS in data:
radius = data[CONF_RADIUS]
if radius != int(radius) or radius < 0:
message = "The home zone takes its radius in whole meters, zero or more"
raise HomeAssistantError(message)
raise HomeAssistantError(
translation_domain=SPOOK_DOMAIN,
translation_key="home_zone_radius",
)
data[CONF_RADIUS] = int(radius)
await self.hass.config.async_update(**data)