Skip to content

Commit

Permalink
feat(discovery): mqtt discovery depends on protocol version
Browse files Browse the repository at this point in the history
  • Loading branch information
tspopp committed Nov 26, 2024
1 parent 7487457 commit 5c10329
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 26 deletions.
2 changes: 1 addition & 1 deletion AquaMQTT/include/Version.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace aquamqtt
{
constexpr char VERSION[] = "v2.0.0";
constexpr char VERSION[] = "v1.5.0";
}
133 changes: 124 additions & 9 deletions AquaMQTT/include/mqtt/MQTTDiscovery.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "MQTTDefinitions.h"
#include "Version.h"
#include "message/MessageConstants.h"

namespace aquamqtt
{
Expand Down Expand Up @@ -159,7 +160,11 @@ static const char* make_unique(char* buffer, uint16_t identifier, const char* st
return buffer;
}

static bool buildConfiguration(uint8_t* buffer, uint16_t identifier, MQTT_ITEM_SENSOR item)
static bool buildConfiguration(
uint8_t* buffer,
aquamqtt::message::ProtocolVersion protocolVersion,
uint16_t identifier,
MQTT_ITEM_SENSOR item)
{
JsonDocument doc = createFromDefault(identifier);
char temp[100];
Expand Down Expand Up @@ -198,7 +203,10 @@ static bool buildConfiguration(uint8_t* buffer, uint16_t identifier, MQTT_ITEM_S
doc["uniq_id"] = make_unique(temp, identifier, "main_evoAirTempLower");
break;
case MQTT_ITEM_SENSOR::MAIN_COMPRESSOR_OUTLET_TEMP:
// FIXME: only if new protocol is detected
if (protocolVersion == aquamqtt::message::ProtocolVersion::PROTOCOL_LEGACY)
{
return false;
}
doc["name"] = "Compressor Outlet Temp";
doc["stat_t"] = "~/main/compressorOutletTemp";
doc["stat_cla"] = "measurement";
Expand Down Expand Up @@ -238,12 +246,20 @@ static bool buildConfiguration(uint8_t* buffer, uint16_t identifier, MQTT_ITEM_S
doc["ent_cat"] = "diagnostic";
break;
case MQTT_ITEM_SENSOR::MAIN_ERROR_CODE:
if (protocolVersion == aquamqtt::message::ProtocolVersion::PROTOCOL_NEXT)
{
return false;
}
doc["name"] = "Error Code";
doc["stat_t"] = "~/main/errorCode";
doc["ic"] = "mdi:alarm-light";
doc["uniq_id"] = make_unique(temp, identifier, "main_error_code");
break;
case MQTT_ITEM_SENSOR::ENERGY_TOTAL_HEATING_ELEM_HOURS:
if (protocolVersion == aquamqtt::message::ProtocolVersion::PROTOCOL_NEXT)
{
return false;
}
doc["name"] = "Total Heating Element Hours";
doc["stat_t"] = "~/energy/totalHeatingElemHours";
doc["unit_of_meas"] = "h";
Expand All @@ -268,6 +284,10 @@ static bool buildConfiguration(uint8_t* buffer, uint16_t identifier, MQTT_ITEM_S
doc["uniq_id"] = make_unique(temp, identifier, "energy_total_h");
break;
case MQTT_ITEM_SENSOR::ENERGY_TOTAL_ENERGY_WH:
if (protocolVersion == aquamqtt::message::ProtocolVersion::PROTOCOL_NEXT)
{
return false;
}
doc["name"] = "Total Energy";
doc["stat_t"] = "~/energy/totalEnergyWh";
doc["unit_of_meas"] = "Wh";
Expand All @@ -277,6 +297,10 @@ static bool buildConfiguration(uint8_t* buffer, uint16_t identifier, MQTT_ITEM_S
doc["dev_cla"] = "energy";
break;
case MQTT_ITEM_SENSOR::ENERGY_POWER_TOTAL:
if (protocolVersion == aquamqtt::message::ProtocolVersion::PROTOCOL_NEXT)
{
return false;
}
doc["name"] = "Power Consumed Total";
doc["stat_t"] = "~/energy/powerTotal";
doc["unit_of_meas"] = "W";
Expand All @@ -286,6 +310,10 @@ static bool buildConfiguration(uint8_t* buffer, uint16_t identifier, MQTT_ITEM_S
doc["dev_cla"] = "power";
break;
case MQTT_ITEM_SENSOR::ENERGY_POWER_HEAT_ELEMENT:
if (protocolVersion == aquamqtt::message::ProtocolVersion::PROTOCOL_NEXT)
{
return false;
}
doc["name"] = "Power Consumed Heating Element";
doc["stat_t"] = "~/energy/powerHeatingElem";
doc["unit_of_meas"] = "W";
Expand All @@ -304,6 +332,10 @@ static bool buildConfiguration(uint8_t* buffer, uint16_t identifier, MQTT_ITEM_S
doc["dev_cla"] = "power";
break;
case MQTT_ITEM_SENSOR::ENERGY_TOTAL_WATER_PRODUCTION:
if (protocolVersion == aquamqtt::message::ProtocolVersion::PROTOCOL_NEXT)
{
return false;
}
doc["name"] = "Total Water Production";
doc["stat_t"] = "~/energy/totalWaterProduction";
doc["unit_of_meas"] = "l";
Expand Down Expand Up @@ -506,6 +538,10 @@ static bool buildConfiguration(uint8_t* buffer, uint16_t identifier, MQTT_ITEM_S
doc["ic"] = "mdi:calendar-clock";
break;
case MQTT_ITEM_SENSOR::HMI_SETUP_STATE:
if (protocolVersion == aquamqtt::message::ProtocolVersion::PROTOCOL_NEXT)
{
return false;
}
doc["name"] = "Setup State";
doc["stat_t"] = "~/hmi/setupState";
doc["uniq_id"] = make_unique(temp, identifier, "hmi_setup");
Expand All @@ -528,61 +564,97 @@ static bool buildConfiguration(uint8_t* buffer, uint16_t identifier, MQTT_ITEM_S
doc["ent_cat"] = "diagnostic";
break;
case MQTT_ITEM_SENSOR::MAIN_SETTING_PWM_01:
if (protocolVersion == aquamqtt::message::ProtocolVersion::PROTOCOL_NEXT)
{
return false;
}
doc["name"] = "PWM Fan Level 1 ";
doc["stat_t"] = "~/main/settingPWM_1";
doc["uniq_id"] = make_unique(temp, identifier, "main_setting_fan1");
doc["unit_of_meas"] = "%";
doc["ic"] = "mdi:fan-speed-1";
break;
case MQTT_ITEM_SENSOR::MAIN_SETTING_PWM_02:
if (protocolVersion == aquamqtt::message::ProtocolVersion::PROTOCOL_NEXT)
{
return false;
}
doc["name"] = "PWM Fan Level 2 ";
doc["stat_t"] = "~/main/settingPWM_2";
doc["uniq_id"] = make_unique(temp, identifier, "main_setting_fan2");
doc["unit_of_meas"] = "%";
doc["ic"] = "mdi:fan-speed-2";
break;
case MQTT_ITEM_SENSOR::MAIN_SETTING_PWM_03:
if (protocolVersion == aquamqtt::message::ProtocolVersion::PROTOCOL_NEXT)
{
return false;
}
doc["name"] = "PWM Fan Level 3 ";
doc["stat_t"] = "~/main/settingPWM_3";
doc["uniq_id"] = make_unique(temp, identifier, "main_setting_fan3");
doc["unit_of_meas"] = "%";
doc["ic"] = "mdi:fan-speed-3";
break;
case MQTT_ITEM_SENSOR::MAIN_SETTING_MIN_TEMP_TARGET:
if (protocolVersion == aquamqtt::message::ProtocolVersion::PROTOCOL_NEXT)
{
return false;
}
doc["name"] = "Minimum Water Target Temperature";
doc["stat_t"] = "~/main/settingMinTargetTemp";
doc["uniq_id"] = make_unique(temp, identifier, "main_setting_min_target_temp");
doc["unit_of_meas"] = "°C";
doc["ic"] = "mdi:thermometer-chevron-down";
break;
case MQTT_ITEM_SENSOR::MAIN_SETTING_MIN_TEMP_LEGIONELLA:
if (protocolVersion == aquamqtt::message::ProtocolVersion::PROTOCOL_NEXT)
{
return false;
}
doc["name"] = "Minimum Water Temperature Anti-Legionella";
doc["stat_t"] = "~/main/settingMinLegionellaTemp";
doc["uniq_id"] = make_unique(temp, identifier, "main_setting_min_target_legionella_temp");
doc["unit_of_meas"] = "°C";
doc["ic"] = "mdi:thermometer-plus";
break;
case MQTT_ITEM_SENSOR::MAIN_SETTING_PWR_HEATELEM:
if (protocolVersion == aquamqtt::message::ProtocolVersion::PROTOCOL_NEXT)
{
return false;
}
doc["name"] = "Wattage Installed Heat Element";
doc["stat_t"] = "~/main/settingWattageElement";
doc["uniq_id"] = make_unique(temp, identifier, "main_setting_wattage_he");
doc["unit_of_meas"] = "W";
doc["ic"] = "mdi:heating-coil";
break;
case MQTT_ITEM_SENSOR::MAIN_SETTING_BOILER_CAP:
if (protocolVersion == aquamqtt::message::ProtocolVersion::PROTOCOL_NEXT)
{
return false;
}
doc["name"] = "Boiler Capacity";
doc["stat_t"] = "~/main/settingBoilerCapacity";
doc["uniq_id"] = make_unique(temp, identifier, "main_setting_cap");
doc["unit_of_meas"] = "l";
doc["ic"] = "mdi:barrel";
break;
case MQTT_ITEM_SENSOR::MAIN_SETTING_BOILER_BRAND:
if (protocolVersion == aquamqtt::message::ProtocolVersion::PROTOCOL_NEXT)
{
return false;
}
doc["name"] = "Boiler Brand";
doc["stat_t"] = "~/main/settingBoilerBrand";
doc["uniq_id"] = make_unique(temp, identifier, "main_setting_brand");
doc["ic"] = "mdi:factory";
break;
case MQTT_ITEM_SENSOR::HMI_TEST_MODE:
if (protocolVersion == aquamqtt::message::ProtocolVersion::PROTOCOL_NEXT)
{
return false;
}
doc["name"] = "Test Mode Status";
doc["stat_t"] = "~/hmi/testModeStatus";
doc["uniq_id"] = make_unique(temp, identifier, "hmi_test_mode");
Expand All @@ -596,14 +668,17 @@ static bool buildConfiguration(uint8_t* buffer, uint16_t identifier, MQTT_ITEM_S
case MQTT_ITEM_SENSOR::RESERVED_COUNT:
default:
return false;

}

serializeJson(doc, buffer, config::MQTT_MAX_PAYLOAD_SIZE);
return true;
}

static bool buildConfiguration(uint8_t* buffer, uint16_t identifier, MQTT_ITEM_BINARY_SENSOR item)
static bool buildConfiguration(
uint8_t* buffer,
aquamqtt::message::ProtocolVersion protocolVersion,
uint16_t identifier,
MQTT_ITEM_BINARY_SENSOR item)
{
JsonDocument doc = createFromDefault(identifier);
char temp[100];
Expand Down Expand Up @@ -776,6 +851,10 @@ static bool buildConfiguration(uint8_t* buffer, uint16_t identifier, MQTT_ITEM_B
doc["ent_cat"] = "diagnostic";
break;
case MQTT_ITEM_BINARY_SENSOR::MAIN_CAPABILITY_HEAT_EXC:
if (protocolVersion == aquamqtt::message::ProtocolVersion::PROTOCOL_NEXT)
{
return false;
}
doc["name"] = "Capability Heat-Exchanger";
doc["stat_t"] = "~/main/capabilityHeatExchanger";
doc["ic"] = "mdi:expansion-card";
Expand All @@ -785,6 +864,10 @@ static bool buildConfiguration(uint8_t* buffer, uint16_t identifier, MQTT_ITEM_B
doc["ent_cat"] = "diagnostic";
break;
case MQTT_ITEM_BINARY_SENSOR::MAIN_CAPABILITY_CIRCULATION:
if (protocolVersion == aquamqtt::message::ProtocolVersion::PROTOCOL_NEXT)
{
return false;
}
doc["name"] = "Capability Circulation";
doc["stat_t"] = "~/main/capabilityCirculation";
doc["ic"] = "mdi:expansion-card";
Expand All @@ -794,6 +877,10 @@ static bool buildConfiguration(uint8_t* buffer, uint16_t identifier, MQTT_ITEM_B
doc["ent_cat"] = "diagnostic";
break;
case MQTT_ITEM_BINARY_SENSOR::MAIN_CAPABILITY_PV_INPUT:
if (protocolVersion == aquamqtt::message::ProtocolVersion::PROTOCOL_NEXT)
{
return false;
}
doc["name"] = "Capability PV Input";
doc["stat_t"] = "~/main/capabilityPVInput";
doc["ic"] = "mdi:expansion-card";
Expand All @@ -803,6 +890,10 @@ static bool buildConfiguration(uint8_t* buffer, uint16_t identifier, MQTT_ITEM_B
doc["ent_cat"] = "diagnostic";
break;
case MQTT_ITEM_BINARY_SENSOR::MAIN_CAPABILITY_EXT_COMM:
if (protocolVersion == aquamqtt::message::ProtocolVersion::PROTOCOL_NEXT)
{
return false;
}
doc["name"] = "Capability External Communication";
doc["stat_t"] = "~/main/capabilityCommunication";
doc["ic"] = "mdi:expansion-card";
Expand All @@ -812,6 +903,10 @@ static bool buildConfiguration(uint8_t* buffer, uint16_t identifier, MQTT_ITEM_B
doc["ent_cat"] = "diagnostic";
break;
case MQTT_ITEM_BINARY_SENSOR::MAIN_CAPABILITY_DRY_HEATING:
if (protocolVersion == aquamqtt::message::ProtocolVersion::PROTOCOL_NEXT)
{
return false;
}
doc["name"] = "Capability Anti Dry Heating";
doc["stat_t"] = "~/main/capabilityCommunication";
doc["ic"] = "mdi:expansion-card";
Expand All @@ -829,7 +924,11 @@ static bool buildConfiguration(uint8_t* buffer, uint16_t identifier, MQTT_ITEM_B
return true;
}

static bool buildConfiguration(uint8_t* buffer, uint16_t identifier, MQTT_ITEM_NUMBER item)
static bool buildConfiguration(
uint8_t* buffer,
aquamqtt::message::ProtocolVersion protocolVersion,
uint16_t identifier,
MQTT_ITEM_NUMBER item)
{
JsonDocument doc = createFromDefault(identifier);
char temp[100];
Expand All @@ -856,7 +955,11 @@ static bool buildConfiguration(uint8_t* buffer, uint16_t identifier, MQTT_ITEM_N
return true;
}

static bool buildConfiguration(uint8_t* buffer, uint16_t identifier, MQTT_ITEM_BUTTON item)
static bool buildConfiguration(
uint8_t* buffer,
aquamqtt::message::ProtocolVersion protocolVersion,
uint16_t identifier,
MQTT_ITEM_BUTTON item)
{
JsonDocument doc = createFromDefault(identifier);
char temp[100];
Expand All @@ -879,7 +982,11 @@ static bool buildConfiguration(uint8_t* buffer, uint16_t identifier, MQTT_ITEM_B
return true;
}

static bool buildConfiguration(uint8_t* buffer, uint16_t identifier, MQTT_ITEM_SELECT item)
static bool buildConfiguration(
uint8_t* buffer,
aquamqtt::message::ProtocolVersion protocolVersion,
uint16_t identifier,
MQTT_ITEM_SELECT item)
{
JsonDocument doc = createFromDefault(identifier);
char temp[100];
Expand Down Expand Up @@ -953,7 +1060,11 @@ static bool buildConfiguration(uint8_t* buffer, uint16_t identifier, MQTT_ITEM_S
return true;
}

static bool buildConfiguration(uint8_t* buffer, uint16_t identifier, MQTT_ITEM_SWITCH item)
static bool buildConfiguration(
uint8_t* buffer,
aquamqtt::message::ProtocolVersion protocolVersion,
uint16_t identifier,
MQTT_ITEM_SWITCH item)
{
JsonDocument doc = createFromDefault(identifier);
char temp[100];
Expand Down Expand Up @@ -1007,7 +1118,11 @@ static bool buildConfiguration(uint8_t* buffer, uint16_t identifier, MQTT_ITEM_S
return true;
}

static bool buildConfiguration(uint8_t* buffer, uint16_t identifier, MQTT_ITEM_WATER_HEATER item)
static bool buildConfiguration(
uint8_t* buffer,
aquamqtt::message::ProtocolVersion protocolVersion,
uint16_t identifier,
MQTT_ITEM_WATER_HEATER item)
{
JsonDocument doc = createFromDefault(identifier);
char temp[100];
Expand Down
Loading

0 comments on commit 5c10329

Please sign in to comment.