mirror of
https://github.com/syssi/esphome-votronic.git
synced 2025-07-23 04:23:02 +02:00
committed by
GitHub
parent
b0ff305e6b
commit
3a925985c2
@@ -309,39 +309,43 @@ std::string Votronic::battery_status_bitmask_to_string_(const uint8_t mask) {
|
||||
return "Standby";
|
||||
}
|
||||
|
||||
if (mask) {
|
||||
for (uint8_t i = 0; i < BATTERY_STATUS_SIZE; i++) {
|
||||
if (mask & (1 << i)) {
|
||||
return BATTERY_STATUS[i];
|
||||
}
|
||||
}
|
||||
if (mask & (1 << 3)) {
|
||||
return "U3 phase";
|
||||
}
|
||||
|
||||
if (mask & (1 << 2)) {
|
||||
return "U2 phase";
|
||||
}
|
||||
|
||||
if (mask & (1 << 1)) {
|
||||
return "U1 phase";
|
||||
}
|
||||
|
||||
if (mask & (1 << 0)) {
|
||||
return "I phase";
|
||||
}
|
||||
|
||||
return str_snprintf("Unknown (0x%02X)", 15, mask);
|
||||
}
|
||||
|
||||
std::string Votronic::solar_charger_status_bitmask_to_string_(const uint8_t mask) {
|
||||
bool first = true;
|
||||
std::string errors_list = "";
|
||||
|
||||
if (mask == 0x00) {
|
||||
return "Standby";
|
||||
}
|
||||
|
||||
if (mask) {
|
||||
for (uint8_t i = 0; i < SOLAR_CHARGER_STATUS_SIZE; i++) {
|
||||
if (mask & (1 << i)) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
errors_list.append(";");
|
||||
}
|
||||
errors_list.append(SOLAR_CHARGER_STATUS[i]);
|
||||
}
|
||||
}
|
||||
if (mask & (1 << 5)) {
|
||||
return "AES active";
|
||||
}
|
||||
|
||||
return errors_list;
|
||||
if (mask & (1 << 4)) {
|
||||
return "Reduced";
|
||||
}
|
||||
|
||||
if (mask & (1 << 3)) {
|
||||
return "Active";
|
||||
}
|
||||
|
||||
return str_snprintf("Unknown (0x%02X)", 15, mask);
|
||||
}
|
||||
|
||||
std::string Votronic::charger_status_bitmask_to_string_(const uint8_t mask) {
|
||||
|
@@ -203,9 +203,10 @@ void VotronicBle::decode_solar_charger_data_(const std::vector<uint8_t> &data) {
|
||||
this->publish_state_(this->pv_voltage_sensor_, votronic_get_16bit(2) * 0.01f);
|
||||
this->publish_state_(this->pv_current_sensor_, votronic_get_16bit(4) * 0.1f);
|
||||
this->publish_state_(this->battery_status_bitmask_sensor_, data[8]);
|
||||
this->publish_state_(this->battery_status_text_sensor_, this->battery_status_to_string_(data[8]));
|
||||
this->publish_state_(this->battery_status_text_sensor_, this->battery_status_bitmask_to_string_(data[8]));
|
||||
this->publish_state_(this->pv_controller_status_bitmask_sensor_, data[12]);
|
||||
this->publish_state_(this->pv_controller_status_text_sensor_, this->pv_controller_status_to_string_(data[12]));
|
||||
this->publish_state_(this->pv_controller_status_text_sensor_,
|
||||
this->solar_charger_status_bitmask_to_string_(data[12]));
|
||||
this->publish_state_(this->charged_capacity_sensor_, (float) votronic_get_16bit(13));
|
||||
this->publish_state_(this->charged_energy_sensor_, votronic_get_16bit(15) * 10.0f);
|
||||
this->publish_state_(this->pv_power_sensor_, (float) votronic_get_16bit(17) * 0.1f);
|
||||
@@ -270,35 +271,47 @@ void VotronicBle::publish_state_(text_sensor::TextSensor *text_sensor, const std
|
||||
text_sensor->publish_state(state);
|
||||
}
|
||||
|
||||
std::string VotronicBle::pv_controller_status_to_string_(const uint8_t mask) {
|
||||
if ((mask & 24) == 24) {
|
||||
return "Current reduction";
|
||||
}
|
||||
|
||||
if ((mask & 8) == 8) {
|
||||
return "Active";
|
||||
}
|
||||
|
||||
if ((mask & 33) == 33) {
|
||||
std::string VotronicBle::battery_status_bitmask_to_string_(const uint8_t mask) {
|
||||
if (mask == 0x00) {
|
||||
return "Standby";
|
||||
}
|
||||
|
||||
if (mask & (1 << 3)) {
|
||||
return "U3 phase";
|
||||
}
|
||||
|
||||
if (mask & (1 << 2)) {
|
||||
return "U2 phase";
|
||||
}
|
||||
|
||||
if (mask & (1 << 1)) {
|
||||
return "U1 phase";
|
||||
}
|
||||
|
||||
if (mask & (1 << 0)) {
|
||||
return "I phase";
|
||||
}
|
||||
|
||||
return str_snprintf("Unknown (0x%02X)", 15, mask);
|
||||
}
|
||||
|
||||
std::string VotronicBle::battery_status_to_string_(const uint8_t mask) {
|
||||
if ((mask & 25) == 25) {
|
||||
return "Current reduction";
|
||||
}
|
||||
|
||||
if ((mask & 32) == 32) {
|
||||
return "Active";
|
||||
}
|
||||
|
||||
if ((mask & 33) == 33) {
|
||||
std::string VotronicBle::solar_charger_status_bitmask_to_string_(const uint8_t mask) {
|
||||
if (mask == 0x00) {
|
||||
return "Standby";
|
||||
}
|
||||
|
||||
if (mask & (1 << 5)) {
|
||||
return "AES active";
|
||||
}
|
||||
|
||||
if (mask & (1 << 4)) {
|
||||
return "Reduced";
|
||||
}
|
||||
|
||||
if (mask & (1 << 3)) {
|
||||
return "Active";
|
||||
}
|
||||
|
||||
return str_snprintf("Unknown (0x%02X)", 15, mask);
|
||||
}
|
||||
|
||||
|
@@ -127,8 +127,8 @@ class VotronicBle : public esphome::ble_client::BLEClientNode, public PollingCom
|
||||
void publish_state_(binary_sensor::BinarySensor *binary_sensor, const bool &state);
|
||||
void publish_state_(sensor::Sensor *sensor, float value);
|
||||
void publish_state_(text_sensor::TextSensor *text_sensor, const std::string &state);
|
||||
std::string pv_controller_status_to_string_(uint8_t mask);
|
||||
std::string battery_status_to_string_(uint8_t mask);
|
||||
std::string battery_status_bitmask_to_string_(uint8_t mask);
|
||||
std::string solar_charger_status_bitmask_to_string_(uint8_t mask);
|
||||
};
|
||||
|
||||
} // namespace votronic_ble
|
||||
|
Reference in New Issue
Block a user