mirror of
https://github.com/Laxilef/OTGateway.git
synced 2025-12-10 18:24:27 +05:00
refactoring: moving some strings to flash memory
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
#include "strings.h"
|
||||
|
||||
class HomeAssistantHelper {
|
||||
public:
|
||||
@@ -57,7 +58,7 @@ public:
|
||||
if (this->deviceManufacturer != nullptr) {
|
||||
doc[FPSTR(HA_DEVICE)][FPSTR(HA_MANUFACTURER)] = this->deviceManufacturer;
|
||||
}
|
||||
|
||||
|
||||
if (this->deviceModel != nullptr) {
|
||||
doc[FPSTR(HA_DEVICE)][FPSTR(HA_MODEL)] = this->deviceModel;
|
||||
}
|
||||
@@ -65,7 +66,7 @@ public:
|
||||
if (this->deviceName != nullptr) {
|
||||
doc[FPSTR(HA_DEVICE)][FPSTR(HA_NAME)] = this->deviceName;
|
||||
}
|
||||
|
||||
|
||||
if (this->deviceConfigUrl != nullptr) {
|
||||
doc[FPSTR(HA_DEVICE)][FPSTR(HA_CONF_URL)] = this->deviceConfigUrl;
|
||||
}
|
||||
@@ -95,7 +96,8 @@ public:
|
||||
return result;
|
||||
}
|
||||
|
||||
String getTopic(const char* category, const char* name, char nameSeparator = '/') {
|
||||
template <class T>
|
||||
String getTopic(T category, T name, char nameSeparator = '/') {
|
||||
String topic = "";
|
||||
topic.concat(this->prefix);
|
||||
topic.concat('/');
|
||||
@@ -107,8 +109,9 @@ public:
|
||||
topic.concat("/config");
|
||||
return topic;
|
||||
}
|
||||
|
||||
template <class T> String getDeviceTopic(T value, char separator = '/') {
|
||||
|
||||
template <class T>
|
||||
String getDeviceTopic(T value, char separator = '/') {
|
||||
String topic = "";
|
||||
topic.concat(this->devicePrefix);
|
||||
topic.concat(separator);
|
||||
@@ -116,7 +119,8 @@ public:
|
||||
return topic;
|
||||
}
|
||||
|
||||
template <class T> String getObjectId(T value, char separator = '_') {
|
||||
template <class T>
|
||||
String getObjectId(T value, char separator = '_') {
|
||||
String topic = "";
|
||||
topic.concat(this->devicePrefix);
|
||||
topic.concat(separator);
|
||||
|
||||
688
src/HaHelper.h
688
src/HaHelper.h
File diff suppressed because it is too large
Load Diff
@@ -38,7 +38,7 @@ protected:
|
||||
if (settings.heating.turbo) {
|
||||
settings.heating.turbo = false;
|
||||
|
||||
Log.sinfoln("REGULATOR", F("Turbo mode auto disabled"));
|
||||
Log.sinfoln(FPSTR(L_REGULATOR), F("Turbo mode auto disabled"));
|
||||
}
|
||||
|
||||
newTemp = getEmergencyModeTemp();
|
||||
@@ -48,7 +48,7 @@ protected:
|
||||
if (settings.heating.turbo) {
|
||||
settings.heating.turbo = false;
|
||||
|
||||
Log.sinfoln("REGULATOR", F("Turbo mode auto disabled"));
|
||||
Log.sinfoln(FPSTR(L_REGULATOR), F("Turbo mode auto disabled"));
|
||||
}
|
||||
|
||||
newTemp = getTuningModeTemp();
|
||||
@@ -62,7 +62,7 @@ protected:
|
||||
if (settings.heating.turbo && (fabs(settings.heating.target - vars.temperatures.indoor) < 1 || !settings.heating.enable || (settings.equitherm.enable && settings.pid.enable))) {
|
||||
settings.heating.turbo = false;
|
||||
|
||||
Log.sinfoln("REGULATOR", F("Turbo mode auto disabled"));
|
||||
Log.sinfoln(FPSTR(L_REGULATOR), F("Turbo mode auto disabled"));
|
||||
}
|
||||
|
||||
newTemp = getNormalModeTemp();
|
||||
@@ -91,7 +91,7 @@ protected:
|
||||
prevEtResult = etResult;
|
||||
newTemp += etResult;
|
||||
|
||||
Log.sinfoln("REGULATOR.EQUITHERM", F("New emergency result: %hhu (%.2f)"), (uint8_t) round(etResult), etResult);
|
||||
Log.sinfoln(FPSTR(L_REGULATOR_EQUITHERM), F("New emergency result: %hhu (%.2f)"), (uint8_t) round(etResult), etResult);
|
||||
|
||||
} else {
|
||||
newTemp += prevEtResult;
|
||||
@@ -108,7 +108,7 @@ protected:
|
||||
prevPidResult = pidResult;
|
||||
newTemp += pidResult;
|
||||
|
||||
Log.sinfoln("REGULATOR.PID", F("New emergency result: %hhu (%.2f)"), (uint8_t) round(pidResult), pidResult);
|
||||
Log.sinfoln(FPSTR(L_REGULATOR_PID), F("New emergency result: %hhu (%.2f)"), (uint8_t) round(pidResult), pidResult);
|
||||
|
||||
} else {
|
||||
newTemp += prevPidResult;
|
||||
@@ -131,11 +131,11 @@ protected:
|
||||
|
||||
if (fabs(prevHeatingTarget - settings.heating.target) > 0.0001) {
|
||||
prevHeatingTarget = settings.heating.target;
|
||||
Log.sinfoln("REGULATOR", F("New target: %.2f"), settings.heating.target);
|
||||
Log.sinfoln(FPSTR(L_REGULATOR), F("New target: %.2f"), settings.heating.target);
|
||||
|
||||
if (settings.equitherm.enable && settings.pid.enable) {
|
||||
pidRegulator.integral = 0;
|
||||
Log.sinfoln("REGULATOR.PID", F("Integral sum has been reset"));
|
||||
Log.sinfoln(FPSTR(L_REGULATOR_PID), F("Integral sum has been reset"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ protected:
|
||||
prevEtResult = etResult;
|
||||
newTemp += etResult;
|
||||
|
||||
Log.sinfoln("REGULATOR.EQUITHERM", F("New result: %hhu (%.2f)"), (uint8_t) round(etResult), etResult);
|
||||
Log.sinfoln(FPSTR(L_REGULATOR_EQUITHERM), F("New result: %hhu (%.2f)"), (uint8_t) round(etResult), etResult);
|
||||
|
||||
} else {
|
||||
newTemp += prevEtResult;
|
||||
@@ -166,7 +166,7 @@ protected:
|
||||
prevPidResult = pidResult;
|
||||
newTemp += pidResult;
|
||||
|
||||
Log.sinfoln("REGULATOR.PID", F("New result: %hhd (%.2f)"), (int8_t) round(pidResult), pidResult);
|
||||
Log.sinfoln(FPSTR(L_REGULATOR_PID), F("New result: %hhd (%.2f)"), (int8_t) round(pidResult), pidResult);
|
||||
|
||||
} else {
|
||||
newTemp += prevPidResult;
|
||||
|
||||
@@ -12,10 +12,6 @@
|
||||
const uint16_t bleUuidCharacteristicHumidity = 0x2A6F;
|
||||
#endif
|
||||
|
||||
const char S_SENSORS_OUTDOOR[] PROGMEM = "SENSORS.OUTDOOR";
|
||||
const char S_SENSORS_INDOOR[] PROGMEM = "SENSORS.INDOOR";
|
||||
const char S_SENSORS_BLE[] PROGMEM = "SENSORS.BLE";
|
||||
|
||||
class SensorsTask : public LeanTask {
|
||||
public:
|
||||
SensorsTask(bool _enabled = false, unsigned long _interval = 0) : LeanTask(_enabled, _interval) {
|
||||
@@ -99,7 +95,7 @@ protected:
|
||||
#if USE_BLE
|
||||
void bluetoothSensor() {
|
||||
if (!initBleSensor && millis() > 5000) {
|
||||
Log.sinfoln(FPSTR(S_SENSORS_BLE), "Init BLE. Free heap %u bytes", ESP.getFreeHeap());
|
||||
Log.sinfoln(FPSTR(L_SENSORS_BLE), "Init BLE. Free heap %u bytes", ESP.getFreeHeap());
|
||||
BLEDevice::init("");
|
||||
|
||||
pBleClient = BLEDevice::createClient();
|
||||
@@ -107,41 +103,41 @@ protected:
|
||||
// Connect to the remote BLE Server.
|
||||
BLEAddress bleServerAddress(std::string(settings.sensors.indoor.bleAddresss));
|
||||
if (pBleClient->connect(bleServerAddress)) {
|
||||
Log.sinfoln(FPSTR(S_SENSORS_BLE), "Connected to BLE device at %s", bleServerAddress.toString().c_str());
|
||||
Log.sinfoln(FPSTR(L_SENSORS_BLE), "Connected to BLE device at %s", bleServerAddress.toString().c_str());
|
||||
// Obtain a reference to the services we are interested in
|
||||
pBleServiceBattery = pBleClient->getService(BLEUUID(bleUuidServiceBattery));
|
||||
if (pBleServiceBattery == nullptr) {
|
||||
Log.sinfoln(FPSTR(S_SENSORS_BLE), "Failed to find battery service");
|
||||
Log.sinfoln(FPSTR(L_SENSORS_BLE), "Failed to find battery service");
|
||||
}
|
||||
pBleServiceEnvironment = pBleClient->getService(BLEUUID(bleUuidServiceEnvironment));
|
||||
if (pBleServiceEnvironment == nullptr) {
|
||||
Log.sinfoln(FPSTR(S_SENSORS_BLE), "Failed to find environmental service");
|
||||
Log.sinfoln(FPSTR(L_SENSORS_BLE), "Failed to find environmental service");
|
||||
}
|
||||
|
||||
} else {
|
||||
Log.swarningln(FPSTR(S_SENSORS_BLE), "Error connecting to BLE device at %s", bleServerAddress.toString().c_str());
|
||||
Log.swarningln(FPSTR(L_SENSORS_BLE), "Error connecting to BLE device at %s", bleServerAddress.toString().c_str());
|
||||
}
|
||||
|
||||
initBleSensor = true;
|
||||
}
|
||||
|
||||
if (pBleClient && pBleClient->isConnected()) {
|
||||
Log.straceln(FPSTR(S_SENSORS_BLE), "Connected. Free heap %u bytes", ESP.getFreeHeap());
|
||||
Log.straceln(FPSTR(L_SENSORS_BLE), "Connected. Free heap %u bytes", ESP.getFreeHeap());
|
||||
if (pBleServiceBattery) {
|
||||
uint8_t batteryLevel = *reinterpret_cast<const uint8_t *>(pBleServiceBattery->getValue(bleUuidCharacteristicBatteryLevel).data());
|
||||
Log.straceln(FPSTR(S_SENSORS_BLE), "Battery: %d", batteryLevel);
|
||||
Log.straceln(FPSTR(L_SENSORS_BLE), "Battery: %d", batteryLevel);
|
||||
}
|
||||
|
||||
if (pBleServiceEnvironment) {
|
||||
float temperature = *reinterpret_cast<const int16_t *>(pBleServiceEnvironment->getValue(bleUuidCharacteristicTemperature).data()) / 100.0f;
|
||||
Log.straceln(FPSTR(S_SENSORS_BLE), "Temperature: %.2f", temperature);
|
||||
Log.straceln(FPSTR(L_SENSORS_BLE), "Temperature: %.2f", temperature);
|
||||
float humidity = *reinterpret_cast<const int16_t *>(pBleServiceEnvironment->getValue(bleUuidCharacteristicHumidity).data()) / 100.0f;
|
||||
Log.straceln(FPSTR(S_SENSORS_BLE), "Humidity: %.2f", humidity);
|
||||
Log.straceln(FPSTR(L_SENSORS_BLE), "Humidity: %.2f", humidity);
|
||||
|
||||
vars.temperatures.indoor = temperature + settings.sensors.indoor.offset;
|
||||
}
|
||||
} else {
|
||||
Log.straceln(FPSTR(S_SENSORS_BLE), "Not connected");
|
||||
Log.straceln(FPSTR(L_SENSORS_BLE), "Not connected");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -169,7 +165,7 @@ protected:
|
||||
this->outdoorSensor->requestTemperatures();
|
||||
this->startOutdoorConversionTime = millis();
|
||||
|
||||
Log.serrorln(FPSTR(S_SENSORS_OUTDOOR), F("Could not read temperature data (no response)"));
|
||||
Log.serrorln(FPSTR(L_SENSORS_OUTDOOR), F("Could not read temperature data (no response)"));
|
||||
}
|
||||
|
||||
if (!completed) {
|
||||
@@ -178,10 +174,10 @@ protected:
|
||||
|
||||
float rawTemp = this->outdoorSensor->getTempCByIndex(0);
|
||||
if (rawTemp == DEVICE_DISCONNECTED_C) {
|
||||
Log.serrorln(FPSTR(S_SENSORS_OUTDOOR), F("Could not read temperature data (not connected)"));
|
||||
Log.serrorln(FPSTR(L_SENSORS_OUTDOOR), F("Could not read temperature data (not connected)"));
|
||||
|
||||
} else {
|
||||
Log.straceln(FPSTR(S_SENSORS_OUTDOOR), F("Raw temp: %f"), rawTemp);
|
||||
Log.straceln(FPSTR(L_SENSORS_OUTDOOR), F("Raw temp: %f"), rawTemp);
|
||||
|
||||
if (this->emptyOutdoorTemp) {
|
||||
this->filteredOutdoorTemp = rawTemp;
|
||||
@@ -195,7 +191,7 @@ protected:
|
||||
|
||||
if (fabs(vars.temperatures.outdoor - this->filteredOutdoorTemp) > 0.099) {
|
||||
vars.temperatures.outdoor = this->filteredOutdoorTemp + settings.sensors.outdoor.offset;
|
||||
Log.sinfoln(FPSTR(S_SENSORS_OUTDOOR), F("New temp: %f"), this->filteredOutdoorTemp);
|
||||
Log.sinfoln(FPSTR(L_SENSORS_OUTDOOR), F("New temp: %f"), this->filteredOutdoorTemp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,7 +222,7 @@ protected:
|
||||
this->indoorSensor->requestTemperatures();
|
||||
this->startIndoorConversionTime = millis();
|
||||
|
||||
Log.serrorln(FPSTR(S_SENSORS_INDOOR), F("Could not read temperature data (no response)"));
|
||||
Log.serrorln(FPSTR(L_SENSORS_INDOOR), F("Could not read temperature data (no response)"));
|
||||
}
|
||||
|
||||
if (!completed) {
|
||||
@@ -235,10 +231,10 @@ protected:
|
||||
|
||||
float rawTemp = this->indoorSensor->getTempCByIndex(0);
|
||||
if (rawTemp == DEVICE_DISCONNECTED_C) {
|
||||
Log.serrorln(FPSTR(S_SENSORS_INDOOR), F("Could not read temperature data (not connected)"));
|
||||
Log.serrorln(FPSTR(L_SENSORS_INDOOR), F("Could not read temperature data (not connected)"));
|
||||
|
||||
} else {
|
||||
Log.straceln(FPSTR(S_SENSORS_INDOOR), F("Raw temp: %f"), rawTemp);
|
||||
Log.straceln(FPSTR(L_SENSORS_INDOOR), F("Raw temp: %f"), rawTemp);
|
||||
|
||||
if (this->emptyIndoorTemp) {
|
||||
this->filteredIndoorTemp = rawTemp;
|
||||
@@ -252,7 +248,7 @@ protected:
|
||||
|
||||
if (fabs(vars.temperatures.indoor - this->filteredIndoorTemp) > 0.099) {
|
||||
vars.temperatures.indoor = this->filteredIndoorTemp + settings.sensors.indoor.offset;
|
||||
Log.sinfoln(FPSTR(S_SENSORS_INDOOR), F("New temp: %f"), this->filteredIndoorTemp);
|
||||
Log.sinfoln(FPSTR(L_SENSORS_INDOOR), F("New temp: %f"), this->filteredIndoorTemp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user