124 files
This commit is contained in:
@@ -7,42 +7,15 @@ 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, label_registry as lr
|
||||
|
||||
from ....services import AbstractSpookAdminService
|
||||
from ..labels import SUPPORTED_LABEL_THEME_COLORS
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from homeassistant.core import ServiceCall
|
||||
|
||||
SUPPORTED_LABEL_THEME_COLORS = {
|
||||
"primary",
|
||||
"accent",
|
||||
"disabled",
|
||||
"amber",
|
||||
"black",
|
||||
"blue-grey",
|
||||
"blue",
|
||||
"brown",
|
||||
"cyan",
|
||||
"dark-grey",
|
||||
"deep-orange",
|
||||
"deep-purple",
|
||||
"green",
|
||||
"grey",
|
||||
"indigo",
|
||||
"light-blue",
|
||||
"light-green",
|
||||
"light-grey",
|
||||
"lime",
|
||||
"orange",
|
||||
"pink",
|
||||
"purple",
|
||||
"red",
|
||||
"teal",
|
||||
"white",
|
||||
"yellow",
|
||||
}
|
||||
|
||||
|
||||
class SpookService(AbstractSpookAdminService):
|
||||
"""Home Assistant service to create labels on the fly."""
|
||||
@@ -61,9 +34,14 @@ class SpookService(AbstractSpookAdminService):
|
||||
async def async_handle_service(self, call: ServiceCall) -> None:
|
||||
"""Handle the service call."""
|
||||
label_registry = lr.async_get(self.hass)
|
||||
label_registry.async_create(
|
||||
name=call.data["name"],
|
||||
color=call.data.get("color"),
|
||||
description=call.data.get("description"),
|
||||
icon=call.data.get("icon"),
|
||||
)
|
||||
try:
|
||||
label_registry.async_create(
|
||||
name=call.data["name"],
|
||||
color=call.data.get("color"),
|
||||
description=call.data.get("description"),
|
||||
icon=call.data.get("icon"),
|
||||
)
|
||||
except ValueError as err:
|
||||
# A name another label already has. Left alone this comes back as
|
||||
# an unknown error with the registry's own wording.
|
||||
raise HomeAssistantError(str(err)) from err
|
||||
|
||||
Reference in New Issue
Block a user