From 672d3cbfe3882cd2e3e197945c1a2446563dcafa Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Sun, 31 Mar 2024 12:04:20 +0200 Subject: [PATCH] Add homeassistant.remove_area_from_floor service --- .../services/remove_area_from_floor.py | 34 +++++++++++++++++++ custom_components/spook/services.yaml | 14 ++++++++ 2 files changed, 48 insertions(+) create mode 100644 custom_components/spook/ectoplasms/homeassistant/services/remove_area_from_floor.py diff --git a/custom_components/spook/ectoplasms/homeassistant/services/remove_area_from_floor.py b/custom_components/spook/ectoplasms/homeassistant/services/remove_area_from_floor.py new file mode 100644 index 00000000..9099b73a --- /dev/null +++ b/custom_components/spook/ectoplasms/homeassistant/services/remove_area_from_floor.py @@ -0,0 +1,34 @@ +"""Spook - Your homie.""" + +from __future__ import annotations + +from typing import TYPE_CHECKING + +import voluptuous as vol + +from homeassistant.components.homeassistant import DOMAIN +from homeassistant.helpers import area_registry as ar, config_validation as cv + +from ....services import AbstractSpookAdminService + +if TYPE_CHECKING: + from homeassistant.core import ServiceCall + + +class SpookService(AbstractSpookAdminService): + """Home Assistant service to remove an area from a floor.""" + + domain = DOMAIN + service = "remove_area_from_floor" + schema = { + vol.Required("area_id"): vol.All(cv.ensure_list, [cv.string]), + } + + async def async_handle_service(self, call: ServiceCall) -> None: + """Handle the service call.""" + area_registry = ar.async_get(self.hass) + for area_id in call.data["area_id"]: + area_registry.async_update( + area_id, + floor_id=None, + ) diff --git a/custom_components/spook/services.yaml b/custom_components/spook/services.yaml index 8c8901af..39b1ed95 100644 --- a/custom_components/spook/services.yaml +++ b/custom_components/spook/services.yaml @@ -410,6 +410,20 @@ homeassistant_add_area_to_floor: area: multiple: true +homeassistant_remove_area_from_floor: + name: Remove an area from a floor 👻 + description: >- + Removes an area from a floor. As an area can only be on one floor, this + call doesn't need to specify the floor. + fields: + area_id: + name: Area ID + description: The ID of the area to remove the floor from. + required: true + selector: + area: + multiple: true + homeassistant_ignore_all_discovered: name: Ignore all currently discovered devices 👻 description: >-