mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2026-03-14 05:36:34 +03:00
HA climate mode and icon check
This commit is contained in:
@@ -2108,7 +2108,6 @@ bool EMSdevice::generate_values(JsonObject output, const int8_t tag_filter, cons
|
||||
void EMSdevice::mqtt_ha_entity_config_create() {
|
||||
bool create_device_config = !ha_config_done(); // do we need to create the main Discovery device config with this entity?
|
||||
uint16_t count = 0;
|
||||
const char * const ** mode_options = nullptr;
|
||||
|
||||
// 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
|
||||
@@ -2121,17 +2120,15 @@ 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])) {
|
||||
const char * const ** mode_options = nullptr;
|
||||
for (auto & d : devicevalues_) {
|
||||
// make sure mode in same circuit is DeviceValueType::ENUM
|
||||
if ((d.tag == dv.tag) && (d.type == DeviceValueType::ENUM) && !strcmp(d.short_name, FL_(mode)[0]) && (d.options_size > 0)) {
|
||||
// get options
|
||||
mode_options = dv.options;
|
||||
mode_options = d.options;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool has_room_temp = (haclimate_value == 1);
|
||||
if (Mqtt::publish_ha_climate_config(dv, has_room_temp, mode_options, false)) {
|
||||
@@ -2155,21 +2152,22 @@ void EMSdevice::mqtt_ha_entity_config_create() {
|
||||
count++;
|
||||
}
|
||||
|
||||
// SRC thermostats mapped to connect/src1/...
|
||||
/* removed climate for testing
|
||||
if (dv.tag >= DeviceValueTAG::TAG_SRC1 && dv.tag <= DeviceValueTAG::TAG_SRC16 && !strcmp(dv.short_name, FL_(selRoomTemp)[0])) {
|
||||
// SRC thermostats mapped to connect/src1/... always contains mode, seltemp, currtemp
|
||||
if (dv.tag >= DeviceValueTAG::TAG_SRC1 && dv.tag <= DeviceValueTAG::TAG_SRC16 && !strcmp(dv.short_name, FL_(mode)[0])) {
|
||||
// add icon if we have one
|
||||
const char * icon = nullptr;
|
||||
for (auto & d : devicevalues_) {
|
||||
if (d.tag == dv.tag && !strcmp(d.short_name, FL_(icon)[0]) && *(uint8_t *)d.value_p != 0) {
|
||||
icon = d.options[*(uint8_t *)d.value_p][0];
|
||||
if (d.tag == dv.tag && !strcmp(d.short_name, FL_(icon)[0]) && (dv.type == DeviceValueType::ENUM)) {
|
||||
uint8_t val = *(uint8_t *)(d.value_p);
|
||||
if (val != 0 && val < d.options_size) {
|
||||
icon = d.options[val][0];
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
// add all modes - auto, heat, off, cool
|
||||
// https://github.com/emsesp/EMS-ESP32/issues/2636
|
||||
Mqtt::publish_ha_climate_config(dv, true, nullptr, false, icon);
|
||||
Mqtt::publish_ha_climate_config(dv, true, dv.options, false, icon);
|
||||
count++;
|
||||
}
|
||||
*/
|
||||
|
||||
#ifndef EMSESP_STANDALONE
|
||||
// always create minimum one config
|
||||
|
||||
@@ -476,7 +476,8 @@ void Thermostat::add_ha_climate(std::shared_ptr<HeatingCircuit> hc) const {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Helpers::hasValue(hc->selTemp) && is_readable(&hc->selTemp)) {
|
||||
// create climate only if we have modes
|
||||
if (Helpers::hasValue(hc->mode) && Helpers::hasValue(hc->selTemp) && is_readable(&hc->selTemp)) {
|
||||
if (Helpers::hasValue(hc->roomTemp) && is_readable(&hc->roomTemp)) {
|
||||
hc->climate = 1; // use roomTemp as we have a sensor
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user