mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 02:07:09 +00:00
Add WebSocket support for handling labels on areas registry (#113755)
This commit is contained in:
parent
506240be10
commit
541d4b78ac
@ -42,6 +42,7 @@ def websocket_list_areas(
|
|||||||
vol.Optional("aliases"): list,
|
vol.Optional("aliases"): list,
|
||||||
vol.Optional("floor_id"): str,
|
vol.Optional("floor_id"): str,
|
||||||
vol.Optional("icon"): str,
|
vol.Optional("icon"): str,
|
||||||
|
vol.Optional("labels"): [str],
|
||||||
vol.Required("name"): str,
|
vol.Required("name"): str,
|
||||||
vol.Optional("picture"): vol.Any(str, None),
|
vol.Optional("picture"): vol.Any(str, None),
|
||||||
}
|
}
|
||||||
@ -64,6 +65,10 @@ def websocket_create_area(
|
|||||||
# Convert aliases to a set
|
# Convert aliases to a set
|
||||||
data["aliases"] = set(data["aliases"])
|
data["aliases"] = set(data["aliases"])
|
||||||
|
|
||||||
|
if "labels" in data:
|
||||||
|
# Convert labels to a set
|
||||||
|
data["labels"] = set(data["labels"])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
entry = registry.async_create(**data)
|
entry = registry.async_create(**data)
|
||||||
except ValueError as err:
|
except ValueError as err:
|
||||||
@ -103,6 +108,7 @@ def websocket_delete_area(
|
|||||||
vol.Required("area_id"): str,
|
vol.Required("area_id"): str,
|
||||||
vol.Optional("floor_id"): vol.Any(str, None),
|
vol.Optional("floor_id"): vol.Any(str, None),
|
||||||
vol.Optional("icon"): vol.Any(str, None),
|
vol.Optional("icon"): vol.Any(str, None),
|
||||||
|
vol.Optional("labels"): [str],
|
||||||
vol.Optional("name"): str,
|
vol.Optional("name"): str,
|
||||||
vol.Optional("picture"): vol.Any(str, None),
|
vol.Optional("picture"): vol.Any(str, None),
|
||||||
}
|
}
|
||||||
@ -125,6 +131,10 @@ def websocket_update_area(
|
|||||||
# Convert aliases to a set
|
# Convert aliases to a set
|
||||||
data["aliases"] = set(data["aliases"])
|
data["aliases"] = set(data["aliases"])
|
||||||
|
|
||||||
|
if "labels" in data:
|
||||||
|
# Convert labels to a set
|
||||||
|
data["labels"] = set(data["labels"])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
entry = registry.async_update(**data)
|
entry = registry.async_update(**data)
|
||||||
except ValueError as err:
|
except ValueError as err:
|
||||||
@ -141,6 +151,7 @@ def _entry_dict(entry: AreaEntry) -> dict[str, Any]:
|
|||||||
"area_id": entry.id,
|
"area_id": entry.id,
|
||||||
"floor_id": entry.floor_id,
|
"floor_id": entry.floor_id,
|
||||||
"icon": entry.icon,
|
"icon": entry.icon,
|
||||||
|
"labels": list(entry.labels),
|
||||||
"name": entry.name,
|
"name": entry.name,
|
||||||
"picture": entry.picture,
|
"picture": entry.picture,
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,7 @@ async def test_list_areas(
|
|||||||
icon="mdi:garage",
|
icon="mdi:garage",
|
||||||
picture="/image/example.png",
|
picture="/image/example.png",
|
||||||
floor_id="first_floor",
|
floor_id="first_floor",
|
||||||
|
labels={"label_1", "label_2"},
|
||||||
)
|
)
|
||||||
|
|
||||||
await client.send_json_auto_id({"type": "config/area_registry/list"})
|
await client.send_json_auto_id({"type": "config/area_registry/list"})
|
||||||
@ -42,6 +43,7 @@ async def test_list_areas(
|
|||||||
"area_id": area1.id,
|
"area_id": area1.id,
|
||||||
"floor_id": None,
|
"floor_id": None,
|
||||||
"icon": None,
|
"icon": None,
|
||||||
|
"labels": [],
|
||||||
"name": "mock 1",
|
"name": "mock 1",
|
||||||
"picture": None,
|
"picture": None,
|
||||||
},
|
},
|
||||||
@ -50,6 +52,7 @@ async def test_list_areas(
|
|||||||
"area_id": area2.id,
|
"area_id": area2.id,
|
||||||
"floor_id": "first_floor",
|
"floor_id": "first_floor",
|
||||||
"icon": "mdi:garage",
|
"icon": "mdi:garage",
|
||||||
|
"labels": unordered(["label_1", "label_2"]),
|
||||||
"name": "mock 2",
|
"name": "mock 2",
|
||||||
"picture": "/image/example.png",
|
"picture": "/image/example.png",
|
||||||
},
|
},
|
||||||
@ -72,6 +75,7 @@ async def test_create_area(
|
|||||||
"area_id": ANY,
|
"area_id": ANY,
|
||||||
"floor_id": None,
|
"floor_id": None,
|
||||||
"icon": None,
|
"icon": None,
|
||||||
|
"labels": [],
|
||||||
"name": "mock",
|
"name": "mock",
|
||||||
"picture": None,
|
"picture": None,
|
||||||
}
|
}
|
||||||
@ -83,6 +87,7 @@ async def test_create_area(
|
|||||||
"aliases": ["alias_1", "alias_2"],
|
"aliases": ["alias_1", "alias_2"],
|
||||||
"floor_id": "first_floor",
|
"floor_id": "first_floor",
|
||||||
"icon": "mdi:garage",
|
"icon": "mdi:garage",
|
||||||
|
"labels": ["label_1", "label_2"],
|
||||||
"name": "mock 2",
|
"name": "mock 2",
|
||||||
"picture": "/image/example.png",
|
"picture": "/image/example.png",
|
||||||
"type": "config/area_registry/create",
|
"type": "config/area_registry/create",
|
||||||
@ -96,6 +101,7 @@ async def test_create_area(
|
|||||||
"area_id": ANY,
|
"area_id": ANY,
|
||||||
"floor_id": "first_floor",
|
"floor_id": "first_floor",
|
||||||
"icon": "mdi:garage",
|
"icon": "mdi:garage",
|
||||||
|
"labels": unordered(["label_1", "label_2"]),
|
||||||
"name": "mock 2",
|
"name": "mock 2",
|
||||||
"picture": "/image/example.png",
|
"picture": "/image/example.png",
|
||||||
}
|
}
|
||||||
@ -166,6 +172,7 @@ async def test_update_area(
|
|||||||
"area_id": area.id,
|
"area_id": area.id,
|
||||||
"floor_id": "first_floor",
|
"floor_id": "first_floor",
|
||||||
"icon": "mdi:garage",
|
"icon": "mdi:garage",
|
||||||
|
"labels": ["label_1", "label_2"],
|
||||||
"name": "mock 2",
|
"name": "mock 2",
|
||||||
"picture": "/image/example.png",
|
"picture": "/image/example.png",
|
||||||
"type": "config/area_registry/update",
|
"type": "config/area_registry/update",
|
||||||
@ -179,6 +186,7 @@ async def test_update_area(
|
|||||||
"area_id": area.id,
|
"area_id": area.id,
|
||||||
"floor_id": "first_floor",
|
"floor_id": "first_floor",
|
||||||
"icon": "mdi:garage",
|
"icon": "mdi:garage",
|
||||||
|
"labels": unordered(["label_1", "label_2"]),
|
||||||
"name": "mock 2",
|
"name": "mock 2",
|
||||||
"picture": "/image/example.png",
|
"picture": "/image/example.png",
|
||||||
}
|
}
|
||||||
@ -190,6 +198,7 @@ async def test_update_area(
|
|||||||
"area_id": area.id,
|
"area_id": area.id,
|
||||||
"floor_id": None,
|
"floor_id": None,
|
||||||
"icon": None,
|
"icon": None,
|
||||||
|
"labels": [],
|
||||||
"picture": None,
|
"picture": None,
|
||||||
"type": "config/area_registry/update",
|
"type": "config/area_registry/update",
|
||||||
}
|
}
|
||||||
@ -202,6 +211,7 @@ async def test_update_area(
|
|||||||
"area_id": area.id,
|
"area_id": area.id,
|
||||||
"floor_id": None,
|
"floor_id": None,
|
||||||
"icon": None,
|
"icon": None,
|
||||||
|
"labels": [],
|
||||||
"name": "mock 2",
|
"name": "mock 2",
|
||||||
"picture": None,
|
"picture": None,
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user