Module sql_interface_ventilation_setvals

Source
Expand description

Contains functions for execution of all queries relevant for ventilation set values (thermal) Manages database interactions for the ventilation system’s user-configurable set points.

This module provides a dedicated interface, SqlInterfaceVentilationSetVals, for handling all SQL operations related to the ventilationsetvals table. It encapsulates logic for reading the ventilation on/off temperature thresholds and implements the ThermalSetValueUpdaterTrait to periodically poll the database for changes.

§Key Components

  • SqlInterfaceVentilationSetVals Struct: The primary struct that holds a database connection and manages the periodic update logic.

  • VentilationSetVals Struct: A simple data structure representing the on/off temperature thresholds for the ventilation fans.

  • new() Constructor: A critical entry point that performs “fail-fast” validation at initialization. It checks the database to ensure:

    • The ventilationsetvals table contains no NULL values.
    • The table contains at most one row, as there should only be a single set of ventilation parameters for the system.
  • get_ventilation_set_values(): The core data-fetching method. It retrieves the ventilation thresholds and performs a critical consistency check to ensure the ventilation_switch_on_temperature is not lower than the ventilation_switch_off_temperature.

  • ThermalSetValueUpdaterTrait Implementation: The update_set_value method allows this struct to be used by a thermal controller to periodically and efficiently check for updated set points from the database without querying on every single loop iteration.

§Design and Purpose

The main goal of this module is to provide a robust, encapsulated, and safe interface for the ventilation subsystem’s configuration data.

  • Encapsulation: All SQL queries and logic specific to ventilation set points are contained within this module, separating concerns.

  • Data Integrity: The constructor’s validation logic and the consistency checks in get_ventilation_set_values enforce data integrity rules, preventing runtime errors caused by invalid database states.

Structs§

SqlInterfaceVentilationSetVals
VentilationSetVals
Contains the ventilation set values which can be set by the user.