Skip to content

Commit

Permalink
fix: configured_networks to publish a single array
Browse files Browse the repository at this point in the history
Previously configured_networks published an array per wifi device
which resulted in empty arrays where a device had no configured
networks.

Signed-off-by: James Chapman <[email protected]>
  • Loading branch information
james-ctc committed Feb 23, 2024
1 parent 9392681 commit a27f7bc
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions modules/Setup/Setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,17 +514,24 @@ bool Setup::rfkill_block(std::string rfkill_id) {

void Setup::publish_configured_networks() {
auto network_devices = this->get_network_devices();

WpaCliSetup::WifiNetworkStatusList all_wifi_networks;

for (auto device : network_devices) {
if (!device.wireless) {
continue;
}
WifiConfigureClass wifi;
auto network_list = wifi.list_networks_status(device.interface);
std::string network_list_var = this->var_base + "configured_networks";
json configured_networks_json = json::array();
configured_networks_json = network_list;
this->mqtt.publish(network_list_var, configured_networks_json.dump());
for (auto& i : network_list) {
all_wifi_networks.push_back(std::move(i));
}
}

std::string network_list_var = this->var_base + "configured_networks";
json configured_networks_json = json::array();
configured_networks_json = all_wifi_networks;
this->mqtt.publish(network_list_var, configured_networks_json.dump());
}

bool Setup::add_and_enable_network(const std::string& interface, const std::string& ssid, const std::string& psk,
Expand Down

0 comments on commit a27f7bc

Please sign in to comment.