Skip to content

Commit

Permalink
Fixed an issue where, if no value was present for the "relay 1/2 is s…
Browse files Browse the repository at this point in the history
…witch/light" value was missing, the manager would crash.
  • Loading branch information
tpanajott committed Mar 30, 2024
1 parent 0dbdbc1 commit 30f4d49
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions docker/MQTTManager/include/nspanel/nspanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,36 +120,51 @@ void NSPanel::update_config(nlohmann::json &init_data) {
} else {
SPDLOG_ERROR("Creating new NSPanel with no known MAC!");
}
this->_ip_address = init_data["address"];

if (init_data.contains("address")) {
this->_ip_address = init_data["address"];
} else {
SPDLOG_ERROR("Received init data for panel but no address was specified. Will set default ''.");
this->_ip_address = "";
}

if (init_data.contains(("is_us_panel"))) {
this->_is_us_panel = init_data["is_us_panel"];
} else {
this->_is_us_panel = false;
}

if (!init_data.contains("id")) {
this->_state = MQTT_MANAGER_NSPANEL_STATE::AWAITING_ACCEPT;
}

if (this->_state == MQTT_MANAGER_NSPANEL_STATE::OFFLINE || this->_state == MQTT_MANAGER_NSPANEL_STATE::UNKNOWN) {
this->_rssi = -255;
this->_heap_used_pct = 0;
this->_nspanel_warnings = "";
this->_temperature = -255;
this->_update_progress = 0;
}

if (init_data.contains("id")) {
SPDLOG_DEBUG("Loaded NSPanel {}::{}.", this->_id, this->_name);
} else {
SPDLOG_DEBUG("Loaded NSPanel {} with no ID.", this->_name);
}
if (this->_relay1_is_mqtt_light != init_data["relay1_is_light"]) {

if (init_data.contains("relay1_is_light")) {
this->_relay1_is_mqtt_light = init_data["relay1_is_light"];
rebuilt_mqtt = true;
} else {
this->_relay1_is_mqtt_light = false;
}
this->_relay1_is_mqtt_light = init_data["relay1_is_light"];

if (this->_relay2_is_mqtt_light != init_data["relay2_is_light"]) {
if (init_data.contains("relay2_is_light")) {
this->_relay2_is_mqtt_light = init_data["relay2_is_light"];
rebuilt_mqtt = true;
} else {
this->_relay2_is_mqtt_light = false;
}
this->_relay2_is_mqtt_light = init_data["relay2_is_light"];

if (rebuilt_mqtt) {
this->reset_mqtt_topics();
Expand Down

0 comments on commit 30f4d49

Please sign in to comment.