ESPHome 2026.11.0b6
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#ifdef ETHERNET_INFO_IP_SENSOR_COUNT
22 void add_ip_sensors(uint8_t index, text_sensor::TextSensor *s) { this->ip_sensors_[index] = s; }
23#endif
24
25 // EthernetIPStateListener interface
26 void on_ip_state(const network::IPAddresses &ips, const network::IPAddress &dns1,
27 const network::IPAddress &dns2) override;
28
29 protected:
30#ifdef ETHERNET_INFO_IP_SENSOR_COUNT
31 // Sized to the highest configured address_N
32 std::array<text_sensor::TextSensor *, ETHERNET_INFO_IP_SENSOR_COUNT> ip_sensors_{};
33#endif
34};
35
36class DNSAddressEthernetInfo final : public Component,
39 public:
40 void setup() override;
41 void dump_config() override;
42
43 // EthernetIPStateListener interface
44 void on_ip_state(const network::IPAddresses &ips, const network::IPAddress &dns1,
45 const network::IPAddress &dns2) override;
46};
47#endif // USE_ETHERNET_IP_STATE_LISTENERS
48
50 public:
51 void setup() override {
52 char buf[MAC_ADDRESS_PRETTY_BUFFER_SIZE];
53 this->publish_state(ethernet::global_eth_component->get_eth_mac_address_pretty_into_buffer(buf));
54 }
55 float get_setup_priority() const override { return setup_priority::ETHERNET; }
56 void dump_config() override;
57};
58
59} // namespace esphome::ethernet_info
60
61#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 *, ETHERNET_INFO_IP_SENSOR_COUNT > 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:368
constexpr float ETHERNET
Definition component.h:51