Skip to content

Commit

Permalink
remove preset names from TEXT entities definitions (m3_vedirect)
Browse files Browse the repository at this point in the history
  • Loading branch information
krahabb committed Nov 20, 2024
1 parent ebc26da commit e77355e
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 41 deletions.
2 changes: 1 addition & 1 deletion esphome/components/m3_vedirect/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ void Manager::on_frame_text_(TextRecord **text_records, uint8_t text_records_cou
if (reg_def) {
hex_register = this->get_hex_register_(reg_def->register_id, true);
} else {
hex_register = Entity::BUILD_ENTITY_FUNC[Entity::TextSensor](this, text_def->description, label);
hex_register = Entity::BUILD_ENTITY_FUNC[Entity::TextSensor](this, label, label);
}
} else {
// We lack the definition for this TEXT RECORD so
Expand Down
2 changes: 1 addition & 1 deletion esphome/components/m3_vedirect/ve_reg_def.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const REG_DEF *REG_DEF::find_register_id(register_id_t register_id) {
return (reg_def_it != reg_def_end) && (reg_def_it->register_id == register_id) ? reg_def_it : nullptr;
}

#define DEFINE_TEXT_DEF_REG(label, register_type, name) {label, name, REG_DEF::TYPE::register_type},
#define DEFINE_TEXT_DEF_REG(label, register_type) {label, REG_DEF::TYPE::register_type},
#define DEFINE_TEXT_DEF(flavor, cls, ...) IF(DEF_##flavor)(DEFINE_TEXT_DEF_REG(__VA_ARGS__))
const TEXT_DEF TEXT_DEF::DEFS[] = {TEXTRECORDS(DEFINE_TEXT_DEF)};

Expand Down
8 changes: 3 additions & 5 deletions esphome/components/m3_vedirect/ve_reg_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ struct REG_DEF {
static constexpr register_id_t REGISTER_UNDEFINED = 0x0000;

const register_id_t register_id;
const char *const label;
const char *const label; // not relevant for manually built (in config.yaml) REG_DEF(s)
CLASS cls : 3;
ACCESS access : 1;
DATA_TYPE data_type : 3; // only relevant for BITMASK and NUMERIC (ENUM are UN8 though)
Expand Down Expand Up @@ -206,15 +206,13 @@ struct REG_DEF {
/// @brief Descriptor struct for TEXT frame records
struct TEXT_DEF {
const char *label;
const char *description;
const REG_DEF::TYPE register_type;

// Constructor used when register_type is a valid mapping to a REG_DEF
TEXT_DEF(const char *label, const char *description, REG_DEF::TYPE register_type)
: label(label), description(description), register_type(register_type) {}
TEXT_DEF(const char *label, REG_DEF::TYPE register_type) : label(label), register_type(register_type) {}

// Constructor for default unknown/untyped field
TEXT_DEF() : label(nullptr), description(nullptr), register_type(REG_DEF::TYPE::TYPE_COUNT) {}
TEXT_DEF() : label(nullptr), register_type(REG_DEF::TYPE::TYPE_COUNT) {}

bool operator<(const char *label) const { return strcmp(this->label, label) < 0; }
static const TEXT_DEF DEFS[];
Expand Down
4 changes: 2 additions & 2 deletions esphome/components/m3_vedirect/ve_reg_flavor.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
#pragma once
#include "ve_reg_macro.h"

#if 0
#if 1
// debug/testing preset environment: remove on release
//#define VEDIRECT_FLAVORS_ALL
#define VEDIRECT_FLAVOR_ALL
//#define VEDIRECT_FLAVOR_MPPT_RS
//#define VEDIRECT_FLAVOR_INV_PHNX
//#define VEDIRECT_FLAVOR_BMV
Expand Down
64 changes: 32 additions & 32 deletions esphome/components/m3_vedirect/ve_reg_text.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,37 @@
// clang-format off

#define TEXTRECORDS(MACRO) \
MACRO(INV, NUMERIC, "AC_OUT_I", AC_OUT_CURRENT, "AC output current") \
MACRO(INV, NUMERIC, "AC_OUT_S", AC_OUT_APPARENT_POWER, "AC output apparent power") \
MACRO(INV, NUMERIC, "AC_OUT_V", AC_OUT_VOLTAGE, "AC output voltage") \
MACRO(ANY, BITMASK, "AR", ALARM_REASON, "Alarm reason") \
MACRO(BMV, BOOLEAN, "Alarm", ALARM_BUZZER, "Alarm") \
MACRO(ANY, ENUM, "CS", DEVICE_STATE, "State of operation") \
MACRO(CHG, ENUM, "ERR", CHR_ERROR_CODE, "Charger error") \
MACRO(ANY, STRING, "FW", APP_VER, "Firmware version (FW)") \
MACRO(ANY, STRING, "FWE", APP_VER, "Firmware version (FWE)") \
MACRO(MPPT, NUMERIC, "H19", USER_YIELD, "Yield total") \
MACRO(MPPT, NUMERIC, "H20", YIELD_TODAY, "Yield today") \
MACRO(MPPT, NUMERIC, "H21", MAXIMUM_POWER_TODAY, "Maximum power today") \
MACRO(MPPT, NUMERIC, "H22", YIELD_YESTERDAY, "Yield yesterday") \
MACRO(MPPT, NUMERIC, "H23", MAXIMUM_POWER_YESTERDAY, "Maximum power yesterday") \
MACRO(ANY, NUMERIC, "I", DC_CHANNEL1_CURRENT, "Battery current") \
MACRO(MPPT, NUMERIC, "IL", LOAD_CURRENT, "Load current") \
MACRO(MPPT, BOOLEAN, "LOAD", LOAD_OUTPUT_STATE, "Output state") \
MACRO(ANY, ENUM, "MODE", DEVICE_MODE, "Device mode") \
MACRO(BMV71, STRING, "MON", DC_MONITOR_MODE, "DC monitor mode") \
MACRO(MPPT, ENUM, "MPPT", MPPT_TRACKER_MODE, "Tracker operation mode") \
MACRO(ANY, BITMASK, "OR", DEVICE_OFF_REASON_2, "Off reason") \
MACRO(BMV, NUMERIC, "P", DC_CHANNEL1_POWER, "Battery power") \
MACRO(ANY, UNKNOWN, "PID", PRODUCT_ID, "Product Id") \
MACRO(MPPT, NUMERIC, "PPV", PANEL_POWER, "PV power") \
MACRO(ANY, BOOLEAN, "Relay", RELAY_CONTROL, "Relay state") \
MACRO(ANY, STRING, "SER#", SERIAL_NUMBER, "Serial number") \
MACRO(BMV, NUMERIC, "SOC", SOC, "SOC") \
MACRO(BMV, NUMERIC, "T", BAT_TEMPERATURE, "Battery temperature") \
MACRO(BMV, NUMERIC, "TTG", TTG, "Time To Go") \
MACRO(ANY, NUMERIC, "V", DC_CHANNEL1_VOLTAGE, "Battery voltage") \
MACRO(MPPT, NUMERIC, "VPV", PANEL_VOLTAGE, "PV voltage") \
MACRO(INV, BITMASK, "WARN", WARNING_REASON, "Warning reason")
MACRO(INV, NUMERIC, "AC_OUT_I", AC_OUT_CURRENT) \
MACRO(INV, NUMERIC, "AC_OUT_S", AC_OUT_APPARENT_POWER) \
MACRO(INV, NUMERIC, "AC_OUT_V", AC_OUT_VOLTAGE) \
MACRO(ANY, BITMASK, "AR", ALARM_REASON) \
MACRO(BMV, BOOLEAN, "Alarm", ALARM_BUZZER) \
MACRO(ANY, ENUM, "CS", DEVICE_STATE) \
MACRO(CHG, ENUM, "ERR", CHR_ERROR_CODE) \
MACRO(ANY, STRING, "FW", APP_VER) \
MACRO(ANY, STRING, "FWE", APP_VER) \
MACRO(MPPT, NUMERIC, "H19", USER_YIELD) \
MACRO(MPPT, NUMERIC, "H20", YIELD_TODAY) \
MACRO(MPPT, NUMERIC, "H21", MAXIMUM_POWER_TODAY) \
MACRO(MPPT, NUMERIC, "H22", YIELD_YESTERDAY) \
MACRO(MPPT, NUMERIC, "H23", MAXIMUM_POWER_YESTERDAY) \
MACRO(ANY, NUMERIC, "I", DC_CHANNEL1_CURRENT) \
MACRO(MPPT, NUMERIC, "IL", LOAD_CURRENT) \
MACRO(MPPT, BOOLEAN, "LOAD", LOAD_OUTPUT_STATE) \
MACRO(ANY, ENUM, "MODE", DEVICE_MODE) \
MACRO(BMV71, STRING, "MON", DC_MONITOR_MODE) \
MACRO(MPPT, ENUM, "MPPT", MPPT_TRACKER_MODE) \
MACRO(ANY, BITMASK, "OR", DEVICE_OFF_REASON_2) \
MACRO(BMV, NUMERIC, "P", DC_CHANNEL1_POWER) \
MACRO(ANY, UNKNOWN, "PID", PRODUCT_ID) \
MACRO(MPPT, NUMERIC, "PPV", PANEL_POWER) \
MACRO(ANY, BOOLEAN, "Relay", RELAY_CONTROL) \
MACRO(ANY, STRING, "SER#", SERIAL_NUMBER) \
MACRO(BMV, NUMERIC, "SOC", SOC) \
MACRO(BMV, NUMERIC, "T", BAT_TEMPERATURE) \
MACRO(BMV, NUMERIC, "TTG", TTG) \
MACRO(ANY, NUMERIC, "V", DC_CHANNEL1_VOLTAGE) \
MACRO(MPPT, NUMERIC, "VPV", PANEL_VOLTAGE) \
MACRO(INV, BITMASK, "WARN", WARNING_REASON)

// clang-format on

0 comments on commit e77355e

Please sign in to comment.