1
0
mirror of https://github.com/home-assistant/core.git synced 2026-02-14 23:28:42 +00:00

Simplify subscribe feature websocket in labs (#162646)

This commit is contained in:
Artur Pragacz
2026-02-09 17:05:43 +01:00
committed by GitHub
parent 718f459026
commit 88c4d88e06

View File

@@ -103,7 +103,6 @@ async def websocket_update_preview_feature(
connection.send_result(msg["id"])
@callback
@websocket_api.websocket_command(
{
vol.Required("type"): "labs/subscribe",
@@ -111,7 +110,8 @@ async def websocket_update_preview_feature(
vol.Required("preview_feature"): str,
}
)
def websocket_subscribe_feature(
@websocket_api.async_response
async def websocket_subscribe_feature(
hass: HomeAssistant,
connection: websocket_api.ActiveConnection,
msg: dict[str, Any],
@@ -133,12 +133,17 @@ def websocket_subscribe_feature(
preview_feature = labs_data.preview_features[preview_feature_id]
async def send_event(event_data: EventLabsUpdatedData) -> None:
async def send_event(event_data: EventLabsUpdatedData | None = None) -> None:
"""Send feature state to client."""
enabled = (
event_data["enabled"]
if event_data is not None
else async_is_preview_feature_enabled(hass, domain, preview_feature_key)
)
connection.send_message(
websocket_api.event_message(
msg["id"],
preview_feature.to_dict(enabled=event_data["enabled"]),
preview_feature.to_dict(enabled=enabled),
)
)
@@ -147,13 +152,4 @@ def websocket_subscribe_feature(
)
connection.send_result(msg["id"])
connection.send_message(
websocket_api.event_message(
msg["id"],
preview_feature.to_dict(
enabled=async_is_preview_feature_enabled(
hass, domain, preview_feature_key
)
),
)
)
await send_event()