mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-16 12:49:56 +03:00
Merge pull request #2817 from proddy/dev
SRC for HA climate, "show gpio" command
This commit is contained in:
@@ -100,6 +100,8 @@ static void setup_commands(std::shared_ptr<Commands> 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");
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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, "<deviceID>")
|
||||
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, "<name>")
|
||||
MAKE_WORD_CUSTOM(name_optional, "[name]")
|
||||
MAKE_WORD_CUSTOM(new_password_prompt1, "Enter new password: ")
|
||||
|
||||
@@ -1367,28 +1367,27 @@ 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<JsonArray>();
|
||||
if (found_auto) {
|
||||
modes.add("auto");
|
||||
@@ -1402,8 +1401,6 @@ bool Mqtt::publish_ha_climate_config(const DeviceValue & dv, const bool has_room
|
||||
if (found_cool) {
|
||||
modes.add("cool");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
add_ha_dev_section(doc.as<JsonObject>(), devicename, nullptr, nullptr, nullptr, false); // add dev section
|
||||
add_ha_avty_section(doc.as<JsonObject>(), topic_t, seltemp_cond, has_roomtemp ? currtemp_cond : nullptr, hc_mode_cond); // add availability section
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user