-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add service: Remove device from area (#53)
- Loading branch information
Showing
3 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
custom_components/spook/services/homeassistant_remove_device_from_area.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
"""Spook - Not 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 config_validation as cv | ||
from homeassistant.helpers import device_registry as dr | ||
|
||
from . import AbstractSpookAdminService | ||
|
||
if TYPE_CHECKING: | ||
from homeassistant.core import ServiceCall | ||
|
||
|
||
class SpookService(AbstractSpookAdminService): | ||
"""Home Assistant service to remove a device from an area.""" | ||
|
||
domain = DOMAIN | ||
service = "remove_device_from_area" | ||
schema = { | ||
vol.Required("device_id"): vol.All(cv.ensure_list, [cv.string]), | ||
} | ||
|
||
async def async_handle_service(self, call: ServiceCall) -> None: | ||
"""Handle the service call.""" | ||
device_registry = dr.async_get(self.hass) | ||
for device_id in call.data["device_id"]: | ||
device_registry.async_update_device( | ||
device_id, | ||
area_id=None, | ||
) |