ESPHome 2026.12.0-dev
Loading...
Searching...
No Matches
wifi_info_sensor.cpp
Go to the documentation of this file.
1#include "wifi_info_sensor.h"
2#if defined(USE_WIFI_CONNECT_STATE_LISTENERS) && defined(USE_SENSOR)
4#include "esphome/core/log.h"
5
7
8ESPHOME_LOG_TAG(TAG, "wifi_info");
9
11
12void ChannelWiFiInfo::dump_config() { LOG_SENSOR("", "Channel", this); }
13
14void ChannelWiFiInfo::on_wifi_connect_state(StringRef ssid, std::span<const uint8_t, 6> bssid) {
15 float channel = NAN;
16 if (mac_address_is_valid(bssid.data())) {
18 if (value > 0)
19 channel = value;
20 }
21 this->publish_state(channel);
22}
23
24} // namespace esphome::wifi_info
25#endif
StringRef is a reference to a string owned by something else.
Definition string_ref.h:31
void publish_state(float state)
Publish a new state to the front-end.
Definition sensor.cpp:65
void add_connect_state_listener(WiFiConnectStateListener *listener)
Add a listener for WiFi connection state changes.
void on_wifi_connect_state(StringRef ssid, std::span< const uint8_t, 6 > bssid) override
ESPHOME_LOG_TAG(TAG, "wifi_info")
WiFiComponent * global_wifi_component
bool mac_address_is_valid(const uint8_t *mac)
Check if the MAC address is not all zeros or all ones.
Definition helpers.cpp:886
uint32_t value
Definition hal.cpp:59