mirror of
https://github.com/esphome/esphome.git
synced 2024-11-22 11:47:30 +01:00
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:
parent
69856286e8
commit
7ca9245735
@ -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
|
||||
),
|
||||
|
@ -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());
|
||||
|
Loading…
Reference in New Issue
Block a user