Source code for server.events.update_frontend
from .. import socketio, connections_devices
from ..resources import devices, entities
[docs]
def emit_full_update(client_sid=None):
"""Send full update to frontend. Includes all entities.
:param client_sid: specify which client should recieve the update, or use
`client_sid=None` to emit to all clients
"""
# TODO: Filter which users receive what based on user_authorized_for_device()
socketio.emit(
"state_updated",
{
"device": devices.to_dict(),
**{k: v.to_dict() for k, v in entities.items()},
},
namespace="/client",
room=client_sid,
)
[docs]
def emit_update(**updated_entities):
"""Send small update to frontend. Contains up to one entity of each type.
Typical usage:
- send a single child-entity when updating existing data
- send a child-entity together with parent-entity (device) when sending
a brand new child-entity
Example:
update_partial(device=data_device, value={"value": 3.2})
"""
if not all(k in entities for k in updated_entities if k != "device"):
raise ValueError(f"Unknown entity name in {list(updated_entities)}")
socketio.emit(
"state_updated_partial",
updated_entities,
namespace="/client",
)