ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
ethernet_info_text_sensor.cpp
Go to the documentation of this file.
2#include "esphome/core/log.h"
3
4#ifdef USE_ETHERNET
5
7
8ESPHOME_LOG_TAG(TAG, "ethernet_info");
9
10#ifdef USE_ETHERNET_IP_STATE_LISTENERS
12
13void IPAddressEthernetInfo::dump_config() { LOG_TEXT_SENSOR("", "EthernetInfo IPAddress", this); }
14
16 const network::IPAddress &dns2) {
17 char buf[network::IP_ADDRESS_BUFFER_SIZE];
18 ips[0].str_to(buf);
19 this->publish_state(buf);
20#ifdef ETHERNET_INFO_IP_SENSOR_COUNT
21 uint8_t sensor = 0;
22 for (const auto &ip : ips) {
23 if (!ip.is_set())
24 continue;
25 if (sensor == ETHERNET_INFO_IP_SENSOR_COUNT)
26 break;
27 if (this->ip_sensors_[sensor] != nullptr) {
28 ip.str_to(buf);
29 this->ip_sensors_[sensor]->publish_state(buf);
30 }
31 sensor++;
32 }
33#endif
34}
35
37
38void DNSAddressEthernetInfo::dump_config() { LOG_TEXT_SENSOR("", "EthernetInfo DNS Address", this); }
39
41 const network::IPAddress &dns2) {
42 // IP_ADDRESS_BUFFER_SIZE (40) = max IP (39) + null; space reuses first null's slot
43 char buf[network::IP_ADDRESS_BUFFER_SIZE * 2];
44 dns1.str_to(buf);
45 size_t len1 = strlen(buf);
46 buf[len1] = ' ';
47 dns2.str_to(buf + len1 + 1);
48 this->publish_state(buf);
49}
50#endif // USE_ETHERNET_IP_STATE_LISTENERS
51
52void MACAddressEthernetInfo::dump_config() { LOG_TEXT_SENSOR("", "EthernetInfo MAC Address", this); }
53
54} // namespace esphome::ethernet_info
55
56#endif // USE_ETHERNET
void add_ip_state_listener(EthernetIPStateListener *listener)
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 publish_state(const std::string &state)
Definition text_sensor.h:42
ESPHOME_LOG_TAG(TAG, "ethernet_info")
EthernetComponent * global_eth_component
std::array< IPAddress, 5 > IPAddresses
Definition ip_address.h:368
char * str_to(char *buf) const
Definition ip_address.h:152