Module sql_interface_heating_setvals

Source
Expand description

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

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

§Key Components

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

  • HeatingSetVals Struct: A simple data structure representing the on/off temperature thresholds for the heater.

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

    • The heatingsetvals table contains no NULL values.
    • The table contains at most one row, as there should only be a single set of heating parameters for the system.
  • get_heating_set_values(): The core data-fetching method. It retrieves the heating thresholds and performs a critical consistency check to ensure the heating_switch_on_temperature is not greater than the heating_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 heating subsystem’s configuration data.

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

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

Structs§

HeatingSetVals
Contains the heating set values which can be set by the user.
SqlInterfaceHeatingSetVals