Skip to content

Commit

Permalink
1.38
Browse files Browse the repository at this point in the history
  • Loading branch information
klausahrenberg committed Nov 26, 2023
1 parent 0daf1d2 commit 07ec967
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 151 deletions.
Binary file renamed WThermostat_1.36.bin → WThermostat_1.38.bin
Binary file not shown.
154 changes: 77 additions & 77 deletions src/WClock.h

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/WThermostat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "WThermostat_DLX_LH01.h"

#define APPLICATION "Thermostat"
#define VERSION "1.36"
#define VERSION "1.38"
#define FLAG_SETTINGS 0x35
#define DEBUG false

Expand All @@ -37,7 +37,7 @@ void setup() {
thermostatModel = network->settings()->setByte("thermostatModel", MODEL_BHT_002_GBLW);
//Thermostat device
device = nullptr;
switch (thermostatModel->getByte()) {
switch (thermostatModel->asByte()) {
case MODEL_BHT_002_GBLW :
device = new WThermostat_BHT_002_GBLW(network, thermostatModel, wClock);
break;
Expand Down Expand Up @@ -66,7 +66,7 @@ void setup() {
device = new WThermostat_DLX_LH01(network, thermostatModel, wClock);
break;
default :
network->error(F("Can't start device. Wrong thermostatModel (%d)"), thermostatModel->getByte());
network->error(F("Can't start device. Wrong thermostatModel (%d)"), thermostatModel->asByte());
}
if (device != nullptr) {
device->configureCommandBytes();
Expand Down
96 changes: 48 additions & 48 deletions src/WThermostat.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,17 @@ public :
this->schedulesDayOffset = network()->settings()->setByte("schedulesDayOffset", 0);
//standard properties
this->actualTemperature = WProps::createTemperatureProperty("temperature", "Actual");
this->actualTemperature->setReadOnly(true);
this->actualTemperature->readOnly(true);
this->addProperty(actualTemperature);
this->targetTemperature = WProps::createTargetTemperatureProperty("targetTemperature", "Target");
this->targetTemperature->setMultipleOf(1.0f / this->temperatureFactor);
this->targetTemperature->multipleOf(1.0f / this->temperatureFactor);
this->targetTemperature->addListener(std::bind(&WThermostat::setTargetTemperature, this, std::placeholders::_1));
this->targetTemperature->setOnValueRequest([this](WProperty* p) {updateTargetTemperature();});
this->targetTemperature->onValueRequest([this](WProperty* p) {updateTargetTemperature();});
this->addProperty(targetTemperature);
if (byteTemperatureFloor != NOT_SUPPORTED) {
this->actualFloorTemperature = WProps::createTargetTemperatureProperty("floorTemperature", "Floor");
this->actualFloorTemperature->setReadOnly(true);
this->actualFloorTemperature->setVisibility(MQTT);
this->actualFloorTemperature->readOnly(true);
this->actualFloorTemperature->visibility(MQTT);
this->addProperty(actualFloorTemperature);
} else {
this->actualFloorTemperature = nullptr;
Expand All @@ -110,16 +110,16 @@ public :
this->switchBackToAuto = network()->settings()->setBoolean("switchBackToAuto", true);
this->locked = WProps::createOnOffProperty("locked", "Lock");
this->locked->addListener(std::bind(&WThermostat::lockedToMcu, this, std::placeholders::_1));
this->locked->setVisibility(MQTT);
this->locked->visibility(MQTT);
this->addProperty(locked);
this->completeDeviceState = network()->settings()->setBoolean("sendCompleteDeviceState", true);
//Heating Relay and State property
this->state = nullptr;
this->supportingHeatingRelay = network()->settings()->setBoolean("supportingHeatingRelay", true);
if (this->supportingHeatingRelay->getBoolean()) {
if (this->supportingHeatingRelay->asBool()) {
pinMode(PIN_STATE_HEATING_RELAY, INPUT);
this->state = new WProperty("state", "State", STRING, TYPE_HEATING_COOLING_PROPERTY);
this->state->setReadOnly(true);
this->state->readOnly(true);
this->state->addEnumString(STATE_OFF);
this->state->addEnumString(STATE_HEATING);
this->addProperty(state);
Expand All @@ -130,18 +130,18 @@ public :
page->printf(HTTP_CONFIG_PAGE_BEGIN, id());
//ComboBox with model selection
page->printf(HTTP_COMBOBOX_BEGIN, "Thermostat model:", "tm");
page->printf(HTTP_COMBOBOX_ITEM, "0", (this->thermostatModel->getByte() == 0 ? HTTP_SELECTED : ""), "BHT-002, BHT-6000, BHT-3000 (floor heating)");
page->printf(HTTP_COMBOBOX_ITEM, "6", (this->thermostatModel->getByte() == 6 ? HTTP_SELECTED : ""), "AVATTO ME102H (Touch screen)");
page->printf(HTTP_COMBOBOX_ITEM, "1", (this->thermostatModel->getByte() == 1 ? HTTP_SELECTED : ""), "BAC-002, BAC-1000 (heating, cooling, ventilation)");
page->printf(HTTP_COMBOBOX_ITEM, "2", (this->thermostatModel->getByte() == 2 ? HTTP_SELECTED : ""), "ET-81W");
page->printf(HTTP_COMBOBOX_ITEM, "3", (this->thermostatModel->getByte() == 3 ? HTTP_SELECTED : ""), "Floureon HY08WE");
page->printf(HTTP_COMBOBOX_ITEM, "4", (this->thermostatModel->getByte() == 4 ? HTTP_SELECTED : ""), "AVATTO ME81AH");
page->printf(HTTP_COMBOBOX_ITEM, "5", (this->thermostatModel->getByte() == 5 ? HTTP_SELECTED : ""), "Minco Heat MK70GB-H");
page->printf(HTTP_COMBOBOX_ITEM, "7", (this->thermostatModel->getByte() == 7 ? HTTP_SELECTED : ""), "VH Control Calypso-W");
page->printf(HTTP_COMBOBOX_ITEM, "8", (this->thermostatModel->getByte() == 8 ? HTTP_SELECTED : ""), "DLX-LH01");
page->printf(HTTP_COMBOBOX_ITEM, "0", (this->thermostatModel->asByte() == 0 ? HTTP_SELECTED : ""), "BHT-002, BHT-6000, BHT-3000 (floor heating)");
page->printf(HTTP_COMBOBOX_ITEM, "6", (this->thermostatModel->asByte() == 6 ? HTTP_SELECTED : ""), "AVATTO ME102H (Touch screen)");
page->printf(HTTP_COMBOBOX_ITEM, "1", (this->thermostatModel->asByte() == 1 ? HTTP_SELECTED : ""), "BAC-002, BAC-1000 (heating, cooling, ventilation)");
page->printf(HTTP_COMBOBOX_ITEM, "2", (this->thermostatModel->asByte() == 2 ? HTTP_SELECTED : ""), "ET-81W");
page->printf(HTTP_COMBOBOX_ITEM, "3", (this->thermostatModel->asByte() == 3 ? HTTP_SELECTED : ""), "Floureon HY08WE");
page->printf(HTTP_COMBOBOX_ITEM, "4", (this->thermostatModel->asByte() == 4 ? HTTP_SELECTED : ""), "AVATTO ME81AH");
page->printf(HTTP_COMBOBOX_ITEM, "5", (this->thermostatModel->asByte() == 5 ? HTTP_SELECTED : ""), "Minco Heat MK70GB-H");
page->printf(HTTP_COMBOBOX_ITEM, "7", (this->thermostatModel->asByte() == 7 ? HTTP_SELECTED : ""), "VH Control Calypso-W");
page->printf(HTTP_COMBOBOX_ITEM, "8", (this->thermostatModel->asByte() == 8 ? HTTP_SELECTED : ""), "DLX-LH01");
page->print(FPSTR(HTTP_COMBOBOX_END));
//Checkbox
page->printf(HTTP_CHECKBOX_OPTION, "sb", "sb", (this->switchBackToAuto->getBoolean() ? HTTP_CHECKED : ""), "", "Auto mode from manual mode at next schedule period change <br> (not at model ET-81W and ME81AH)");
page->printf(HTTP_CHECKBOX_OPTION, "sb", "sb", (this->switchBackToAuto->asBool() ? HTTP_CHECKED : ""), "", "Auto mode from manual mode at next schedule period change <br> (not at model ET-81W and ME81AH)");
//ComboBox with weekday
page->printf(HTTP_COMBOBOX_BEGIN, "Workday schedules:", "ws");
page->printf(HTTP_COMBOBOX_ITEM, "0", (getSchedulesDayOffset() == 0 ? HTTP_SELECTED : ""), "Workday Mon-Fri; Weekend Sat-Sun");
Expand All @@ -154,9 +154,9 @@ public :
page->print(FPSTR(HTTP_COMBOBOX_END));
page->printf(HTTP_CHECKBOX_OPTION, "cr", "cr", (this->sendCompleteDeviceState() ? "" : HTTP_CHECKED), "", "Send changes in separate MQTT messages");
//notifyAllMcuCommands
page->printf(HTTP_CHECKBOX_OPTION, "am", "am", (this->notifyAllMcuCommands->getBoolean() ? HTTP_CHECKED : ""), "", "Send all MCU commands via MQTT");
page->printf(HTTP_CHECKBOX_OPTION, "am", "am", (this->notifyAllMcuCommands->asBool() ? HTTP_CHECKED : ""), "", "Send all MCU commands via MQTT");
//Checkbox with support for relay
page->printf(HTTP_CHECKBOX_OPTION, "rs", "rs", (this->supportingHeatingRelay->getBoolean() ? HTTP_CHECKED : ""), "", "Relay at GPIO 5 (not working without hw mod)");
page->printf(HTTP_CHECKBOX_OPTION, "rs", "rs", (this->supportingHeatingRelay->asBool() ? HTTP_CHECKED : ""), "", "Relay at GPIO 5 (not working without hw mod)");

printConfigPageCustomParameters(request, page);

Expand All @@ -168,12 +168,12 @@ public :
}

virtual void submitConfigPage(AsyncWebServerRequest* request, Print* page) {
this->thermostatModel->setByte(request->arg("tm").toInt());
this->schedulesDayOffset->setByte(request->arg("ws").toInt());
this->switchBackToAuto->setBoolean(request->arg("sb") == HTTP_TRUE);
this->completeDeviceState->setBoolean(request->arg("cr") != HTTP_TRUE);
this->notifyAllMcuCommands->setBoolean(request->arg("am") == HTTP_TRUE);
this->supportingHeatingRelay->setBoolean(request->arg("rs") == HTTP_TRUE);
this->thermostatModel->asByte(request->arg("tm").toInt());
this->schedulesDayOffset->asByte(request->arg("ws").toInt());
this->switchBackToAuto->asBool(request->arg("sb") == HTTP_TRUE);
this->completeDeviceState->asBool(request->arg("cr") != HTTP_TRUE);
this->notifyAllMcuCommands->asBool(request->arg("am") == HTTP_TRUE);
this->supportingHeatingRelay->asBool(request->arg("rs") == HTTP_TRUE);
submitConfigPageCustomParameters(request, page);
}

Expand Down Expand Up @@ -303,10 +303,10 @@ public :
virtual void loop(unsigned long now) {
if (state != nullptr) {
bool heating = false;
if ((this->supportingHeatingRelay->getBoolean()) && (state != nullptr)) {
if ((this->supportingHeatingRelay->asBool()) && (state != nullptr)) {
heating = digitalRead(PIN_STATE_HEATING_RELAY);
}
this->state->setString(heating ? STATE_HEATING : STATE_OFF);
this->state->asString(heating ? STATE_HEATING : STATE_OFF);
}
WTuyaDevice::loop(now);
updateCurrentSchedulePeriod();
Expand All @@ -321,7 +321,7 @@ public :
}

virtual bool sendCompleteDeviceState() {
return this->completeDeviceState->getBoolean();
return this->completeDeviceState->asBool();
}

protected :
Expand Down Expand Up @@ -391,7 +391,7 @@ protected :
}

byte getSchedulesDayOffset() {
return schedulesDayOffset->getByte();
return schedulesDayOffset->asByte();
}

virtual bool processCommand(byte commandByte, byte length) {
Expand Down Expand Up @@ -437,8 +437,8 @@ protected :
//2021-01-24 test for bht-002
if (!this->mcuRestarted) {
newB = (receivedCommand[10] == 0x01);
changed = ((changed) || (newB != deviceOn->getBoolean()));
deviceOn->setBoolean(newB);
changed = ((changed) || (newB != deviceOn->asBool()));
deviceOn->asBool(newB);
} else if (!this->deviceOn->isNull()) {
deviceOnToMcu(this->deviceOn);
this->mcuRestarted = false;
Expand All @@ -464,7 +464,7 @@ protected :
unsigned long rawValue = WSettings::getUnsignedLong(receivedCommand[10], receivedCommand[11], receivedCommand[12], receivedCommand[13]);
newValue = (float) rawValue / this->temperatureFactor;
changed = ((changed) || (!actualTemperature->equalsDouble(newValue)));
actualTemperature->setDouble(newValue);
actualTemperature->asDouble(newValue);
knownCommand = true;
}
} else if ((byteTemperatureFloor != NOT_SUPPORTED) && (cByte == byteTemperatureFloor)) {
Expand All @@ -474,15 +474,15 @@ protected :
unsigned long rawValue = WSettings::getUnsignedLong(receivedCommand[10], receivedCommand[11], receivedCommand[12], receivedCommand[13]);
newValue = (float) rawValue / this->temperatureFactor;
changed = ((changed) || (!actualFloorTemperature->equalsDouble(newValue)));
actualFloorTemperature->setDouble(newValue);
actualFloorTemperature->asDouble(newValue);
knownCommand = true;
}
} else if (cByte == byteSchedulesMode) {
if (commandLength == 0x05) {
//schedulesMode
newS = schedulesMode->getEnumString(receivedCommand[10]);
newS = schedulesMode->enumString(receivedCommand[10]);
if (newS != nullptr) {
changed = ((changed) || (schedulesMode->setString(newS)));
changed = ((changed) || (schedulesMode->asString(newS)));
if (changed) updateTargetTemperature();
knownCommand = true;
}
Expand All @@ -491,8 +491,8 @@ protected :
if (commandLength == 0x05) {
//locked
newB = (receivedCommand[10] == 0x01);
changed = ((changed) || (newB != locked->getBoolean()));
locked->setBoolean(newB);
changed = ((changed) || (newB != locked->asBool()));
locked->asBool(newB);
knownCommand = true;
}
} else if (cByte == byteSchedules) {
Expand Down Expand Up @@ -561,10 +561,10 @@ protected :
}
}
int newPeriod = startAddr + period * 3;
if ((this->switchBackToAuto->getBoolean()) &&
if ((this->switchBackToAuto->asBool()) &&
(this->currentSchedulePeriod > -1) && (newPeriod != this->currentSchedulePeriod) &&
(this->schedulesMode->equalsString(SCHEDULES_MODE_OFF))) {
this->schedulesMode->setString(SCHEDULES_MODE_AUTO);
this->schedulesMode->asString(SCHEDULES_MODE_AUTO);
}
this->currentSchedulePeriod = newPeriod;
} else {
Expand All @@ -575,7 +575,7 @@ protected :
virtual void deviceOnToMcu(WProperty* property) {
if (!isReceivingDataFromMcu()) {
//55 AA 00 06 00 05 01 01 00 01 01
byte dt = (this->deviceOn->getBoolean() ? 0x01 : 0x00);
byte dt = (this->deviceOn->asBool() ? 0x01 : 0x00);
unsigned char deviceOnCommand[] = { 0x55, 0xAA, 0x00, 0x06, 0x00, 0x05,
byteDeviceOn, 0x01, 0x00, 0x01, dt};
commandCharsToSerial(11, deviceOnCommand);
Expand All @@ -597,7 +597,7 @@ protected :
void schedulesModeToMcu(WProperty* property) {
if ((!isReceivingDataFromMcu()) && (schedulesMode != nullptr)) {
//55 AA 00 06 00 05 04 04 00 01 01
byte sm = schedulesMode->getEnumIndex();
byte sm = schedulesMode->enumIndex();
if (sm != 0xFF) {
unsigned char deviceOnCommand[] = { 0x55, 0xAA, 0x00, 0x06, 0x00, 0x05,
byteSchedulesMode, 0x04, 0x00, 0x01, sm};
Expand All @@ -608,7 +608,7 @@ protected :

void lockedToMcu(WProperty* property) {
if (!isReceivingDataFromMcu()) {
byte dt = (this->locked->getBoolean() ? 0x01 : 0x00);
byte dt = (this->locked->asBool() ? 0x01 : 0x00);
unsigned char deviceOnCommand[] = { 0x55, 0xAA, 0x00, 0x06, 0x00, 0x05,
byteLocked, 0x01, 0x00, 0x01, dt};
commandCharsToSerial(11, deviceOnCommand);
Expand Down Expand Up @@ -649,7 +649,7 @@ protected :
void handleSchedulesChange(String completeTopic) {
network()->debug(F("Send Schedules state..."));
if (completeTopic == "") {
completeTopic = String(network()->getMqttBaseTopic()) + SLASH + String(this->id()) + SLASH + String(network()->getMqttStateTopic()) + SLASH + SCHEDULES;
completeTopic = String(network()->mqttBaseTopic()) + SLASH + String(this->id()) + SLASH + String(network()->mqttStateTopic()) + SLASH + SCHEDULES;
}
WStringStream* response = network()->getResponseStream();
WJson json(response);
Expand Down Expand Up @@ -732,8 +732,8 @@ protected :
}

void setTargetTemperature(WProperty* property) {
if (!WProperty::isEqual(targetTemperatureManualMode, this->targetTemperature->getDouble(), 0.01)) {
targetTemperatureManualMode = this->targetTemperature->getDouble();
if (!WProperty::isEqual(targetTemperatureManualMode, this->targetTemperature->asDouble(), 0.01)) {
targetTemperatureManualMode = this->targetTemperature->asDouble();
targetTemperatureManualModeToMcu();
//schedulesMode->setString(SCHEDULES_MODE_OFF);
}
Expand All @@ -742,9 +742,9 @@ protected :
void updateTargetTemperature() {
if ((this->currentSchedulePeriod != -1) && (schedulesMode->equalsString(SCHEDULES_MODE_AUTO))) {
double temp = (double) schedules[this->currentSchedulePeriod + 2] / this->temperatureFactor;
targetTemperature->setDouble(temp);
targetTemperature->asDouble(temp);
} else {
targetTemperature->setDouble(targetTemperatureManualMode);
targetTemperature->asDouble(targetTemperatureManualMode);
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/WThermostat_BAC_002_ALW.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ protected :
//cooling: 55 AA 00 06 00 05 66 04 00 01 00
//heating: 55 AA 00 06 00 05 66 04 00 01 01
//ventilation: 55 AA 00 06 00 05 66 04 00 01 02
newS = systemMode->getEnumString(receivedCommand[10]);
newS = systemMode->enumString(receivedCommand[10]);
if (newS != nullptr) {
changed = ((changed) || (systemMode->setString(newS)));
changed = ((changed) || (systemMode->asString(newS)));
knownCommand = true;
}
}
Expand All @@ -84,9 +84,9 @@ protected :
//high - 55 aa 01 07 00 05 67 04 00 01 01
//medium - 55 aa 01 07 00 05 67 04 00 01 02
//low - 55 aa 01 07 00 05 67 04 00 01 03
newS = fanMode->getEnumString(receivedCommand[10]);
newS = fanMode->enumString(receivedCommand[10]);
if (newS != nullptr) {
changed = ((changed) || (fanMode->setString(newS)));
changed = ((changed) || (fanMode->asString(newS)));
knownCommand = true;
}
}
Expand All @@ -105,7 +105,7 @@ protected :

void systemModeToMcu(WProperty* property) {
if (!isReceivingDataFromMcu()) {
byte sm = property->getEnumIndex();
byte sm = property->enumIndex();
if (sm != 0xFF) {
//send to device
//cooling: 55 AA 00 06 00 05 66 04 00 01 00
Expand All @@ -120,7 +120,7 @@ protected :

void fanModeToMcu(WProperty* property) {
if (!isReceivingDataFromMcu()) {
byte fm = fanMode->getEnumIndex();
byte fm = fanMode->enumIndex();
if (fm != 0xFF) {
//send to device
//auto: 55 aa 00 06 00 05 67 04 00 01 00
Expand Down
8 changes: 4 additions & 4 deletions src/WThermostat_ME102H.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public :
this->sensorSelection->addEnumString(SENSOR_SELECTION_INTERNAL);
this->sensorSelection->addEnumString(SENSOR_SELECTION_FLOOR);
this->sensorSelection->addEnumString(SENSOR_SELECTION_BOTH);
this->sensorSelection->setVisibility(MQTT);
this->sensorSelection->visibility(MQTT);
this->sensorSelection->addListener(std::bind(&WThermostat_ME102H::sensorSelectionToMcu, this, std::placeholders::_1));
this->addProperty(this->sensorSelection);
}
Expand All @@ -63,9 +63,9 @@ protected :
//internal: 55 aa 03 07 00 05 2b 04 00 01 00
//floor: 55 aa 03 07 00 05 2b 04 00 01 01
//both: 55 aa 03 07 00 05 2b 04 00 01 02
newS = this->sensorSelection->getEnumString(receivedCommand[10]);
newS = this->sensorSelection->enumString(receivedCommand[10]);
if (newS != nullptr) {
changed = ((changed) || (this->sensorSelection->setString(newS)));
changed = ((changed) || (this->sensorSelection->asString(newS)));
knownCommand = true;
}
}
Expand Down Expand Up @@ -121,7 +121,7 @@ protected :

void sensorSelectionToMcu(WProperty* property) {
if (!isReceivingDataFromMcu()) {
byte sm = property->getEnumIndex();
byte sm = property->enumIndex();
if (sm != 0xFF) {
//send to device
//internal: 55 aa 03 07 00 05 2b 04 00 01 00
Expand Down
Loading

0 comments on commit 07ec967

Please sign in to comment.