mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Add aliases support to floor registry WebSocket API (#113401)
This commit is contained in:
parent
b1c636c886
commit
221893c1d7
@ -41,6 +41,7 @@ def websocket_list_floors(
|
||||
{
|
||||
vol.Required("type"): "config/floor_registry/create",
|
||||
vol.Required("name"): str,
|
||||
vol.Optional("aliases"): list,
|
||||
vol.Optional("icon"): vol.Any(str, None),
|
||||
vol.Optional("level"): int,
|
||||
}
|
||||
@ -57,6 +58,10 @@ def websocket_create_floor(
|
||||
data.pop("type")
|
||||
data.pop("id")
|
||||
|
||||
if "aliases" in data:
|
||||
# Convert aliases to a set
|
||||
data["aliases"] = set(data["aliases"])
|
||||
|
||||
try:
|
||||
entry = registry.async_create(**data)
|
||||
except ValueError as err:
|
||||
@ -91,6 +96,7 @@ def websocket_delete_floor(
|
||||
{
|
||||
vol.Required("type"): "config/floor_registry/update",
|
||||
vol.Required("floor_id"): str,
|
||||
vol.Optional("aliases"): list,
|
||||
vol.Optional("icon"): vol.Any(str, None),
|
||||
vol.Optional("level"): int,
|
||||
vol.Optional("name"): str,
|
||||
@ -108,6 +114,10 @@ def websocket_update_floor(
|
||||
data.pop("type")
|
||||
data.pop("id")
|
||||
|
||||
if "aliases" in data:
|
||||
# Convert aliases to a set
|
||||
data["aliases"] = set(data["aliases"])
|
||||
|
||||
try:
|
||||
entry = registry.async_update(**data)
|
||||
except ValueError as err:
|
||||
@ -120,6 +130,7 @@ def websocket_update_floor(
|
||||
def _entry_dict(entry: FloorEntry) -> dict[str, Any]:
|
||||
"""Convert entry to API format."""
|
||||
return {
|
||||
"aliases": list(entry.aliases),
|
||||
"floor_id": entry.floor_id,
|
||||
"icon": entry.icon,
|
||||
"level": entry.level,
|
||||
|
@ -1,6 +1,7 @@
|
||||
"""Test floor registry API."""
|
||||
|
||||
import pytest
|
||||
from pytest_unordered import unordered
|
||||
|
||||
from homeassistant.components.config import floor_registry
|
||||
from homeassistant.core import HomeAssistant
|
||||
@ -26,6 +27,7 @@ async def test_list_floors(
|
||||
floor_registry.async_create("First floor")
|
||||
floor_registry.async_create(
|
||||
name="Second floor",
|
||||
aliases={"top floor", "attic"},
|
||||
icon="mdi:home-floor-2",
|
||||
level=2,
|
||||
)
|
||||
@ -38,12 +40,14 @@ async def test_list_floors(
|
||||
|
||||
assert len(msg["result"]) == len(floor_registry.floors)
|
||||
assert msg["result"][0] == {
|
||||
"aliases": [],
|
||||
"icon": None,
|
||||
"floor_id": "first_floor",
|
||||
"name": "First floor",
|
||||
"level": 0,
|
||||
}
|
||||
assert msg["result"][1] == {
|
||||
"aliases": unordered(["top floor", "attic"]),
|
||||
"icon": "mdi:home-floor-2",
|
||||
"floor_id": "second_floor",
|
||||
"name": "Second floor",
|
||||
@ -64,6 +68,7 @@ async def test_create_floor(
|
||||
|
||||
assert len(floor_registry.floors) == 1
|
||||
assert msg["result"] == {
|
||||
"aliases": [],
|
||||
"icon": None,
|
||||
"floor_id": "first_floor",
|
||||
"name": "First floor",
|
||||
@ -74,6 +79,7 @@ async def test_create_floor(
|
||||
{
|
||||
"name": "Second floor",
|
||||
"type": "config/floor_registry/create",
|
||||
"aliases": ["top floor", "attic"],
|
||||
"icon": "mdi:home-floor-2",
|
||||
"level": 2,
|
||||
}
|
||||
@ -83,6 +89,7 @@ async def test_create_floor(
|
||||
|
||||
assert len(floor_registry.floors) == 2
|
||||
assert msg["result"] == {
|
||||
"aliases": unordered(["top floor", "attic"]),
|
||||
"icon": "mdi:home-floor-2",
|
||||
"floor_id": "second_floor",
|
||||
"name": "Second floor",
|
||||
@ -165,6 +172,7 @@ async def test_update_floor(
|
||||
{
|
||||
"floor_id": floor.floor_id,
|
||||
"name": "Second floor",
|
||||
"aliases": ["top floor", "attic"],
|
||||
"icon": "mdi:home-floor-2",
|
||||
"type": "config/floor_registry/update",
|
||||
"level": 2,
|
||||
@ -175,6 +183,7 @@ async def test_update_floor(
|
||||
|
||||
assert len(floor_registry.floors) == 1
|
||||
assert msg["result"] == {
|
||||
"aliases": unordered(["top floor", "attic"]),
|
||||
"icon": "mdi:home-floor-2",
|
||||
"floor_id": floor.floor_id,
|
||||
"name": "Second floor",
|
||||
@ -185,6 +194,7 @@ async def test_update_floor(
|
||||
{
|
||||
"floor_id": floor.floor_id,
|
||||
"name": "First floor",
|
||||
"aliases": [],
|
||||
"icon": None,
|
||||
"level": 1,
|
||||
"type": "config/floor_registry/update",
|
||||
@ -195,6 +205,7 @@ async def test_update_floor(
|
||||
|
||||
assert len(floor_registry.floors) == 1
|
||||
assert msg["result"] == {
|
||||
"aliases": [],
|
||||
"icon": None,
|
||||
"floor_id": floor.floor_id,
|
||||
"name": "First floor",
|
||||
|
Loading…
x
Reference in New Issue
Block a user