ESPHome 2026.1.5
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_ESP32
5
7
8static const char *const 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 uint8_t sensor = 0;
21 for (const auto &ip : ips) {
22 if (ip.is_set()) {
23 if (this->ip_sensors_[sensor] != nullptr) {
24 ip.str_to(buf);
25 this->ip_sensors_[sensor]->publish_state(buf);
26 }
27 sensor++;
28 }
29 }
30}
31
33
34void DNSAddressEthernetInfo::dump_config() { LOG_TEXT_SENSOR("", "EthernetInfo DNS Address", this); }
35
37 const network::IPAddress &dns2) {
38 // IP_ADDRESS_BUFFER_SIZE (40) = max IP (39) + null; space reuses first null's slot
39 char buf[network::IP_ADDRESS_BUFFER_SIZE * 2];
40 dns1.str_to(buf);
41 size_t len1 = strlen(buf);
42 buf[len1] = ' ';
43 dns2.str_to(buf + len1 + 1);
44 this->publish_state(buf);
45}
46#endif // USE_ETHERNET_IP_STATE_LISTENERS
47
48void MACAddressEthernetInfo::dump_config() { LOG_TEXT_SENSOR("", "EthernetInfo MAC Address", this); }
49
50} // namespace esphome::ethernet_info
51
52#endif // USE_ESP32
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 *, 5 > ip_sensors_
void publish_state(const std::string &state)
EthernetComponent * global_eth_component
std::array< IPAddress, 5 > IPAddresses
Definition ip_address.h:180
char * str_to(char *buf) const
Write IP address to buffer. Buffer must be at least IP_ADDRESS_BUFFER_SIZE bytes.
Definition ip_address.h:69