diff --git a/src/core/console.cpp b/src/core/console.cpp index f7141baf0..59ab70403 100644 --- a/src/core/console.cpp +++ b/src/core/console.cpp @@ -100,6 +100,8 @@ static void setup_commands(std::shared_ptr const & commands) { EMSESP::show_sensor_values(shell); } else if (command == F_(mqtt)) { Mqtt::show_mqtt(shell); + } else if (command == F_(gpio)) { + EMSESP::system_.show_gpio(shell); } else { shell.printfln("Unknown show command"); } diff --git a/src/core/emsdevice.cpp b/src/core/emsdevice.cpp index baa5d6a23..586607241 100644 --- a/src/core/emsdevice.cpp +++ b/src/core/emsdevice.cpp @@ -1701,9 +1701,9 @@ std::string EMSdevice::get_metrics_prometheus(const int8_t tag) { // Helper function to check if a device value type is supported for Prometheus metrics auto is_supported_type = [](uint8_t type) -> bool { - return type == DeviceValueType::BOOL || type == DeviceValueType::UINT8 || type == DeviceValueType::INT8 - || type == DeviceValueType::UINT16 || type == DeviceValueType::INT16 || type == DeviceValueType::UINT24 - || type == DeviceValueType::UINT32 || type == DeviceValueType::TIME || type == DeviceValueType::ENUM; + return type == DeviceValueType::BOOL || type == DeviceValueType::UINT8 || type == DeviceValueType::INT8 || type == DeviceValueType::UINT16 + || type == DeviceValueType::INT16 || type == DeviceValueType::UINT24 || type == DeviceValueType::UINT32 || type == DeviceValueType::TIME + || type == DeviceValueType::ENUM; }; // Dynamically reserve memory for the result @@ -2086,17 +2086,6 @@ void EMSdevice::mqtt_ha_entity_config_create() { uint16_t count = 0; const char * const ** mode_options = nullptr; - // if it's a thermostat go fetch the list of modes - if (device_type() == EMSdevice::DeviceType::THERMOSTAT) { - for (auto & dv : devicevalues_) { - // make sure it's a type DeviceValueType::ENUM - if ((dv.type == DeviceValueType::ENUM) && !strcmp(dv.short_name, FL_(mode)[0])) { - // get options - mode_options = dv.options; - break; - } - } - } // check the state of each of the device values // create the discovery topic if if hasn't already been created, not a command (like reset) and is active and visible @@ -2109,6 +2098,18 @@ void EMSdevice::mqtt_ha_entity_config_create() { bool needs_update = !has_config_created || (haclimate_value == 1 ? has_climate_no_rt : !has_climate_no_rt); if (needs_update) { + // if it's a thermostat go fetch the list of modes + if (device_type() == EMSdevice::DeviceType::THERMOSTAT) { + for (auto & dv : devicevalues_) { + // make sure it's a type DeviceValueType::ENUM + if ((dv.type == DeviceValueType::ENUM) && !strcmp(dv.short_name, FL_(mode)[0])) { + // get options + mode_options = dv.options; + break; + } + } + } + bool has_room_temp = (haclimate_value == 1); if (Mqtt::publish_ha_climate_config(dv, has_room_temp, mode_options, false)) { if (has_room_temp) { @@ -2130,9 +2131,12 @@ void EMSdevice::mqtt_ha_entity_config_create() { create_device_config = false; // only create the main config once count++; } + // SRC thermostats mapped to connect/src1/... if (dv.tag >= DeviceValueTAG::TAG_SRC1 && dv.tag <= DeviceValueTAG::TAG_SRC16 && !strcmp(dv.short_name, FL_(selRoomTemp)[0])) { - Mqtt::publish_ha_climate_config(dv, true, mode_options, false); + // add all modes - auto, heat, off, cool + // https://github.com/emsesp/EMS-ESP32/issues/2636 + Mqtt::publish_ha_climate_config(dv, true, nullptr, false); } #ifndef EMSESP_STANDALONE diff --git a/src/core/locale_common.h b/src/core/locale_common.h index 3705a9d6e..71f00e681 100644 --- a/src/core/locale_common.h +++ b/src/core/locale_common.h @@ -55,6 +55,7 @@ MAKE_WORD(ems) MAKE_WORD(devices) MAKE_WORD(shower) MAKE_WORD(mqtt) +MAKE_WORD(gpio) MAKE_WORD(modbus) MAKE_WORD(emsesp) MAKE_WORD(connected) @@ -158,7 +159,7 @@ MAKE_WORD_CUSTOM(deviceid_mandatory, "") MAKE_WORD_CUSTOM(device_type_optional, "[device]") MAKE_WORD_CUSTOM(invalid_log_level, "Invalid log level") MAKE_WORD_CUSTOM(log_level_optional, "[level]") -MAKE_WORD_CUSTOM(show_commands, "[system | users | devices | log | ems | values | mqtt | commands]") +MAKE_WORD_CUSTOM(show_commands, "[system | users | devices | log | ems | values | mqtt | commands | gpio]") MAKE_WORD_CUSTOM(name_mandatory, "") MAKE_WORD_CUSTOM(name_optional, "[name]") MAKE_WORD_CUSTOM(new_password_prompt1, "Enter new password: ") diff --git a/src/core/mqtt.cpp b/src/core/mqtt.cpp index e36b41ee9..b82f2a3e5 100644 --- a/src/core/mqtt.cpp +++ b/src/core/mqtt.cpp @@ -1367,42 +1367,39 @@ bool Mqtt::publish_ha_climate_config(const DeviceValue & dv, const bool has_room // map EMS modes to HA climate modes // EMS modes: auto, manual, heat, off, night, day, nofrost, eco, comfort, cool) // HA supports: auto, off, cool, heat, dry, fan_only - // we map day and manual to heat + bool found_auto = true; + bool found_heat = true; + bool found_off = true; + bool found_cool = true; if (mode_options != nullptr) { // scan through mode_options and add to modes - bool found_auto = false; - bool found_heat = false; - bool found_off = false; - bool found_cool = false; for (uint8_t i = 0; i < Helpers::count_items(mode_options); i++) { const char * mode = mode_options[i][0]; // take EN if (!strcmp(mode, FL_(auto)[0])) { found_auto = true; } else if (!strcmp(mode, FL_(heat)[0]) || !strcmp(mode, FL_(day)[0]) || !strcmp(mode, FL_(manual)[0])) { - found_heat = true; + found_heat = true; // we map day and manual to heat } else if (!strcmp(mode, FL_(off)[0])) { found_off = true; } else if (!strcmp(mode, FL_(cool)[0])) { found_cool = true; - } + } } + } - // only add modes if we found at least one - if (found_auto || found_heat || found_off || found_cool) { - JsonArray modes = doc["modes"].to(); - if (found_auto) { - modes.add("auto"); - } - if (found_heat) { - modes.add("heat"); - } - if (found_off) { - modes.add("off"); - } - if (found_cool) { - modes.add("cool"); - } - } + // only add modes if we found at least one + JsonArray modes = doc["modes"].to(); + if (found_auto) { + modes.add("auto"); + } + if (found_heat) { + modes.add("heat"); + } + if (found_off) { + modes.add("off"); + } + if (found_cool) { + modes.add("cool"); } add_ha_dev_section(doc.as(), devicename, nullptr, nullptr, nullptr, false); // add dev section diff --git a/src/core/system.cpp b/src/core/system.cpp index 5fc3862cd..be231c9cf 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -1015,6 +1015,22 @@ void System::show_users(uuid::console::Shell & shell) { shell.println(); } +// print GPIO available and used pins to console +void System::show_gpio(uuid::console::Shell & shell) { + shell.printfln("GPIO:"); + shell.printf(" In use (%d):", used_gpios_.size()); + for (const auto & gpio : used_gpios_) { + shell.printf(" %d", gpio); + } + shell.println(); + auto available = available_gpios(); + shell.printf(" Available (%d):", available.size()); + for (const auto & gpio : available) { + shell.printf(" %d", gpio); + } + shell.println(); +} + // shell command 'show system' void System::show_system(uuid::console::Shell & shell) { refreshHeapMem(); // refresh free heap and max alloc heap diff --git a/src/core/system.h b/src/core/system.h index 968d404a8..5e6fbd779 100644 --- a/src/core/system.h +++ b/src/core/system.h @@ -300,8 +300,10 @@ class System { } void show_system(uuid::console::Shell & shell); - void wifi_reconnect(); void show_users(uuid::console::Shell & shell); + void show_gpio(uuid::console::Shell & shell); + + void wifi_reconnect(); static std::string languages_string();