Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add commands for shower, small fixes #2178

Merged
merged 6 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 55 additions & 15 deletions src/emsdevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,27 @@ const char * EMSdevice::device_type_2_device_name(const uint8_t device_type) {
case DeviceType::GATEWAY:
return F_(gateway);
case DeviceType::SWITCH:
return F_(switch);
case DeviceType::CONTROLLER : return F_(controller); case DeviceType::CONNECT : return F_(connect); case DeviceType::ALERT : return F_(alert);
case DeviceType::EXTENSION : return F_(extension); case DeviceType::GENERIC : return F_(generic);
case DeviceType::HEATSOURCE : return F_(heatsource); case DeviceType::VENTILATION : return F_(ventilation);
case DeviceType::WATER : return F_(water); case DeviceType::POOL : return F_(pool); default : return Helpers::translated_word(FL_(unknown), true);
return F_(switcher);
case DeviceType::CONTROLLER:
return F_(controller);
case DeviceType::CONNECT:
return F_(connect);
case DeviceType::ALERT:
return F_(alert);
case DeviceType::EXTENSION:
return F_(extension);
case DeviceType::GENERIC:
return F_(generic);
case DeviceType::HEATSOURCE:
return F_(heatsource);
case DeviceType::VENTILATION:
return F_(ventilation);
case DeviceType::WATER:
return F_(water);
case DeviceType::POOL:
return F_(pool);
default:
return Helpers::translated_word(FL_(unknown), true);
}
}

Expand Down Expand Up @@ -217,23 +233,47 @@ uint8_t EMSdevice::device_name_2_device_type(const char * topic) {
if (!strcmp(lowtopic, F_(mixer))) {
return DeviceType::MIXER;
}
if (!strcmp(lowtopic, F_(switch))) {
return DeviceType::SWITCH;
}
if (!strcmp(lowtopic, F_(gateway))) { return DeviceType::GATEWAY; } if (!strcmp(lowtopic, F_(alert))) {
if (!strcmp(lowtopic, F_(switcher))) {
return DeviceType::SWITCH;
}
if (!strcmp(lowtopic, F_(gateway))) {
return DeviceType::GATEWAY;
}
if (!strcmp(lowtopic, F_(alert))) {
return DeviceType::ALERT;
} if (!strcmp(lowtopic, F_(extension))) { return DeviceType::EXTENSION; } if (!strcmp(lowtopic, F_(heatsource))) {
}
if (!strcmp(lowtopic, F_(extension))) {
return DeviceType::EXTENSION;
}
if (!strcmp(lowtopic, F_(heatsource))) {
return DeviceType::HEATSOURCE;
} if (!strcmp(lowtopic, F_(ventilation))) { return DeviceType::VENTILATION; } if (!strcmp(lowtopic, F_(water))) {
}
if (!strcmp(lowtopic, F_(ventilation))) {
return DeviceType::VENTILATION;
}
if (!strcmp(lowtopic, F_(water))) {
return DeviceType::WATER;
} if (!strcmp(lowtopic, F_(pool))) { return DeviceType::POOL; }
}
if (!strcmp(lowtopic, F_(pool))) {
return DeviceType::POOL;
}

// non EMS
if (!strcmp(lowtopic, F_(custom))) { return DeviceType::CUSTOM; } if (!strcmp(lowtopic, F_(temperaturesensor))) {
if (!strcmp(lowtopic, F_(custom))) {
return DeviceType::CUSTOM;
}
if (!strcmp(lowtopic, F_(temperaturesensor))) {
return DeviceType::TEMPERATURESENSOR;
} if (!strcmp(lowtopic, F_(analogsensor))) { return DeviceType::ANALOGSENSOR; } if (!strcmp(lowtopic, F_(scheduler))) {
}
if (!strcmp(lowtopic, F_(analogsensor))) {
return DeviceType::ANALOGSENSOR;
}
if (!strcmp(lowtopic, F_(scheduler))) {
return DeviceType::SCHEDULER;
} if (!strcmp(lowtopic, F_(system))) { return DeviceType::SYSTEM; }
}
if (!strcmp(lowtopic, F_(system))) {
return DeviceType::SYSTEM;
}

return DeviceType::UNKNOWN;
}
Expand Down
4 changes: 3 additions & 1 deletion src/locale_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ MAKE_WORD(send)
MAKE_WORD(telegram)
MAKE_WORD(bus_id)
MAKE_WORD(tx_mode)
MAKE_WORD(showertimer)
MAKE_WORD(showeralert)
MAKE_WORD(ems)
MAKE_WORD(devices)
MAKE_WORD(shower)
Expand Down Expand Up @@ -88,7 +90,7 @@ MAKE_WORD(coldshot)
// device types - lowercase, used in MQTT
MAKE_WORD(boiler)
MAKE_WORD(thermostat)
MAKE_WORD(switch)
MAKE_WORD_CUSTOM(switcher, "switch")
MAKE_WORD(solar)
MAKE_WORD(mixer)
MAKE_WORD(gateway)
Expand Down
2 changes: 2 additions & 0 deletions src/locale_translations.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ MAKE_WORD_TRANSLATION(commands_response, "get response", "Hole Antwort", "Verzoe
MAKE_WORD_TRANSLATION(coldshot_cmd, "send a cold shot of water", "Zugabe einer Menge kalten Wassers", "", "", "uruchom tryśnięcie zimnej wody", "", "", "soğuk su gönder", "", "pošlite studenú dávku vody", "poslat studenou vodu") // TODO translate
MAKE_WORD_TRANSLATION(message_cmd, "send a message", "Eine Nachricht senden", "", "", "", "", "", "", "", "poslať správu", "odeslat zprávu") // TODO translate
MAKE_WORD_TRANSLATION(values_cmd, "list all values", "Liste alle Werte auf", "", "", "", "", "", "", "", "vypísať všetky hodnoty", "vypsat všechny hodnoty") // TODO translate
MAKE_WORD_TRANSLATION(showertimer_cmd, "enable shower timer", "aktiviere Duschzeitmessung", "", "", "", "", "", "", "", "", "") // TODO translate
MAKE_WORD_TRANSLATION(showeralert_cmd, "enable shower alert", "aktiviere Duschzeitwarnung", "", "", "", "", "", "", "", "", "") // TODO translate

// tags
MAKE_WORD_TRANSLATION(tag_hc1, "hc1", "HK1", "hc1", "VK1", "OG1", "hc1", "hc1", "ID1", "hc1", "hc1", "hc1")
Expand Down
1 change: 1 addition & 0 deletions src/mqtt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,7 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
break;
default:
// plain old sensor
snprintf(topic, sizeof(topic), "sensor/%s", config_topic);
proddy marked this conversation as resolved.
Show resolved Hide resolved
break;
}
} else {
Expand Down
42 changes: 42 additions & 0 deletions src/shower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,48 @@ void Shower::start() {
FL_(coldshot_cmd),
CommandFlag::ADMIN_ONLY);

Command::add(
EMSdevice::DeviceType::SYSTEM,
F_(showertimer),
[&](const char * value, const int8_t id, JsonObject output) {
bool b;
if (!Helpers::value2bool(value, b)) {
return false;
}
shower_timer_ = b;
EMSESP::webSettingsService.update([&](WebSettings & settings) {
if (settings.shower_timer != b) {
settings.shower_timer = b;
return StateUpdateResult::CHANGED;
}
return StateUpdateResult::UNCHANGED;
});
return true;
},
FL_(showertimer_cmd),
CommandFlag::ADMIN_ONLY);

Command::add(
EMSdevice::DeviceType::SYSTEM,
F_(showeralert),
[&](const char * value, const int8_t id, JsonObject output) {
bool b;
if (!Helpers::value2bool(value, b)) {
return false;
}
shower_alert_ = b;
EMSESP::webSettingsService.update([&](WebSettings & settings) {
if (settings.shower_alert != b) {
settings.shower_alert = b;
return StateUpdateResult::CHANGED;
}
return StateUpdateResult::UNCHANGED;
});
return true;
},
FL_(showeralert_cmd),
CommandFlag::ADMIN_ONLY);

if (shower_timer_) {
set_shower_state(false, true); // turns shower to off and creates HA topic if not already done
}
Expand Down
2 changes: 1 addition & 1 deletion src/telegram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ void RxService::add(uint8_t * data, uint8_t length) {
// validate the CRC. if it fails then increment the number of corrupt/incomplete telegrams and only report to console/syslog
uint8_t crc = calculate_crc(data, length - 1);
if (data[length - 1] != crc) {
if ((data[0] & 0x7F) != ems_bus_id()) { // do not count echos as errors
if (data[0] != EMSuart::last_tx_src()) { // do not count echos as errors
telegram_error_count_++;
LOG_WARNING("Incomplete Rx: %s", Helpers::data_to_hex(data, length).c_str()); // include CRC
} else {
Expand Down
3 changes: 3 additions & 0 deletions src/uart/emsuart_esp32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "emsesp.h"

namespace emsesp {
uint8_t EMSuart::last_tx_src_ = 0;

static QueueHandle_t uart_queue;
uint8_t tx_mode_ = 0xFF;
Expand Down Expand Up @@ -144,6 +145,8 @@ uint16_t EMSuart::transmit(const uint8_t * buf, const uint8_t len) {
return EMS_TX_STATUS_OK;
}

last_tx_src_ = len < 4 ? 0 : buf[0];

if (tx_mode_ == EMS_TXMODE_HW) { // hardware controlled mode
uart_write_bytes_with_break(EMSUART_NUM, buf, len, 10);
return EMS_TX_STATUS_OK;
Expand Down
4 changes: 4 additions & 0 deletions src/uart/emsuart_esp32.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,14 @@ class EMSuart {
static void send_poll(const uint8_t data);
static void stop();
static uint16_t transmit(const uint8_t * buf, const uint8_t len);
static uint8_t last_tx_src() {
return last_tx_src_;
}

private:
static void IRAM_ATTR uart_gen_break(uint32_t length_us);
static void uart_event_task(void * pvParameters);
static uint8_t last_tx_src_;
};

} // namespace emsesp
Expand Down