Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add homeassistant.set_floor_aliases service #705

Merged
merged 1 commit into from
Mar 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""Spook - Your homie."""

from __future__ import annotations

from typing import TYPE_CHECKING

import voluptuous as vol

from homeassistant.components.homeassistant import DOMAIN
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import config_validation as cv, floor_registry as fr

from ....services import AbstractSpookAdminService

if TYPE_CHECKING:
from homeassistant.core import ServiceCall


class SpookService(AbstractSpookAdminService):
"""Home Assistant service to set the aliases of a floor."""

domain = DOMAIN
service = "set_floor_aliases"
schema = {
vol.Required("floor_id"): cv.string,
vol.Required("aliases"): vol.All(cv.ensure_list, [cv.string]),
}

async def async_handle_service(self, call: ServiceCall) -> None:
"""Handle the service call."""
floor_registry = fr.async_get(self.hass)
if not floor_registry.async_get_floor(call.data["floor_id"]):
msg = f"Floor {call.data['floor_id']} not found"
raise HomeAssistantError(msg)

floor_registry.async_update(
call.data["floor_id"],
aliases=set(call.data["aliases"]),
)
18 changes: 18 additions & 0 deletions custom_components/spook/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,24 @@ homeassistant_remove_alias_from_floor:
object:

homeassistant_set_floor_aliases:
name: Sets aliases for a floor 👻
description: >-
Sets aliases for a floor. Overwrite and removed any existing aliases,
fully replacing them with the new ones.
fields:
floor_id:
name: Floor ID
description: The ID of the floor to set the aliases for.
required: true
selector:
text:
aliases:
name: Aliases
description: The aliases to set for the floor.
required: true
selector:
object:

homeassistant_ignore_all_discovered:
name: Ignore all currently discovered devices 👻
description: >-
Expand Down