wifi_info, reduce polling interval (#3165)

Co-authored-by: Jonas Bergler <jbergler@meraki.com>
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
Jonas Bergler 2022-02-08 20:27:39 +13:00 committed by GitHub
parent 69856286e8
commit 7ca9245735
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 12 deletions

View file

@ -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
),

View file

@ -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());