Skip to content

Commit

Permalink
feat(protocol-next): full support of E/E protocol (next)
Browse files Browse the repository at this point in the history
  • Loading branch information
tspopp committed Dec 4, 2024
1 parent 2c17120 commit 2cbcb17
Show file tree
Hide file tree
Showing 13 changed files with 569 additions and 250 deletions.
17 changes: 17 additions & 0 deletions AquaMQTT/include/message/IEnergyMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@
namespace aquamqtt::message
{

enum class ENERGY_ATTR_I8
{
DIAG_AIR_TEMP_MAX,
DIAG_AIR_TEMP_MIN,
DIAG_EVA_UPPER_AIR_TEMP_MAX,
DIAG_EVA_UPPER_AIR_TEMP_MIN,
DIAG_EVA_LOWER_AIR_TEMP_MAX,
DIAG_EVA_LOWER_AIR_TEMP_MIN,
DIAG_COMPRESSOR_TEMP_MAX,
DIAG_COMPRESSOR_TEMP_MIN,
DIAG_WATER_TEMP_MAX,
DIAG_WATER_TEMP_MIN
};

enum class ENERGY_ATTR_U16
{
POWER_HEATPUMP,
Expand Down Expand Up @@ -36,14 +50,17 @@ class IEnergyMessage
virtual uint64_t getAttr(ENERGY_ATTR_U64 attr) = 0;
virtual uint32_t getAttr(ENERGY_ATTR_U32 attr) = 0;
virtual uint16_t getAttr(ENERGY_ATTR_U16 attr) = 0;
virtual int8_t getAttr(ENERGY_ATTR_I8 attr) = 0;

virtual bool hasAttr(ENERGY_ATTR_U64 attr) const = 0;
virtual bool hasAttr(ENERGY_ATTR_U32 attr) const = 0;
virtual bool hasAttr(ENERGY_ATTR_U16 attr) const = 0;
virtual bool hasAttr(ENERGY_ATTR_I8 attr) const = 0;

virtual bool hasChanged(ENERGY_ATTR_U64 attr) const = 0;
virtual bool hasChanged(ENERGY_ATTR_U32 attr) const = 0;
virtual bool hasChanged(ENERGY_ATTR_U16 attr) const = 0;
virtual bool hasChanged(ENERGY_ATTR_I8 attr) const = 0;
};
} // namespace aquamqtt::message

Expand Down
3 changes: 3 additions & 0 deletions AquaMQTT/include/message/legacy/MainEnergyMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ class MainEnergyMessage : public IEnergyMessage
uint64_t getAttr(ENERGY_ATTR_U64 attr) override;
uint32_t getAttr(ENERGY_ATTR_U32 attr) override;
uint16_t getAttr(ENERGY_ATTR_U16 attr) override;
int8_t getAttr(ENERGY_ATTR_I8 attr) override;

bool hasAttr(ENERGY_ATTR_U64 attr) const override;
bool hasAttr(ENERGY_ATTR_U32 attr) const override;
bool hasAttr(ENERGY_ATTR_U16 attr) const override;
bool hasAttr(ENERGY_ATTR_I8 attr) const override;

bool hasChanged(ENERGY_ATTR_U64 attr) const override;
bool hasChanged(ENERGY_ATTR_U32 attr) const override;
bool hasChanged(ENERGY_ATTR_U16 attr) const override;
bool hasChanged(ENERGY_ATTR_I8 attr) const override;

private:
void compareWith(uint8_t* data);
Expand Down
5 changes: 5 additions & 0 deletions AquaMQTT/include/message/next/MainEnergyMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ class MainEnergyMessage : public IEnergyMessage
uint64_t getAttr(ENERGY_ATTR_U64 attr) override;
uint32_t getAttr(ENERGY_ATTR_U32 attr) override;
uint16_t getAttr(ENERGY_ATTR_U16 attr) override;
int8_t getAttr(ENERGY_ATTR_I8 attr) override;

bool hasAttr(ENERGY_ATTR_U64 attr) const override;
bool hasAttr(ENERGY_ATTR_U32 attr) const override;
bool hasAttr(ENERGY_ATTR_U16 attr) const override;
bool hasAttr(ENERGY_ATTR_I8 attr) const override;

bool hasChanged(ENERGY_ATTR_U64 attr) const override;
bool hasChanged(ENERGY_ATTR_U32 attr) const override;
bool hasChanged(ENERGY_ATTR_U16 attr) const override;
bool hasChanged(ENERGY_ATTR_I8 attr) const override;

private:
void compareWith(uint8_t* data);
Expand All @@ -38,6 +41,8 @@ class MainEnergyMessage : public IEnergyMessage
std::set<ENERGY_ATTR_U16> mHasChangedU16;
std::set<ENERGY_ATTR_U32> mHasChangedU32;
std::set<ENERGY_ATTR_U64> mHasChangedU64;
std::set<ENERGY_ATTR_I8> mHasChangedI8;

};

} // namespace aquamqtt::message::next
Expand Down
11 changes: 11 additions & 0 deletions AquaMQTT/include/mqtt/MQTTDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,17 @@ constexpr char ENERGY_POWER_HEAT_ELEMENT[] = { "powerHeatingElem" };
constexpr char ENERGY_POWER_HEATPUMP[] = { "powerHeatpump" };
constexpr char ENERGY_TOTAL_WATER_PRODUCTION[] = { "totalWaterProduction" };

constexpr char ENERGY_DIAG_AIR_TEMP_MAX[] = { "diagAirTempMax" };
constexpr char ENERGY_DIAG_AIR_TEMP_MIN[] = { "diagAirTempMin" };
constexpr char ENERGY_DIAG_EVA_UPPER_AIR_TEMP_MAX[] = { "diagEvaUpperMax" };
constexpr char ENERGY_DIAG_EVA_UPPER_AIR_TEMP_MIN[] = { "diagEvaUpperMin" };
constexpr char ENERGY_DIAG_EVA_LOWER_AIR_TEMP_MAX[] = { "diagEvaLowerMax" };
constexpr char ENERGY_DIAG_EVA_LOWER_AIR_TEMP_MIN[] = { "diagEvaLowerMin" };
constexpr char ENERGY_DIAG_COMPRESSOR_TEMP_MAX[] = { "diagCompressorMax" };
constexpr char ENERGY_DIAG_COMPRESSOR_TEMP_MIN[] = { "diagCompressorMin" };
constexpr char ENERGY_DIAG_WATER_TEMP_MAX[] = { "diagWaterTempMax" };
constexpr char ENERGY_DIAG_WATER_TEMP_MIN[] = { "diagWaterTempMin" };

constexpr char ERROR_ERROR_NUMBER[] = { "errorNumber" };

constexpr char STATS_AQUAMQTT_ADDR[] = { "ipAddress" };
Expand Down
144 changes: 130 additions & 14 deletions AquaMQTT/include/mqtt/MQTTDiscovery.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ enum class MQTT_ITEM_SENSOR
STATS_MAIN_MSG_CRC_NOK,
STATS_MAIN_DROPPED_BYTES,
MAIN_COMPRESSOR_OUTLET_TEMP,
ENERGY_DIAG_AIR_TEMP_MAX,
ENERGY_DIAG_AIR_TEMP_MIN,
ENERGY_DIAG_EVA_UPPER_AIR_TEMP_MAX,
ENERGY_DIAG_EVA_UPPER_AIR_TEMP_MIN,
ENERGY_DIAG_EVA_LOWER_AIR_TEMP_MAX,
ENERGY_DIAG_EVA_LOWER_AIR_TEMP_MIN,
ENERGY_DIAG_COMPRESSOR_TEMP_MAX,
ENERGY_DIAG_COMPRESSOR_TEMP_MIN,
ENERGY_DIAG_WATER_TEMP_MAX,
ENERGY_DIAG_WATER_TEMP_MIN,
RESERVED_COUNT
};

Expand Down Expand Up @@ -256,10 +266,6 @@ static bool buildConfiguration(
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 @@ -276,6 +282,10 @@ static bool buildConfiguration(
doc["uniq_id"] = make_unique(temp, identifier, "energy_total_hp_h");
break;
case MQTT_ITEM_SENSOR::ENERGY_TOTAL_HOURS:
if (protocolVersion == aquamqtt::message::ProtocolVersion::PROTOCOL_NEXT)
{
return false;
}
doc["name"] = "Total Hours";
doc["stat_t"] = "~/energy/totalHours";
doc["unit_of_meas"] = "h";
Expand All @@ -284,23 +294,15 @@ static bool buildConfiguration(
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";
doc["stat_cla"] = "total";
doc["stat_cla"] = "total_increasing";
doc["ic"] = "mdi:lightning-bolt-circle";
doc["uniq_id"] = make_unique(temp, identifier, "energy_total_energy");
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 @@ -323,6 +325,10 @@ static bool buildConfiguration(
doc["dev_cla"] = "power";
break;
case MQTT_ITEM_SENSOR::ENERGY_POWER_HEATPUMP:
if (protocolVersion == aquamqtt::message::ProtocolVersion::PROTOCOL_NEXT)
{
return false;
}
doc["name"] = "Power Consumed Heatpump";
doc["stat_t"] = "~/energy/powerHeatpump";
doc["unit_of_meas"] = "W";
Expand Down Expand Up @@ -665,10 +671,120 @@ static bool buildConfiguration(
doc["stat_t"] = "~/hmi/pvInputActivated";
doc["uniq_id"] = make_unique(temp, identifier, "hmi_pv_allowed");
doc["ic"] = "mdi:solar-power-variant";
break;
case MQTT_ITEM_SENSOR::ENERGY_DIAG_AIR_TEMP_MAX:
if (protocolVersion == aquamqtt::message::ProtocolVersion::PROTOCOL_LEGACY)
{
return false;
}
doc["name"] = "Air Temperature Observed Max";
doc["stat_t"] = "~/energy/diagAirTempMax";
doc["ent_cat"] = "diagnostic";
doc["uniq_id"] = make_unique(temp, identifier, "energy_d_at_max");
doc["unit_of_meas"] = "°C";
break;
case MQTT_ITEM_SENSOR::ENERGY_DIAG_AIR_TEMP_MIN:
if (protocolVersion == aquamqtt::message::ProtocolVersion::PROTOCOL_LEGACY)
{
return false;
}
doc["name"] = "Air Temperature Observed Min";
doc["stat_t"] = "~/energy/diagAirTempMin";
doc["ent_cat"] = "diagnostic";
doc["uniq_id"] = make_unique(temp, identifier, "energy_d_at_min");
doc["unit_of_meas"] = "°C";
break;
case MQTT_ITEM_SENSOR::ENERGY_DIAG_EVA_UPPER_AIR_TEMP_MAX:
if (protocolVersion == aquamqtt::message::ProtocolVersion::PROTOCOL_LEGACY)
{
return false;
}
doc["name"] = "Upper Evaporator Temperature Observed Max";
doc["stat_t"] = "~/energy/diagEvaUpperMax";
doc["ent_cat"] = "diagnostic";
doc["uniq_id"] = make_unique(temp, identifier, "energy_d_ue_max");
doc["unit_of_meas"] = "°C";
break;
case MQTT_ITEM_SENSOR::ENERGY_DIAG_EVA_UPPER_AIR_TEMP_MIN:
if (protocolVersion == aquamqtt::message::ProtocolVersion::PROTOCOL_LEGACY)
{
return false;
}
doc["name"] = "Upper Evaporator Temperature Observed Min";
doc["stat_t"] = "~/energy/diagEvaUpperMin";
doc["ent_cat"] = "diagnostic";
doc["uniq_id"] = make_unique(temp, identifier, "energy_d_ue_min");
doc["unit_of_meas"] = "°C";
break;
case MQTT_ITEM_SENSOR::ENERGY_DIAG_EVA_LOWER_AIR_TEMP_MAX:
if (protocolVersion == aquamqtt::message::ProtocolVersion::PROTOCOL_LEGACY)
{
return false;
}
doc["name"] = "Lower Evaporator Temperature Observed Max";
doc["stat_t"] = "~/energy/diagEvaLowerMax";
doc["ent_cat"] = "diagnostic";
doc["uniq_id"] = make_unique(temp, identifier, "energy_d_le_max");
doc["unit_of_meas"] = "°C";
break;
case MQTT_ITEM_SENSOR::ENERGY_DIAG_EVA_LOWER_AIR_TEMP_MIN:
if (protocolVersion == aquamqtt::message::ProtocolVersion::PROTOCOL_LEGACY)
{
return false;
}
doc["name"] = "Lower Evaporator Temperature Observed Min";
doc["stat_t"] = "~/energy/diagEvaLowerMin";
doc["ent_cat"] = "diagnostic";
doc["uniq_id"] = make_unique(temp, identifier, "energy_d_le_min");
doc["unit_of_meas"] = "°C";
break;
case MQTT_ITEM_SENSOR::ENERGY_DIAG_COMPRESSOR_TEMP_MAX:
if (protocolVersion == aquamqtt::message::ProtocolVersion::PROTOCOL_LEGACY)
{
return false;
}
doc["name"] = "Compressor Temperature Observed Max";
doc["stat_t"] = "~/energy/diagCompressorMax";
doc["ent_cat"] = "diagnostic";
doc["uniq_id"] = make_unique(temp, identifier, "energy_d_c_max");
doc["unit_of_meas"] = "°C";
break;
case MQTT_ITEM_SENSOR::ENERGY_DIAG_COMPRESSOR_TEMP_MIN:
if (protocolVersion == aquamqtt::message::ProtocolVersion::PROTOCOL_LEGACY)
{
return false;
}
doc["name"] = "Compressor Temperature Observed Min";
doc["stat_t"] = "~/energy/diagCompressorMin";
doc["ent_cat"] = "diagnostic";
doc["uniq_id"] = make_unique(temp, identifier, "energy_d_c_min");
doc["unit_of_meas"] = "°C";
break;
case MQTT_ITEM_SENSOR::ENERGY_DIAG_WATER_TEMP_MAX:
if (protocolVersion == aquamqtt::message::ProtocolVersion::PROTOCOL_LEGACY)
{
return false;
}
doc["name"] = "Water Temperature Observed Max";
doc["stat_t"] = "~/energy/diagWaterTempMax";
doc["ent_cat"] = "diagnostic";
doc["uniq_id"] = make_unique(temp, identifier, "energy_d_w_max");
doc["unit_of_meas"] = "°C";
break;
case MQTT_ITEM_SENSOR::ENERGY_DIAG_WATER_TEMP_MIN:
if (protocolVersion == aquamqtt::message::ProtocolVersion::PROTOCOL_LEGACY)
{
return false;
}
doc["name"] = "Water Temperature Observed Min";
doc["stat_t"] = "~/energy/diagWaterTempMin";
doc["ent_cat"] = "diagnostic";
doc["uniq_id"] = make_unique(temp, identifier, "energy_d_w_min");
doc["unit_of_meas"] = "°C";
break;
case MQTT_ITEM_SENSOR::RESERVED_COUNT:
default:
return false;

}

serializeJson(doc, buffer, config::MQTT_MAX_PAYLOAD_SIZE);
Expand Down
18 changes: 18 additions & 0 deletions AquaMQTT/src/message/legacy/MainEnergyMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ uint16_t MainEnergyMessage::getAttr(ENERGY_ATTR_U16 attr)
return 0;
}

int8_t MainEnergyMessage::getAttr(ENERGY_ATTR_I8 attr)
{
return 0;
}



bool MainEnergyMessage::hasAttr(ENERGY_ATTR_U64 attr) const
{
switch (attr)
Expand Down Expand Up @@ -168,6 +175,11 @@ bool MainEnergyMessage::hasAttr(ENERGY_ATTR_U16 attr) const
}
}

bool MainEnergyMessage::hasAttr(ENERGY_ATTR_I8 attr) const
{
return false;
}

bool MainEnergyMessage::hasChanged(ENERGY_ATTR_U64 attr) const
{
return mCreatedWithoutPrevious || mHasChangedU64.find(attr) != mHasChangedU64.end();
Expand All @@ -182,4 +194,10 @@ bool MainEnergyMessage::hasChanged(ENERGY_ATTR_U16 attr) const
{
return mCreatedWithoutPrevious || mHasChangedU16.find(attr) != mHasChangedU16.end();
}

bool MainEnergyMessage::hasChanged(ENERGY_ATTR_I8 attr) const
{
return false;
}

} // namespace aquamqtt::message::legacy
Loading

0 comments on commit 2cbcb17

Please sign in to comment.