pub struct Reading {
pub key: String,
pub value: f32,
pub unit: String,
pub status: Status,
pub band: Option<[f32; 2]>,
pub viz: Option<String>,
pub trend: Option<Trend>,
pub state: Option<String>,
pub actions: Option<Vec<String>>,
pub range: Option<[f32; 2]>,
pub label: Option<String>,
pub stat: bool,
}Expand description
A single measured value, named by a stable key and a canonical unit.
Fields§
§key: StringA stable, language-neutral element key, such as "soil_moisture".
value: f32The raw measured value, in the canonical unit.
unit: StringThe canonical unit name, such as "percent", "celsius", or "volt".
status: StatusThe health of this reading on its own.
band: Option<[f32; 2]>The safe band [low, high] in the same unit, drawn as the gauge’s safe zone.
viz: Option<String>An explicit visualization kind that overrides the page’s key/unit heuristic, such
as "radial" or "bar". Set from a profile’s Viz with
with_viz so a custom reading is drawn the way its profile
intends; None lets the page pick from the key and unit.
trend: Option<Trend>Which way the reading is moving, if known.
state: Option<String>A discrete state code for a non-numeric reading, such as "state.open" for a
valve or "pump.nominal" for a pump, which the page renders as a labeled chip.
Numeric readings leave this None.
actions: Option<Vec<String>>The discrete actions this reading can be commanded to, such as
["open", "closed"] for a valve. Present only on a controllable actuator; a
read-only sensor leaves this None, and the page shows control only when it is set.
range: Option<[f32; 2]>The numeric range [low, high] this reading can be commanded to, in its unit,
present only on a numeric actuator such as a pump speed or a setpoint. The page
shows a control for it, and a Command::Set inside the
range moves the value.
label: Option<String>A display name for a key the page’s own bundles and the served catalog do not carry, such as a sensor added from the page itself. The page prefers a translated label when it has one, then this, then a reading of the key.
stat: boolWhether this is a node or network stat (neighbors, hops, link or relay status, a
tamper-log record count) rather than a measurement of the world. The page counts and
renders stats apart from sensors. Defaults false.
Implementations§
Source§impl Reading
impl Reading
Sourcepub fn new(key: impl Into<String>, value: f32, unit: impl Into<String>) -> Self
pub fn new(key: impl Into<String>, value: f32, unit: impl Into<String>) -> Self
Creates a reading in good standing with no band or trend.
§Arguments
key- the stable element key.value- the raw measured value.unit- the canonical unit name.
§Returns
A Status::Ok reading carrying just the value and unit.
Sourcepub fn from_element(element: &ElementSpec) -> Self
pub fn from_element(element: &ElementSpec) -> Self
Creates a reading from an element a profile declares.
A profile says how a reading should be drawn: its key, unit, graphic, safe band, and the value or discrete state it starts in. This is that declaration turned into the first reading a gateway reports, so a fleet can be stood up straight from the profiles it runs. Later samples replace the value and keep the rest.
§Arguments
element- the element the profile declares.
§Returns
A Status::Ok reading carrying the element’s key, unit, graphic, band, and
starting value or state.
§Examples
use pamoja_dashboard::{ElementSpec, Reading, Viz};
let element = ElementSpec::new("store_humidity", "percent", "Store humidity", Viz::Droplet)
.with_band(30.0, 65.0)
.with_value(48.0);
let reading = Reading::from_element(&element);
assert_eq!(reading.key, "store_humidity");
assert_eq!(reading.band, Some([30.0, 65.0]));
assert_eq!(reading.viz.as_deref(), Some("droplet"));Sourcepub fn with_status(self, status: Status) -> Self
pub fn with_status(self, status: Status) -> Self
Sourcepub fn with_viz(self, viz: Viz) -> Self
pub fn with_viz(self, viz: Viz) -> Self
Pins the graphic this reading is drawn with, overriding the page’s heuristic.
Use this when a profile declares a custom element with Viz and you want the
live reading drawn the same way, regardless of its key and unit.
§Arguments
viz- the graphic to draw the reading with.
§Returns
The reading, for chaining.