ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
ethernet_info_text_sensor.h
Go to the documentation of this file.
1#pragma once
2
6
7#ifdef USE_ETHERNET
8
10
11#ifdef USE_ETHERNET_IP_STATE_LISTENERS
12class IPAddressEthernetInfo final : public Component,
15 public:
16 // User provided, not "= default": `new(p) IPAddressEthernetInfo()` would zero-fill .bss that is already zero.
18
19 void setup() override;
20 void dump_config() override;
21 void add_ip_sensors(uint8_t index, text_sensor::TextSensor *s) { this->ip_sensors_[index] = s; }
22
23 // EthernetIPStateListener interface
24 void on_ip_state(const network::IPAddresses &ips, const network::IPAddress &dns1,
25 const network::IPAddress &dns2) override;
26
27 protected:
28 std::array<text_sensor::TextSensor *, 5> ip_sensors_{};
29};
30
31class DNSAddressEthernetInfo final : public Component,
34 public:
35 void setup() override;
36 void dump_config() override;
37
38 // EthernetIPStateListener interface
39 void on_ip_state(const network::IPAddresses &ips, const network::IPAddress &dns1,
40 const network::IPAddress &dns2) override;
41};
42#endif // USE_ETHERNET_IP_STATE_LISTENERS
43
45 public:
46 void setup() override {
47 char buf[MAC_ADDRESS_PRETTY_BUFFER_SIZE];
48 this->publish_state(ethernet::global_eth_component->get_eth_mac_address_pretty_into_buffer(buf));
49 }
50 float get_setup_priority() const override { return setup_priority::ETHERNET; }
51 void dump_config() override;
52};
53
54} // namespace esphome::ethernet_info
55
56#endif // USE_ETHERNET
Listener interface for Ethernet IP state changes.
void on_ip_state(const network::IPAddresses &ips, const network::IPAddress &dns1, const network::IPAddress &dns2) override
void on_ip_state(const network::IPAddresses &ips, const network::IPAddress &dns1, const network::IPAddress &dns2) override
std::array< text_sensor::TextSensor *, 5 > ip_sensors_
void add_ip_sensors(uint8_t index, text_sensor::TextSensor *s)
void publish_state(const std::string &state)
Definition text_sensor.h:42
EthernetComponent * global_eth_component
std::array< IPAddress, 5 > IPAddresses
Definition ip_address.h:369
constexpr float ETHERNET
Definition component.h:51