pub struct SqlInterfaceHeatingSetVals {
pub conn: PooledConn,
update_time: Option<Instant>,
update_duration: Duration,
}Fields§
§conn: PooledConnConnection to the database
update_time: Option<Instant>recording of time when the database has been polled for the last time
update_duration: Durationtarget update duration
Implementations§
Source§impl SqlInterfaceHeatingSetVals
impl SqlInterfaceHeatingSetVals
Sourcepub fn new(
conn: PooledConn,
config: &HeatingConfig,
) -> Result<SqlInterfaceHeatingSetVals, SqlInterfaceError>
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
heatingsetvalstable contains entries withNULLvalues (DatabaseHeatingSetValTableContainsNull). - The
heatingsetvalstable contains more than one row (DatabaseHeatingSetValTableContainsTooManyRows).
Sourcepub fn get_heating_set_values(
&mut self,
) -> Result<Option<HeatingSetVals>, SqlInterfaceError>
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:
- **Query Execution: ** Attempts to fetch heating set values from the database using
SQL_QUERY_READ_HEATING_STATS. - **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. - **Multiple Results: ** If the query returns more than one entry, it signifies a data
inconsistency, and an
Erris returned, as only a single set of heating values is expected. - **Consistency Check: ** Validates that the
heating_switch_on_temperatureis not greater than theheating_switch_off_temperature. If this crucial control logic consistency is violated, anErris 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
HeatingSetValsRequestFailurethat should be updated to include the sourcemysql::Error. - The query returns more than one row, indicating a data inconsistency (
HeatingSetValsNoSingleResponse). - The retrieved
heating_switch_on_temperatureis bigger than theheating_switch_off_temperature, which is a critical configuration error (HeatingSetValsInvalid).
Trait Implementations§
Source§impl Debug for SqlInterfaceHeatingSetVals
impl Debug for SqlInterfaceHeatingSetVals
Source§impl ThermalSetValueUpdaterTrait for SqlInterfaceHeatingSetVals
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>
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).