Round dashboards: one face at a time, a face per widget type, paged by swipe, dots and keys; slider reading; face row in the editor
This commit is contained in:
@@ -90,12 +90,6 @@ INPUT_WIDGETS = {
|
||||
"color",
|
||||
}
|
||||
|
||||
#: What a round dashboard may draw on its ring: the widgets that are one value
|
||||
#: along a range, which is what turning a knob's ring can set or a circle's
|
||||
#: edge can show. Mirrored in the client
|
||||
#: (``frontend/src/components/Dashboard/DashboardView.tsx``).
|
||||
RING_WIDGETS = {"slider", "dropdown", "color", "gauge"}
|
||||
|
||||
#: What a colour widget puts on the wire, by the format it was configured for.
|
||||
#: The default is what the Node-RED instance this ports already sends its
|
||||
#: DMX encoders — ``[h, s, v]``, hue in degrees and the other two in percent —
|
||||
@@ -231,6 +225,10 @@ class WidgetDef(BaseModel):
|
||||
|
||||
The first two are a ``list`` message, the third a ``str``, which is what
|
||||
``COLOR_DTYPES`` records and the check below holds a binding to.
|
||||
|
||||
A slider may also show what it is setting: ``reading`` binds
|
||||
``{message, dtype, label}`` — a room's temperature beside its setpoint —
|
||||
held to the same numbers its target is.
|
||||
"""
|
||||
|
||||
id: str
|
||||
@@ -297,6 +295,12 @@ class WidgetDef(BaseModel):
|
||||
)
|
||||
return [*outer, *self.inner_bindings]
|
||||
|
||||
@property
|
||||
def reading(self) -> dict[str, Any]:
|
||||
"""What a slider reads beside the value it sets; empty for anything else."""
|
||||
reading = self.config.get("reading") if self.type == "slider" else None
|
||||
return reading if isinstance(reading, dict) else {}
|
||||
|
||||
@property
|
||||
def messages(self) -> list[str]:
|
||||
"""Every message name this widget reads."""
|
||||
@@ -318,8 +322,8 @@ class WidgetDef(BaseModel):
|
||||
return [
|
||||
str(row.get("message")) for row in self.bar_rows if row.get("message")
|
||||
]
|
||||
name = self.config.get("message")
|
||||
return [str(name)] if name else []
|
||||
names = [self.config.get("message"), self.reading.get("message")]
|
||||
return [str(name) for name in names if name]
|
||||
|
||||
@property
|
||||
def target(self) -> str:
|
||||
@@ -358,7 +362,10 @@ class WidgetDef(BaseModel):
|
||||
]
|
||||
if self.type == "bar":
|
||||
return [str(row.get("dtype") or "") for row in self.bar_rows]
|
||||
return [str(self.config.get("dtype") or "")]
|
||||
return [
|
||||
str(self.config.get("dtype") or ""),
|
||||
str(self.reading.get("dtype") or ""),
|
||||
]
|
||||
|
||||
@model_validator(mode="after")
|
||||
def _check_binding(self) -> WidgetDef:
|
||||
@@ -481,14 +488,11 @@ class DashboardDef(BaseModel):
|
||||
#: "unset" and the client falls back to its default.
|
||||
canvas_width: int = Field(default=1920, ge=0, le=7680)
|
||||
canvas_height: int = Field(default=1080, ge=0, le=4320)
|
||||
#: ``round`` draws the dashboard in the circle inscribed in its canvas, for
|
||||
#: a round screen such as a rotary knob. A circle has one size, so a round
|
||||
#: canvas is square: its height is its width.
|
||||
#: ``round`` draws the dashboard on the circle inscribed in its canvas, for
|
||||
#: a round screen such as a rotary knob: one widget at a time, each a whole
|
||||
#: face, in the order of ``widgets`` (``layout`` is not read). A circle has
|
||||
#: one size, so a round canvas is square: its height is its width.
|
||||
shape: Literal["rect", "round"] = "rect"
|
||||
#: The widget a round dashboard draws along its edge instead of in the grid
|
||||
#: — one of ``RING_WIDGETS``, by id — which a knob's ring turns. Empty
|
||||
#: draws no ring.
|
||||
ring: str = ""
|
||||
#: A lucide icon name, drawn on the panel rail; empty falls back to two
|
||||
#: letters of the title.
|
||||
icon: str = ""
|
||||
@@ -550,20 +554,9 @@ class DashboardDef(BaseModel):
|
||||
|
||||
@model_validator(mode="after")
|
||||
def _check_shape(self) -> DashboardDef:
|
||||
"""Square a round canvas, and hold the ring to a widget it can draw."""
|
||||
"""Square a round canvas."""
|
||||
if self.shape == "round":
|
||||
self.canvas_height = self.canvas_width
|
||||
if not self.ring:
|
||||
return self
|
||||
if self.shape != "round":
|
||||
raise ValueError("only a round dashboard has a ring")
|
||||
widget = next((w for w in self.widgets if w.id == self.ring), None)
|
||||
if widget is None:
|
||||
raise ValueError(
|
||||
f"the ring names '{self.ring}', which is not a widget here"
|
||||
)
|
||||
if widget.type not in RING_WIDGETS:
|
||||
raise ValueError(f"a '{widget.type}' widget cannot be drawn on the ring")
|
||||
return self
|
||||
|
||||
@property
|
||||
@@ -581,9 +574,6 @@ class DashboardDef(BaseModel):
|
||||
"""
|
||||
shapes = []
|
||||
for widget in self.widgets:
|
||||
# Drawn along the edge, so it takes no place in the grid.
|
||||
if widget.id == self.ring:
|
||||
continue
|
||||
at = (
|
||||
widget.layout.get("lg")
|
||||
or widget.layout.get("md")
|
||||
|
||||
Reference in New Issue
Block a user