pub struct SqlInterfaceVentilationSetVals {
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 SqlInterfaceVentilationSetVals
impl SqlInterfaceVentilationSetVals
Sourcepub fn new(
conn: PooledConn,
config: &VentilationConfig,
) -> Result<Self, SqlInterfaceError>
pub fn new( conn: PooledConn, config: &VentilationConfig, ) -> Result<Self, SqlInterfaceError>
Creates a new SqlInterfaceVentilationSetVals instance.
This constructor initializes the SQL interface for ventilation set values. It performs
several pre-flight checks to ensure data integrity, such as verifying that the
ventilationsetvals table contains no NULL values and has at most one row.
§Arguments
conn- An active, pooled database connection.config- A reference to the ventilation configuration to determine the update interval.
§Returns
A Result containing a new SqlInterfaceVentilationSetVals instance on success.
§Errors
This function will return an error if:
- Any of the initial database queries to get table counts fail (
DatabaseCheckVentilationSetValsFailure). - Any of the retrieved counts are negative, indicating a database issue (
DatabaseVentilationSetValTableNegativeValue). - The
ventilationsetvalstable contains entries withNULLvalues (DatabaseVentilationSetValTableContainsNull). - The
ventilationsetvalstable contains more than one row (DatabaseVentilationSetValTableContainsTooManyRows).
Sourcepub fn get_ventilation_set_values(
&mut self,
) -> Result<Option<VentilationSetVals>, SqlInterfaceError>
pub fn get_ventilation_set_values( &mut self, ) -> Result<Option<VentilationSetVals>, SqlInterfaceError>
Retrieves the ventilation set point values (switch-on and switch-off temperatures) from the database.
This function queries the database for the configured ventilation 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 ventilation set values from the database using
SQL_QUERY_READ_VENTILATION_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 ventilation values is expected. - **Consistency Check: ** Validates that the
ventilation_switch_on_temperatureis not greater than theventilation_switch_off_temperature. If this crucial control logic consistency is violated, anErris returned.
§Returns
Ok(Some(VentilationSetVals)): If a single, consistent set of ventilation set values is successfully retrieved.Ok(None): If the database query returns no entries, indicating that values have not yet been configured.Err(SqlInterfaceError::VentilationSetValsReadError): If there’s an error during database interaction, if multiple entries are found, or if the retrieved values fail the consistency check (e.g.,switch_on_temperatureis higher thanswitch_off_temperature).
§Errors
This function returns an SqlInterfaceError::VentilationSetValsReadError in the following cases:
- The underlying database query fails.
- More than one
VentilationSetValsentry is found in the database. - The
ventilation_switch_on_temperatureis found to be greater than theventilation_switch_off_temperature, which is a critical configuration inconsistency.
Trait Implementations§
Source§impl ThermalSetValueUpdaterTrait for SqlInterfaceVentilationSetVals
impl ThermalSetValueUpdaterTrait for SqlInterfaceVentilationSetVals
Source§fn update_set_value(
&mut self,
ventilation_switch_off_temperature: &mut f32,
ventilation_switch_on_temperature: &mut f32,
) -> Result<(), SqlInterfaceError>
fn update_set_value( &mut self, ventilation_switch_off_temperature: &mut f32, ventilation_switch_on_temperature: &mut f32, ) -> Result<(), SqlInterfaceError>
Periodically updates ventilation 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
VentilationSetVals and updates the provided mutable references. If no values are
found in the database, the existing values are kept unchanged.
§Arguments
ventilation_switch_off_temperature- A mutable reference to the current switch-off temperature.ventilation_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::VentilationSetValsUpdateFailure if the underlying call to
get_ventilation_set_values fails. This can happen due to a database connection issue,
data inconsistency (e.g., multiple rows), or invalid set values.