Skip to content

Commit

Permalink
Filter NA values #51
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed May 24, 2024
1 parent 4624f6e commit d86e3a4
Showing 1 changed file with 35 additions and 7 deletions.
42 changes: 35 additions & 7 deletions components/victron_ble/sensor/victron_sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,11 @@ void VictronSensor::setup() {
this->parent_->add_on_message_callback([this](const VictronBleData *msg) {
switch (msg->record_type) {
case VICTRON_BLE_RECORD_TYPE::SOLAR_CHARGER:
this->publish_state(-0.1f * msg->data.solar_charger.load_current);
if (msg->data.solar_charger.load_current == 0x1FF) {
this->publish_state(NAN);
} else {
this->publish_state(-0.1f * msg->data.solar_charger.load_current);
}
break;
default:
ESP_LOGW(TAG, "[%s] Device has no `load current` field.", this->parent_->address_str().c_str());
Expand Down Expand Up @@ -485,13 +489,25 @@ void VictronSensor::setup() {
this->parent_->add_on_message_callback([this](const VictronBleData *msg) {
switch (msg->record_type) {
case VICTRON_BLE_RECORD_TYPE::SOLAR_CHARGER:
this->publish_state(msg->data.solar_charger.pv_power);
if (msg->data.solar_charger.pv_power == 0xFFFF) {
this->publish_state(NAN);
} else {
this->publish_state(msg->data.solar_charger.pv_power);
}
break;
case VICTRON_BLE_RECORD_TYPE::INVERTER_RS:
this->publish_state(msg->data.inverter_rs.pv_power);
if (msg->data.inverter_rs.pv_power == 0xFFFF) {
this->publish_state(NAN);
} else {
this->publish_state(msg->data.inverter_rs.pv_power);
}
break;
case VICTRON_BLE_RECORD_TYPE::MULTI_RS:
this->publish_state(msg->data.multi_rs.pv_power);
if (msg->data.multi_rs.pv_power == 0xFFFF) {
this->publish_state(NAN);
} else {
this->publish_state(msg->data.multi_rs.pv_power);
}
break;
default:
ESP_LOGW(TAG, "[%s] Device has no `PV power` field.", this->parent_->address_str().c_str());
Expand Down Expand Up @@ -598,13 +614,25 @@ void VictronSensor::setup() {
this->parent_->add_on_message_callback([this](const VictronBleData *msg) {
switch (msg->record_type) {
case VICTRON_BLE_RECORD_TYPE::SOLAR_CHARGER:
this->publish_state(0.01f * msg->data.solar_charger.yield_today);
if (msg->data.solar_charger.yield_today == 0xFFFF) {
this->publish_state(NAN);
} else {
this->publish_state(0.01f * msg->data.solar_charger.yield_today);
}
break;
case VICTRON_BLE_RECORD_TYPE::INVERTER_RS:
this->publish_state(0.01f * msg->data.inverter_rs.yield_today);
if (msg->data.inverter_rs.yield_today == 0xFFFF) {
this->publish_state(NAN);
} else {
this->publish_state(0.01f * msg->data.inverter_rs.yield_today);
}
break;
case VICTRON_BLE_RECORD_TYPE::MULTI_RS:
this->publish_state(0.01f * msg->data.multi_rs.yield_today);
if (msg->data.multi_rs.yield_today == 0xFFFF) {
this->publish_state(NAN);
} else {
this->publish_state(0.01f * msg->data.multi_rs.yield_today);
}
break;
default:
ESP_LOGW(TAG, "[%s] Device has no `yield today` field.", this->parent_->address_str().c_str());
Expand Down

0 comments on commit d86e3a4

Please sign in to comment.