Add WebSocket support for handling labels on areas registry (#113755)

This commit is contained in:
Franck Nijhof 2024-03-18 22:17:13 +01:00 committed by GitHub
parent 506240be10
commit 541d4b78ac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 0 deletions

View File

@ -42,6 +42,7 @@ def websocket_list_areas(
vol.Optional("aliases"): list,
vol.Optional("floor_id"): str,
vol.Optional("icon"): str,
vol.Optional("labels"): [str],
vol.Required("name"): str,
vol.Optional("picture"): vol.Any(str, None),
}
@ -64,6 +65,10 @@ def websocket_create_area(
# Convert aliases to a set
data["aliases"] = set(data["aliases"])
if "labels" in data:
# Convert labels to a set
data["labels"] = set(data["labels"])
try:
entry = registry.async_create(**data)
except ValueError as err:
@ -103,6 +108,7 @@ def websocket_delete_area(
vol.Required("area_id"): str,
vol.Optional("floor_id"): vol.Any(str, None),
vol.Optional("icon"): vol.Any(str, None),
vol.Optional("labels"): [str],
vol.Optional("name"): str,
vol.Optional("picture"): vol.Any(str, None),
}
@ -125,6 +131,10 @@ def websocket_update_area(
# Convert aliases to a set
data["aliases"] = set(data["aliases"])
if "labels" in data:
# Convert labels to a set
data["labels"] = set(data["labels"])
try:
entry = registry.async_update(**data)
except ValueError as err:
@ -141,6 +151,7 @@ def _entry_dict(entry: AreaEntry) -> dict[str, Any]:
"area_id": entry.id,
"floor_id": entry.floor_id,
"icon": entry.icon,
"labels": list(entry.labels),
"name": entry.name,
"picture": entry.picture,
}

View File

@ -31,6 +31,7 @@ async def test_list_areas(
icon="mdi:garage",
picture="/image/example.png",
floor_id="first_floor",
labels={"label_1", "label_2"},
)
await client.send_json_auto_id({"type": "config/area_registry/list"})
@ -42,6 +43,7 @@ async def test_list_areas(
"area_id": area1.id,
"floor_id": None,
"icon": None,
"labels": [],
"name": "mock 1",
"picture": None,
},
@ -50,6 +52,7 @@ async def test_list_areas(
"area_id": area2.id,
"floor_id": "first_floor",
"icon": "mdi:garage",
"labels": unordered(["label_1", "label_2"]),
"name": "mock 2",
"picture": "/image/example.png",
},
@ -72,6 +75,7 @@ async def test_create_area(
"area_id": ANY,
"floor_id": None,
"icon": None,
"labels": [],
"name": "mock",
"picture": None,
}
@ -83,6 +87,7 @@ async def test_create_area(
"aliases": ["alias_1", "alias_2"],
"floor_id": "first_floor",
"icon": "mdi:garage",
"labels": ["label_1", "label_2"],
"name": "mock 2",
"picture": "/image/example.png",
"type": "config/area_registry/create",
@ -96,6 +101,7 @@ async def test_create_area(
"area_id": ANY,
"floor_id": "first_floor",
"icon": "mdi:garage",
"labels": unordered(["label_1", "label_2"]),
"name": "mock 2",
"picture": "/image/example.png",
}
@ -166,6 +172,7 @@ async def test_update_area(
"area_id": area.id,
"floor_id": "first_floor",
"icon": "mdi:garage",
"labels": ["label_1", "label_2"],
"name": "mock 2",
"picture": "/image/example.png",
"type": "config/area_registry/update",
@ -179,6 +186,7 @@ async def test_update_area(
"area_id": area.id,
"floor_id": "first_floor",
"icon": "mdi:garage",
"labels": unordered(["label_1", "label_2"]),
"name": "mock 2",
"picture": "/image/example.png",
}
@ -190,6 +198,7 @@ async def test_update_area(
"area_id": area.id,
"floor_id": None,
"icon": None,
"labels": [],
"picture": None,
"type": "config/area_registry/update",
}
@ -202,6 +211,7 @@ async def test_update_area(
"area_id": area.id,
"floor_id": None,
"icon": None,
"labels": [],
"name": "mock 2",
"picture": None,
}