File tree 2 files changed +57
-1
lines changed
ectoplasms/homeassistant/services
2 files changed +57
-1
lines changed Original file line number Diff line number Diff line change
1
+ """Spook - Your homie."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import TYPE_CHECKING
6
+
7
+ import voluptuous as vol
8
+
9
+ from homeassistant .components .homeassistant import DOMAIN
10
+ from homeassistant .helpers import config_validation as cv , entity_registry as er
11
+
12
+ from ....services import AbstractSpookAdminService
13
+
14
+ if TYPE_CHECKING :
15
+ from homeassistant .core import ServiceCall
16
+
17
+
18
+ class SpookService (AbstractSpookAdminService ):
19
+ """Home Assistant service to remove a label from an entity."""
20
+
21
+ domain = DOMAIN
22
+ service = "remove_label_from_entity"
23
+ schema = {
24
+ vol .Required ("label_id" ): vol .All (cv .ensure_list , [cv .string ]),
25
+ vol .Required ("entity_id" ): vol .All (cv .ensure_list , [cv .string ]),
26
+ }
27
+
28
+ async def async_handle_service (self , call : ServiceCall ) -> None :
29
+ """Handle the service call."""
30
+ entity_registry = er .async_get (self .hass )
31
+ for entity_id in call .data ["entity_id" ]:
32
+ if entity_entry := entity_registry .async_get (entity_id ):
33
+ labels = entity_entry .labels .copy ()
34
+ labels .difference_update (call .data ["label_id" ])
35
+ entity_registry .async_update_entity (entity_id , labels = labels )
Original file line number Diff line number Diff line change @@ -602,7 +602,7 @@ homeassistant_remove_label_from_area:
602
602
homeassistant_remove_label_from_device :
603
603
name : Remove a label from a device 👻
604
604
description : >-
605
- Removes a label to a device. If multiple labels or multiple devices are
605
+ Removes a label from a device. If multiple labels or multiple devices are
606
606
provided, all combinations will be removed.
607
607
fields :
608
608
label_id :
@@ -620,6 +620,27 @@ homeassistant_remove_label_from_device:
620
620
device :
621
621
multiple : true
622
622
623
+ homeassistant_remove_label_from_entity :
624
+ name : Remove a label from an entity 👻
625
+ description : >-
626
+ Removes a label from an entity. If multiple labels or multiple entities are
627
+ provided, all combinations will be removed.
628
+ fields :
629
+ label_id :
630
+ name : Label ID
631
+ description : The ID(s) of the label(s) to remove from the entity/entities.
632
+ required : true
633
+ selector :
634
+ label :
635
+ multiple : true
636
+ entity_id :
637
+ name : Entity ID
638
+ description : The ID(s) of the entity/entities to remove the label(s) from.
639
+ required : true
640
+ selector :
641
+ entity :
642
+ multiple : true
643
+
623
644
homeassistant_delete_label :
624
645
name : Delete a label 👻
625
646
description : >-
You can’t perform that action at this time.
0 commit comments