Skip to main content

Reading

Struct Reading 

Source
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: String

A stable, language-neutral element key, such as "soil_moisture".

§value: f32

The raw measured value, in the canonical unit.

§unit: String

The canonical unit name, such as "percent", "celsius", or "volt".

§status: Status

The 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: bool

Whether 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

Source

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.

Source

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"));
Source

pub fn with_status(self, status: Status) -> Self

Sets the reading’s health.

§Arguments
  • status - the health to record.
§Returns

The reading, for chaining.

Source

pub fn with_band(self, low: f32, high: f32) -> Self

Sets the safe band drawn as the gauge’s safe zone.

§Arguments
  • low - the bottom of the safe band.
  • high - the top of the safe band.
§Returns

The reading, for chaining.

Source

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.

Source

pub fn with_trend(self, trend: Trend) -> Self

Sets the reading’s trend arrow.

§Arguments
  • trend - which way the reading is moving.
§Returns

The reading, for chaining.

Source

pub fn with_state(self, state: impl Into<String>) -> Self

Sets a discrete state code for a non-numeric reading, rendered as a chip.

§Arguments
  • state - the stable state code, such as "state.open".
§Returns

The reading, for chaining.

Source

pub fn with_actions( self, actions: impl IntoIterator<Item = impl Into<String>>, ) -> Self

Marks the reading as a controllable actuator with the given discrete actions.

§Arguments
  • actions - the action codes a client may command, such as ["open", "closed"].
§Returns

The reading, for chaining.

Source

pub fn with_range(self, low: f32, high: f32) -> Self

Marks the reading as a numeric actuator that accepts a value inside a range.

§Arguments
  • low - the lowest value a client may command, in the reading’s unit.
  • high - the highest value a client may command.
§Returns

The reading, for chaining.

Source

pub fn with_label(self, label: impl Into<String>) -> Self

Gives the reading a display name of its own, for a key no bundle or catalog knows.

§Arguments
  • label - the name the page shows when it has no translation for the key.
§Returns

The reading, for chaining.

Source

pub fn as_stat(self) -> Self

Marks the reading as a node or network stat rather than a measurement, so the page counts and renders it apart from sensors.

§Returns

The reading, for chaining.

Trait Implementations§

Source§

impl Clone for Reading

Source§

fn clone(&self) -> Reading

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Reading

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Reading

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Reading

Source§

fn eq(&self, other: &Reading) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Reading

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Reading

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.