Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
floatplane committed Feb 18, 2024
1 parent cd90207 commit dfd0e14
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
27 changes: 14 additions & 13 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,6 @@ void setup() {
}
// Serial.println(F("Connection to HVAC. Stop serial log."));
LOG(F("MQTT initialized, trying to connect to HVAC"));
hp.setStatusChangedCallback(onHeatPumpStatusChanged);
hp.setPacketCallback(hpPacketDebug);

// Merge settings from remote control with settings driven from MQTT
Expand Down Expand Up @@ -1555,23 +1554,25 @@ String hpGetAction(const HeatpumpStatus &hpStatus, const HeatpumpSettings &hpSet
return hpmode; // unknown
}

// Invoked async when the heatpump's room temperature changes, or when the heatpump's operating
// state changes. Also invoked synchronously every time through `loop`.
// TODO(floatplane): remove async invocation - we do it on every loop, so what's the point?
// NOLINTNEXTLINE(passedByValue) - we don't control this callback signature
// cppcheck-suppress passedByValue
void onHeatPumpStatusChanged([[maybe_unused]] heatpumpStatus _newStatus) {
void validateHeatPumpRemoteTemp() {
if (remoteTempActive && (millis() - lastRemoteTemp >
CHECK_REMOTE_TEMP_INTERVAL_MS)) { // if it's been 5 minutes since last
// remote_temp message, power off the heat pump
hp.setPowerSetting("OFF");
remoteTempActive = false;
hp.setRemoteTemperature(0.0f);
// TODO(floatplane): do we need to explicitly call update? we don't do it anywhere else
hp.update();
}
}

void onLoopHeatPump() {
if (millis() - lastTempSend > SEND_ROOM_TEMP_INTERVAL_MS) { // only send the temperature every
// SEND_ROOM_TEMP_INTERVAL_MS
// (millis rollover tolerant)
hpCheckRemoteTemp(); // if the remote temperature feed from mqtt is stale,
// disable it and revert to the internal thermometer.

// TODO(floatplane): what? why?
// if (newStatus.roomTemperature == 0) {
// return;
// }

// TODO(floatplane): let's separate the job of periodically pushing latest state to MQTT from
// the job of figuring out whether to use the remote temp sensor or the internal one.
String mqttOutput;
Expand Down Expand Up @@ -2068,7 +2069,7 @@ void loop() { // NOLINT(readability-function-cognitive-complexity)
}
// MQTT connected send status
else {
onHeatPumpStatusChanged(hp.getStatus());
onLoopHeatPump();
mqtt_client.loop();
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ void handleUploadLoop();
void handleControl();
void initMqtt();
void initCaptivePortal();
void onHeatPumpSettingsChanged();
void onHeatPumpStatusChanged(heatpumpStatus newStatus);
void onLoopHeatPump();
void hpPacketDebug(byte *packet_, unsigned int length, char *packetDirection_);
float convertCelsiusToLocalUnit(float temperature, bool isFahrenheit);
float convertLocalUnitToCelsius(float temperature, bool isFahrenheit);
Expand Down

0 comments on commit dfd0e14

Please sign in to comment.