mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 09:17:53 +00:00
Add theme color support to labels (#113404)
This commit is contained in:
parent
360f7dea75
commit
436c83e8a7
@ -10,6 +10,35 @@ from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.label_registry import LabelEntry, async_get
|
||||
|
||||
SUPPORTED_LABEL_THEME_COLORS = {
|
||||
"primary",
|
||||
"accent",
|
||||
"disabled",
|
||||
"red",
|
||||
"pink",
|
||||
"purple",
|
||||
"deep-purple",
|
||||
"indigo",
|
||||
"blue",
|
||||
"light-blue",
|
||||
"cyan",
|
||||
"teal",
|
||||
"green",
|
||||
"light-green",
|
||||
"lime",
|
||||
"yellow",
|
||||
"amber",
|
||||
"orange",
|
||||
"deep-orange",
|
||||
"brown",
|
||||
"light-grey",
|
||||
"grey",
|
||||
"dark-grey",
|
||||
"blue-grey",
|
||||
"black",
|
||||
"white",
|
||||
}
|
||||
|
||||
|
||||
@callback
|
||||
def async_setup(hass: HomeAssistant) -> bool:
|
||||
@ -42,7 +71,9 @@ def websocket_list_labels(
|
||||
{
|
||||
vol.Required("type"): "config/label_registry/create",
|
||||
vol.Required("name"): str,
|
||||
vol.Optional("color"): vol.Any(cv.color_hex, None),
|
||||
vol.Optional("color"): vol.Any(
|
||||
cv.color_hex, vol.In(SUPPORTED_LABEL_THEME_COLORS), None
|
||||
),
|
||||
vol.Optional("description"): vol.Any(str, None),
|
||||
vol.Optional("icon"): vol.Any(cv.icon, None),
|
||||
}
|
||||
@ -93,7 +124,9 @@ def websocket_delete_label(
|
||||
{
|
||||
vol.Required("type"): "config/label_registry/update",
|
||||
vol.Required("label_id"): str,
|
||||
vol.Optional("color"): vol.Any(cv.color_hex, None),
|
||||
vol.Optional("color"): vol.Any(
|
||||
cv.color_hex, vol.In(SUPPORTED_LABEL_THEME_COLORS), None
|
||||
),
|
||||
vol.Optional("description"): vol.Any(str, None),
|
||||
vol.Optional("icon"): vol.Any(cv.icon, None),
|
||||
vol.Optional("name"): str,
|
||||
|
@ -99,6 +99,27 @@ async def test_create_label(
|
||||
"name": "MOCKERY",
|
||||
}
|
||||
|
||||
await client.send_json_auto_id(
|
||||
{
|
||||
"name": "MAGIC",
|
||||
"type": "config/label_registry/create",
|
||||
"color": "indigo",
|
||||
"description": "This is the third label",
|
||||
"icon": "mdi:three",
|
||||
}
|
||||
)
|
||||
|
||||
msg = await client.receive_json()
|
||||
|
||||
assert len(label_registry.labels) == 3
|
||||
assert msg["result"] == {
|
||||
"color": "indigo",
|
||||
"description": "This is the third label",
|
||||
"icon": "mdi:three",
|
||||
"label_id": "magic",
|
||||
"name": "MAGIC",
|
||||
}
|
||||
|
||||
|
||||
async def test_create_label_with_name_already_in_use(
|
||||
client: MockHAClientWebSocket,
|
||||
@ -210,6 +231,28 @@ async def test_update_label(
|
||||
"name": "UPDATED AGAIN",
|
||||
}
|
||||
|
||||
await client.send_json_auto_id(
|
||||
{
|
||||
"label_id": label.label_id,
|
||||
"name": "UPDATED YET AGAIN",
|
||||
"icon": None,
|
||||
"color": "primary",
|
||||
"description": None,
|
||||
"type": "config/label_registry/update",
|
||||
}
|
||||
)
|
||||
|
||||
msg = await client.receive_json()
|
||||
|
||||
assert len(label_registry.labels) == 1
|
||||
assert msg["result"] == {
|
||||
"color": "primary",
|
||||
"description": None,
|
||||
"icon": None,
|
||||
"label_id": "mock",
|
||||
"name": "UPDATED YET AGAIN",
|
||||
}
|
||||
|
||||
|
||||
async def test_update_with_name_already_in_use(
|
||||
client: MockHAClientWebSocket,
|
||||
|
Loading…
x
Reference in New Issue
Block a user