Provide feeback to user on broken UI components.

This commit is contained in:
Julian Stirling 2026-05-15 14:30:14 +01:00
parent 050c2b7672
commit c0158a7a6c
6 changed files with 55 additions and 5 deletions

View file

@ -214,6 +214,9 @@ class ActionButton(BaseModel):
Downstream components can subscribe to this and request an update.
"""
broken: bool = False
"""If True the action button is broken. There is no corresponding action."""
def action_button_for(thing: lt.Thing, action_name: str, **kwargs: Any) -> ActionButton:
"""Create a ActionButton data for the specified Thing Action.
@ -225,7 +228,8 @@ def action_button_for(thing: lt.Thing, action_name: str, **kwargs: Any) -> Actio
webapp needs to create the action button.
"""
if action_name not in thing.actions:
raise AttributeError(f"{thing.name} has no action {action_name}")
thing.logger.error(f"{thing.name} has no action {action_name}")
kwargs["broken"] = True
return ActionButton(thing=thing.name, action=action_name, **kwargs)
@ -272,6 +276,9 @@ class PropertyControl(BaseModel):
used.
"""
broken: bool = False
"""If True the property control is broken. There is no corresponding property."""
def property_control_for(
thing: lt.Thing, property_name: str, **kwargs: Any
@ -286,7 +293,8 @@ def property_control_for(
if "label" not in kwargs:
kwargs["label"] = property_name
if property_name not in thing.properties:
raise AttributeError(f"{thing.name} has no property {property_name}")
thing.logger.error(f"{thing.name} has no property {property_name}")
kwargs["broken"] = True
return PropertyControl(thing=thing.name, property_name=property_name, **kwargs)