diff --git a/esphome/components/wifi_info/text_sensor.py b/esphome/components/wifi_info/text_sensor.py index d7d652ac7b..58250c3759 100644 --- a/esphome/components/wifi_info/text_sensor.py +++ b/esphome/components/wifi_info/text_sensor.py @@ -14,14 +14,16 @@ DEPENDENCIES = ["wifi"] wifi_info_ns = cg.esphome_ns.namespace("wifi_info") IPAddressWiFiInfo = wifi_info_ns.class_( - "IPAddressWiFiInfo", text_sensor.TextSensor, cg.Component + "IPAddressWiFiInfo", text_sensor.TextSensor, cg.PollingComponent ) ScanResultsWiFiInfo = wifi_info_ns.class_( "ScanResultsWiFiInfo", text_sensor.TextSensor, cg.PollingComponent ) -SSIDWiFiInfo = wifi_info_ns.class_("SSIDWiFiInfo", text_sensor.TextSensor, cg.Component) +SSIDWiFiInfo = wifi_info_ns.class_( + "SSIDWiFiInfo", text_sensor.TextSensor, cg.PollingComponent +) BSSIDWiFiInfo = wifi_info_ns.class_( - "BSSIDWiFiInfo", text_sensor.TextSensor, cg.Component + "BSSIDWiFiInfo", text_sensor.TextSensor, cg.PollingComponent ) MacAddressWifiInfo = wifi_info_ns.class_( "MacAddressWifiInfo", text_sensor.TextSensor, cg.Component @@ -31,16 +33,16 @@ CONFIG_SCHEMA = cv.Schema( { cv.Optional(CONF_IP_ADDRESS): text_sensor.text_sensor_schema( klass=IPAddressWiFiInfo, entity_category=ENTITY_CATEGORY_DIAGNOSTIC - ), + ).extend(cv.polling_component_schema("1s")), cv.Optional(CONF_SCAN_RESULTS): text_sensor.text_sensor_schema( klass=ScanResultsWiFiInfo, entity_category=ENTITY_CATEGORY_DIAGNOSTIC ).extend(cv.polling_component_schema("60s")), cv.Optional(CONF_SSID): text_sensor.text_sensor_schema( klass=SSIDWiFiInfo, entity_category=ENTITY_CATEGORY_DIAGNOSTIC - ), + ).extend(cv.polling_component_schema("1s")), cv.Optional(CONF_BSSID): text_sensor.text_sensor_schema( klass=BSSIDWiFiInfo, entity_category=ENTITY_CATEGORY_DIAGNOSTIC - ), + ).extend(cv.polling_component_schema("1s")), cv.Optional(CONF_MAC_ADDRESS): text_sensor.text_sensor_schema( klass=MacAddressWifiInfo, entity_category=ENTITY_CATEGORY_DIAGNOSTIC ), diff --git a/esphome/components/wifi_info/wifi_info_text_sensor.h b/esphome/components/wifi_info/wifi_info_text_sensor.h index 5b54451ed0..e5b0fa3223 100644 --- a/esphome/components/wifi_info/wifi_info_text_sensor.h +++ b/esphome/components/wifi_info/wifi_info_text_sensor.h @@ -7,9 +7,9 @@ namespace esphome { namespace wifi_info { -class IPAddressWiFiInfo : public Component, public text_sensor::TextSensor { +class IPAddressWiFiInfo : public PollingComponent, public text_sensor::TextSensor { public: - void loop() override { + void update() override { auto ip = wifi::global_wifi_component->wifi_sta_ip(); if (ip != this->last_ip_) { this->last_ip_ = ip; @@ -53,9 +53,9 @@ class ScanResultsWiFiInfo : public PollingComponent, public text_sensor::TextSen std::string last_scan_results_; }; -class SSIDWiFiInfo : public Component, public text_sensor::TextSensor { +class SSIDWiFiInfo : public PollingComponent, public text_sensor::TextSensor { public: - void loop() override { + void update() override { std::string ssid = wifi::global_wifi_component->wifi_ssid(); if (this->last_ssid_ != ssid) { this->last_ssid_ = ssid; @@ -70,9 +70,9 @@ class SSIDWiFiInfo : public Component, public text_sensor::TextSensor { std::string last_ssid_; }; -class BSSIDWiFiInfo : public Component, public text_sensor::TextSensor { +class BSSIDWiFiInfo : public PollingComponent, public text_sensor::TextSensor { public: - void loop() override { + void update() override { wifi::bssid_t bssid = wifi::global_wifi_component->wifi_bssid(); if (memcmp(bssid.data(), last_bssid_.data(), 6) != 0) { std::copy(bssid.begin(), bssid.end(), last_bssid_.begin());