Merge branch 'emsesp:dev' into dev

This commit is contained in:
Proddy
2022-02-12 17:38:38 +01:00
committed by GitHub
8 changed files with 164 additions and 152 deletions

View File

@@ -96,8 +96,15 @@ Boiler::Boiler(uint8_t device_type, int8_t device_id, uint8_t product_id, const
register_device_value(DeviceValueTAG::TAG_BOILER_DATA, &tapwaterActive_, DeviceValueType::BOOL, nullptr, FL_(tapwaterActive), DeviceValueUOM::NONE);
register_device_value(
DeviceValueTAG::TAG_BOILER_DATA, &selFlowTemp_, DeviceValueType::UINT, nullptr, FL_(selFlowTemp), DeviceValueUOM::DEGREES, MAKE_CF_CB(set_flow_temp));
register_device_value(
DeviceValueTAG::TAG_BOILER_DATA, &selBurnPow_, DeviceValueType::UINT, nullptr, FL_(selBurnPow), DeviceValueUOM::PERCENT, MAKE_CF_CB(set_burn_power));
register_device_value(DeviceValueTAG::TAG_BOILER_DATA,
&selBurnPow_,
DeviceValueType::UINT,
nullptr,
FL_(selBurnPow),
DeviceValueUOM::PERCENT,
MAKE_CF_CB(set_burn_power),
0,
130);
register_device_value(DeviceValueTAG::TAG_BOILER_DATA, &heatingPumpMod_, DeviceValueType::UINT, nullptr, FL_(heatingPumpMod), DeviceValueUOM::PERCENT);
register_device_value(DeviceValueTAG::TAG_BOILER_DATA, &heatingPump2Mod_, DeviceValueType::UINT, nullptr, FL_(heatingPump2Mod), DeviceValueUOM::PERCENT);
register_device_value(DeviceValueTAG::TAG_BOILER_DATA, &outdoorTemp_, DeviceValueType::SHORT, FL_(div10), FL_(outdoorTemp), DeviceValueUOM::DEGREES);

View File

@@ -93,7 +93,7 @@ class Boiler : public EMSdevice {
uint8_t heatingActive_; // Central heating is on/off
uint8_t tapwaterActive_; // Hot tap water is on/off
uint8_t selFlowTemp_; // Selected flow temperature
uint8_t selBurnPow_; // Burner max power %
uint8_t selBurnPow_; // Burner max power % (can be > 100%)
uint8_t heatingPump2Mod_; // heatpump modulation from 0xE3 (heatpumps)
uint8_t heatingPumpMod_; // Pump modulation %
int16_t outdoorTemp_; // Outside temperature

View File

@@ -552,11 +552,10 @@ void EMSESP::reset_mqtt_ha() {
// this will also create the HA /config topic
// generate_values_json is called to build the device value (dv) object array
void EMSESP::publish_device_values(uint8_t device_type) {
DynamicJsonDocument doc(EMSESP_JSON_SIZE_XLARGE_DYN); // use max size
JsonObject json = doc.to<JsonObject>();
DynamicJsonDocument doc(EMSESP_JSON_SIZE_XLARGE_DYN);
JsonObject json;
bool need_publish = false;
bool nested = (Mqtt::is_nested());
bool nested = (Mqtt::is_nested());
// group by device type
for (const auto & emsdevice : emsdevices) {
@@ -572,10 +571,11 @@ void EMSESP::publish_device_values(uint8_t device_type) {
// if its a boiler, generate json for each group and publish it directly. not nested
if (device_type == DeviceType::BOILER) {
json = doc.to<JsonObject>();
if (emsdevice->generate_values(json, DeviceValueTAG::TAG_BOILER_DATA, false, EMSdevice::OUTPUT_TARGET::MQTT)) {
Mqtt::publish(Mqtt::tag_to_topic(device_type, DeviceValueTAG::TAG_BOILER_DATA), json);
}
doc.clear();
json = doc.to<JsonObject>();
if (emsdevice->generate_values(json, DeviceValueTAG::TAG_DEVICE_DATA_WW, false, EMSdevice::OUTPUT_TARGET::MQTT)) {
Mqtt::publish(Mqtt::tag_to_topic(device_type, DeviceValueTAG::TAG_DEVICE_DATA_WW), json);
}
@@ -587,39 +587,42 @@ void EMSESP::publish_device_values(uint8_t device_type) {
// only publish the single master thermostat
if (emsdevice->device_id() == EMSESP::actual_master_thermostat()) {
if (nested) {
json = doc.to<JsonObject>();
need_publish |= emsdevice->generate_values(json, DeviceValueTAG::TAG_NONE, true, EMSdevice::OUTPUT_TARGET::MQTT); // nested
} else {
json = doc.to<JsonObject>();
if (emsdevice->generate_values(json, DeviceValueTAG::TAG_THERMOSTAT_DATA, false, EMSdevice::OUTPUT_TARGET::MQTT)) { // not nested
Mqtt::publish(Mqtt::tag_to_topic(device_type, DeviceValueTAG::TAG_NONE), json);
}
doc.clear();
for (uint8_t hc_tag = DeviceValueTAG::TAG_HC1; hc_tag <= DeviceValueTAG::TAG_HC8; hc_tag++) {
json = doc.to<JsonObject>();
if (emsdevice->generate_values(json, hc_tag, false, EMSdevice::OUTPUT_TARGET::MQTT)) { // not nested
Mqtt::publish(Mqtt::tag_to_topic(device_type, hc_tag), json);
}
doc.clear();
}
need_publish = false;
}
need_publish = false;
}
}
// Mixer
else if (device_type == DeviceType::MIXER) {
if (nested) {
json = doc.to<JsonObject>();
need_publish |= emsdevice->generate_values(json, DeviceValueTAG::TAG_NONE, true, EMSdevice::OUTPUT_TARGET::MQTT); // nested
} else {
for (uint8_t hc_tag = DeviceValueTAG::TAG_HC1; hc_tag <= DeviceValueTAG::TAG_WWC4; hc_tag++) {
json = doc.to<JsonObject>();
if (emsdevice->generate_values(json, hc_tag, false, EMSdevice::OUTPUT_TARGET::MQTT)) { // not nested
Mqtt::publish(Mqtt::tag_to_topic(device_type, hc_tag), json);
}
doc.clear();
}
need_publish = false;
}
} else {
// for all other devices add the values to the json
json = doc.to<JsonObject>();
need_publish |= emsdevice->generate_values(json, DeviceValueTAG::TAG_NONE, true, EMSdevice::OUTPUT_TARGET::MQTT); // nested
}
}

View File

@@ -183,27 +183,23 @@ class Mqtt {
static uint8_t nested_format() {
return nested_format_;
}
static bool is_nested() {
return nested_format_ == 1;
}
static void nested_format(uint8_t nested_format) {
nested_format_ = nested_format;
}
static bool publish_single() {
return publish_single_;
}
static void publish_single(bool publish_single) {
publish_single_ = publish_single;
}
static void nested_format(uint8_t nested_format) {
nested_format_ = nested_format;
}
static bool ha_enabled() {
return ha_enabled_;
}
static void ha_enabled(bool ha_enabled) {
ha_enabled_ = ha_enabled;
}
@@ -211,7 +207,6 @@ class Mqtt {
static bool send_response() {
return send_response_;
}
static void send_response(bool send_response) {
send_response_ = send_response;
}

View File

@@ -173,8 +173,6 @@ bool Test::run_test(const char * command, int8_t id) {
if (strcmp(command, "thermostat") == 0) {
EMSESP::logger().info(F("Adding thermostat..."));
Mqtt::nested_format(1); // use nested
// Mqtt::nested_format(2); // single
add_device(0x10, 192); // FW120
@@ -498,17 +496,19 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const
if (command == "ha") {
shell.printfln(F("Testing HA mqtt discovery"));
Mqtt::ha_enabled(true);
// Mqtt::nested_format(1);
Mqtt::nested_format(2);
// Mqtt::ha_enabled(true);
Mqtt::ha_enabled(false);
run_test("boiler");
// Mqtt::nested_format(1); // is nested
Mqtt::nested_format(2); // not nested
// run_test("boiler");
run_test("thermostat");
// run_test("solar");
// run_test("mixer");
shell.invoke_command("call system publish");
shell.invoke_command("show mqtt");
// shell.invoke_command("show mqtt");
// shell.invoke_command("call boiler fanwork");
// shell.invoke_command("call thermostat seltemp"); // sensor.thermostat_hc1_selected_room_temperature