Skip to content

Commit

Permalink
parse(energy): applied latest state of knowledge
Browse files Browse the repository at this point in the history
  • Loading branch information
tspopp committed Nov 30, 2024
1 parent 50eeb90 commit d8cc538
Show file tree
Hide file tree
Showing 3 changed files with 188 additions and 217 deletions.
22 changes: 9 additions & 13 deletions AquaMQTT/include/mqtt/MQTTDiscovery.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,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 +272,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 +284,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 +315,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
62 changes: 40 additions & 22 deletions AquaMQTT/src/message/next/MainEnergyMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,39 +59,57 @@ uint8_t MainEnergyMessage::getLength()
return ENERGY_MESSAGE_LENGTH_NEXT;
}

uint16_t MainEnergyMessage::hack_unknown_value_a(){
uint16_t MainEnergyMessage::hack_unknown_value_a()
{
return ((uint16_t) mData[2] << 8) | (uint16_t) mData[1];
}
uint16_t MainEnergyMessage::hack_unknown_value_b(){

uint16_t MainEnergyMessage::hack_unknown_value_b()
{
return ((uint16_t) mData[4] << 8) | (uint16_t) mData[3];
}
uint32_t MainEnergyMessage::hack_unknown_value_c(){

uint32_t MainEnergyMessage::hack_unknown_value_c()
{
return ((uint32_t) mData[8] << 24) | ((uint32_t) mData[7] << 16) | ((uint32_t) mData[6] << 8)
| (uint32_t) mData[5];
}
uint32_t MainEnergyMessage::hack_unknown_value_d(){

uint32_t MainEnergyMessage::hack_unknown_value_d()
{
return ((uint32_t) mData[12] << 24) | ((uint32_t) mData[11] << 16) | ((uint32_t) mData[10] << 8)
| (uint32_t) mData[9];

}
uint32_t MainEnergyMessage::hack_unknown_value_e(){

uint32_t MainEnergyMessage::hack_unknown_value_e()
{
return ((uint32_t) mData[16] << 24) | ((uint32_t) mData[15] << 16) | ((uint32_t) mData[14] << 8)
| (uint32_t) mData[13];
}
uint32_t MainEnergyMessage::hack_unknown_value_f(){

uint32_t MainEnergyMessage::hack_unknown_value_f()
{
return ((uint32_t) mData[20] << 24) | ((uint32_t) mData[19] << 16) | ((uint32_t) mData[18] << 8)
| (uint32_t) mData[17];
}
uint16_t MainEnergyMessage::hack_unknown_value_g(){

uint16_t MainEnergyMessage::hack_unknown_value_g()
{
return ((uint16_t) mData[22] << 8) | (uint16_t) mData[21];
}
uint16_t MainEnergyMessage::hack_unknown_value_h(){

uint16_t MainEnergyMessage::hack_unknown_value_h()
{
return ((uint16_t) mData[34] << 8) | (uint16_t) mData[33];
}
uint16_t MainEnergyMessage::hack_unknown_value_i(){

uint16_t MainEnergyMessage::hack_unknown_value_i()
{
return ((uint16_t) mData[36] << 8) | (uint16_t) mData[35];
}
uint64_t MainEnergyMessage::hack_unknown_value_j(){

uint64_t MainEnergyMessage::hack_unknown_value_j()
{
return ((uint64_t) mData[44] << 56) | ((uint64_t) mData[43] << 48) | ((uint64_t) mData[42] << 40)
| ((uint64_t) mData[41] << 32) | ((uint64_t) mData[40] << 24) | ((uint64_t) mData[39] << 16)
| ((uint64_t) mData[38] << 8) | (uint64_t) mData[37];
Expand All @@ -102,7 +120,9 @@ uint64_t MainEnergyMessage::getAttr(ENERGY_ATTR_U64 attr)
switch (attr)
{
case ENERGY_ATTR_U64::TOTAL_ENERGY:
break;
// NEXT protocol has this attribute stored as u32
return ((uint32_t) mData[20] << 24) | ((uint32_t) mData[19] << 16) | ((uint32_t) mData[18] << 8)
| (uint32_t) mData[17];
}
return 0;
}
Expand All @@ -114,17 +134,15 @@ uint32_t MainEnergyMessage::getAttr(ENERGY_ATTR_U32 attr)
case ENERGY_ATTR_U32::TOTAL_HEATPUMP_HOURS:
return ((uint32_t) mData[16] << 24) | ((uint32_t) mData[15] << 16) | ((uint32_t) mData[14] << 8)
| (uint32_t) mData[13];
case ENERGY_ATTR_U32::TOTAL_HOURS:
return ((uint32_t) mData[6] << 24) | ((uint32_t) mData[5] << 16) | ((uint32_t) mData[4] << 8)
| (uint32_t) mData[3];
case ENERGY_ATTR_U32::TOTAL_HEATING_ELEMENT_HOURS:
return ((uint32_t) mData[12] << 24) | ((uint32_t) mData[11] << 16) | ((uint32_t) mData[10] << 8)
| (uint32_t) mData[9];
case ENERGY_ATTR_U32::TOTAL_HOURS:
break;
}
return 0;
}



uint16_t MainEnergyMessage::getAttr(ENERGY_ATTR_U16 attr)
{
switch (attr)
Expand All @@ -144,7 +162,7 @@ bool MainEnergyMessage::hasAttr(ENERGY_ATTR_U64 attr) const
switch (attr)
{
case ENERGY_ATTR_U64::TOTAL_ENERGY:
break;
return true;
}
return false;
}
Expand All @@ -154,9 +172,9 @@ bool MainEnergyMessage::hasAttr(ENERGY_ATTR_U32 attr) const
switch (attr)
{
case ENERGY_ATTR_U32::TOTAL_HEATPUMP_HOURS:
case ENERGY_ATTR_U32::TOTAL_HOURS:
return true;
case ENERGY_ATTR_U32::TOTAL_HEATING_ELEMENT_HOURS:
return true;
case ENERGY_ATTR_U32::TOTAL_HOURS:
break;
}
return false;
Expand All @@ -166,10 +184,10 @@ bool MainEnergyMessage::hasAttr(ENERGY_ATTR_U16 attr) const
{
switch (attr)
{
case ENERGY_ATTR_U16::POWER_HEATPUMP:
case ENERGY_ATTR_U16::POWER_TOTAL:
return true;
case ENERGY_ATTR_U16::POWER_HEATPUMP:
case ENERGY_ATTR_U16::POWER_HEATELEMENT:
case ENERGY_ATTR_U16::POWER_TOTAL:
case ENERGY_ATTR_U16::WATER_TOTAL:
break;
}
Expand Down
Loading

0 comments on commit d8cc538

Please sign in to comment.