Struct SqlInterfaceHeatingSetVals

Source
pub struct SqlInterfaceHeatingSetVals {
    pub conn: PooledConn,
    update_time: Option<Instant>,
    update_duration: Duration,
}

Fields§

§conn: PooledConn

Connection to the database

§update_time: Option<Instant>

recording of time when the database has been polled for the last time

§update_duration: Duration

target update duration

Implementations§

Source§

impl SqlInterfaceHeatingSetVals

Source

pub fn new( conn: PooledConn, config: &HeatingConfig, ) -> Result<SqlInterfaceHeatingSetVals, SqlInterfaceError>

Creates a new SqlInterfaceHeatingSetVals instance.

This constructor initializes the SQL interface for heating set values. It performs several pre-flight checks to ensure data integrity, such as verifying that the heatingsetvals table contains no NULL values and has at most one row.

§Arguments
  • conn - An active, pooled database connection.
  • config - A reference to the heating configuration to determine the update interval.
§Returns

A Result containing a new SqlInterfaceHeatingSetVals instance on success.

§Errors

This function will return an error if:

  • Any of the initial database queries to get table counts fail (DatabaseCheckHeatingSetValsFailure).
  • Any of the retrieved counts are negative, indicating a database issue (DatabaseHeatingSetValTableNegativeValue).
  • The heatingsetvals table contains entries with NULL values (DatabaseHeatingSetValTableContainsNull).
  • The heatingsetvals table contains more than one row (DatabaseHeatingSetValTableContainsTooManyRows).
Source

pub fn get_heating_set_values( &mut self, ) -> Result<Option<HeatingSetVals>, SqlInterfaceError>

Retrieves the heating set point values (switch-on and switch-off temperatures) from the database.

This function queries the database for the configured heating thresholds. It expects either no entries (if values haven’t been set yet) or exactly one entry.

It performs the following checks:

  1. **Query Execution: ** Attempts to fetch heating set values from the database using SQL_QUERY_READ_HEATING_STATS.
  2. **Empty Result: ** If the query returns no entries, it indicates that the set points have not yet been configured in the database, and Ok(None) is returned.
  3. **Multiple Results: ** If the query returns more than one entry, it signifies a data inconsistency, and an Err is returned, as only a single set of heating values is expected.
  4. **Consistency Check: ** Validates that the heating_switch_on_temperature is not greater than the heating_switch_off_temperature. If this crucial control logic consistency is violated, an Err is returned.
§Returns

A Result containing an Option<HeatingSetVals>:

  • Ok(Some(HeatingSetVals)): If a single, consistent set of heating values is found.
  • Ok(None): If the query returns no rows, indicating values have not been set.
§Errors

This function will return an error if:

  • The underlying database query fails. This will be a HeatingSetValsRequestFailure that should be updated to include the source mysql::Error.
  • The query returns more than one row, indicating a data inconsistency (HeatingSetValsNoSingleResponse).
  • The retrieved heating_switch_on_temperature is bigger than the heating_switch_off_temperature, which is a critical configuration error (HeatingSetValsInvalid).

Trait Implementations§

Source§

impl Debug for SqlInterfaceHeatingSetVals

Source§

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

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

impl ThermalSetValueUpdaterTrait for SqlInterfaceHeatingSetVals

Source§

fn update_set_value( &mut self, heating_switch_off_temperature: &mut f32, heating_switch_on_temperature: &mut f32, ) -> Result<(), SqlInterfaceError>

Periodically updates heating set point values from the database.

This method checks if a configured interval (update_duration) has passed since the last database check. If it has, it queries the database for the latest HeatingSetVals and updates the provided mutable references. If no values are found in the database, the existing values are kept unchanged.

§Arguments
  • heating_switch_off_temperature - A mutable reference to the current switch-off temperature.
  • heating_switch_on_temperature - A mutable reference to the current switch-on temperature.
§Returns

An empty Result (Ok(())) on success. Success includes cases where the update was skipped due to the time interval or when no new values were found in the database.

§Errors

Returns SqlInterfaceError::HeatingSetValsUpdateFailure if the underlying call to get_heating_set_values fails. This can happen due to a database connection issue, data inconsistency (e.g., multiple rows), or invalid set values (e.g., on-temp > off-temp).

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
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.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T