[wifi_info] Fix compilation error when using only mac_address sensor, add tests (#12222)
This commit is contained in:
@@ -6,6 +6,8 @@ namespace esphome::wifi_info {
|
||||
|
||||
static const char *const TAG = "wifi_info";
|
||||
|
||||
#ifdef USE_WIFI_LISTENERS
|
||||
|
||||
static constexpr size_t MAX_STATE_LENGTH = 255;
|
||||
|
||||
/********************
|
||||
@@ -98,6 +100,8 @@ void BSSIDWiFiInfo::on_wifi_connect_state(const std::string &ssid, const wifi::b
|
||||
this->publish_state(buf);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* MacAddressWifiInfo
|
||||
********************/
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
namespace esphome::wifi_info {
|
||||
|
||||
#ifdef USE_WIFI_LISTENERS
|
||||
class IPAddressWiFiInfo final : public Component, public text_sensor::TextSensor, public wifi::WiFiIPStateListener {
|
||||
public:
|
||||
void setup() override;
|
||||
@@ -62,6 +63,7 @@ class BSSIDWiFiInfo final : public Component, public text_sensor::TextSensor, pu
|
||||
// WiFiConnectStateListener interface
|
||||
void on_wifi_connect_state(const std::string &ssid, const wifi::bssid_t &bssid) override;
|
||||
};
|
||||
#endif
|
||||
|
||||
class MacAddressWifiInfo final : public Component, public text_sensor::TextSensor {
|
||||
public:
|
||||
|
||||
8
tests/components/wifi_info/common-mac.yaml
Normal file
8
tests/components/wifi_info/common-mac.yaml
Normal file
@@ -0,0 +1,8 @@
|
||||
wifi:
|
||||
ssid: MySSID
|
||||
password: password1
|
||||
|
||||
text_sensor:
|
||||
- platform: wifi_info
|
||||
mac_address:
|
||||
name: MAC Address
|
||||
@@ -13,6 +13,6 @@ text_sensor:
|
||||
bssid:
|
||||
name: BSSID
|
||||
mac_address:
|
||||
name: Mac Address
|
||||
name: MAC Address
|
||||
dns_address:
|
||||
name: DNS ADdress
|
||||
|
||||
4
tests/components/wifi_info/test-mac.esp32-idf.yaml
Normal file
4
tests/components/wifi_info/test-mac.esp32-idf.yaml
Normal file
@@ -0,0 +1,4 @@
|
||||
packages:
|
||||
i2c: !include ../../test_build_components/common/i2c/esp32-idf.yaml
|
||||
|
||||
<<: !include common-mac.yaml
|
||||
4
tests/components/wifi_info/test-mac.esp8266-ard.yaml
Normal file
4
tests/components/wifi_info/test-mac.esp8266-ard.yaml
Normal file
@@ -0,0 +1,4 @@
|
||||
packages:
|
||||
i2c: !include ../../test_build_components/common/i2c/esp8266-ard.yaml
|
||||
|
||||
<<: !include common-mac.yaml
|
||||
4
tests/components/wifi_info/test-mac.rp2040-ard.yaml
Normal file
4
tests/components/wifi_info/test-mac.rp2040-ard.yaml
Normal file
@@ -0,0 +1,4 @@
|
||||
packages:
|
||||
i2c: !include ../../test_build_components/common/i2c/rp2040-ard.yaml
|
||||
|
||||
<<: !include common-mac.yaml
|
||||
Reference in New Issue
Block a user