ESPHome
2026.11.0b6
Loading...
Searching...
No Matches
esphome
components
ethernet_info
ethernet_info_text_sensor.h
Go to the documentation of this file.
1
#pragma once
2
3
#include "
esphome/core/component.h
"
4
#include "
esphome/components/text_sensor/text_sensor.h
"
5
#include "
esphome/components/ethernet/ethernet_component.h
"
6
7
#ifdef USE_ETHERNET
8
9
namespace
esphome::ethernet_info
{
10
11
#ifdef USE_ETHERNET_IP_STATE_LISTENERS
12
class
IPAddressEthernetInfo
final :
public
Component
,
13
public
text_sensor::TextSensor
,
14
public
ethernet::EthernetIPStateListener
{
15
public
:
16
// User provided, not "= default": `new(p) IPAddressEthernetInfo()` would zero-fill .bss that is already zero.
17
IPAddressEthernetInfo
() {}
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
36
class
DNSAddressEthernetInfo
final :
public
Component
,
37
public
text_sensor::TextSensor
,
38
public
ethernet::EthernetIPStateListener
{
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
49
class
MACAddressEthernetInfo
final :
public
Component
,
public
text_sensor::TextSensor
{
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
esphome::Component
Definition
component.h:147
esphome::ethernet::EthernetIPStateListener
Listener interface for Ethernet IP state changes.
Definition
ethernet_component.h:70
esphome::ethernet_info::DNSAddressEthernetInfo
Definition
ethernet_info_text_sensor.h:38
esphome::ethernet_info::DNSAddressEthernetInfo::on_ip_state
void on_ip_state(const network::IPAddresses &ips, const network::IPAddress &dns1, const network::IPAddress &dns2) override
Definition
ethernet_info_text_sensor.cpp:40
esphome::ethernet_info::DNSAddressEthernetInfo::setup
void setup() override
Definition
ethernet_info_text_sensor.cpp:36
esphome::ethernet_info::DNSAddressEthernetInfo::dump_config
void dump_config() override
Definition
ethernet_info_text_sensor.cpp:38
esphome::ethernet_info::IPAddressEthernetInfo
Definition
ethernet_info_text_sensor.h:14
esphome::ethernet_info::IPAddressEthernetInfo::IPAddressEthernetInfo
IPAddressEthernetInfo()
Definition
ethernet_info_text_sensor.h:17
esphome::ethernet_info::IPAddressEthernetInfo::dump_config
void dump_config() override
Definition
ethernet_info_text_sensor.cpp:13
esphome::ethernet_info::IPAddressEthernetInfo::on_ip_state
void on_ip_state(const network::IPAddresses &ips, const network::IPAddress &dns1, const network::IPAddress &dns2) override
Definition
ethernet_info_text_sensor.cpp:15
esphome::ethernet_info::IPAddressEthernetInfo::setup
void setup() override
Definition
ethernet_info_text_sensor.cpp:11
esphome::ethernet_info::IPAddressEthernetInfo::ip_sensors_
std::array< text_sensor::TextSensor *, ETHERNET_INFO_IP_SENSOR_COUNT > ip_sensors_
Definition
ethernet_info_text_sensor.h:32
esphome::ethernet_info::IPAddressEthernetInfo::add_ip_sensors
void add_ip_sensors(uint8_t index, text_sensor::TextSensor *s)
Definition
ethernet_info_text_sensor.h:22
esphome::ethernet_info::MACAddressEthernetInfo
Definition
ethernet_info_text_sensor.h:49
esphome::ethernet_info::MACAddressEthernetInfo::get_setup_priority
float get_setup_priority() const override
Definition
ethernet_info_text_sensor.h:55
esphome::ethernet_info::MACAddressEthernetInfo::setup
void setup() override
Definition
ethernet_info_text_sensor.h:51
esphome::ethernet_info::MACAddressEthernetInfo::dump_config
void dump_config() override
Definition
ethernet_info_text_sensor.cpp:52
esphome::text_sensor::TextSensor
Definition
text_sensor.h:29
esphome::text_sensor::TextSensor::publish_state
void publish_state(const std::string &state)
Definition
text_sensor.h:42
component.h
ethernet_component.h
esphome::ethernet_info
Definition
ethernet_info_text_sensor.cpp:6
esphome::ethernet::global_eth_component
EthernetComponent * global_eth_component
Definition
ethernet_component.cpp:9
esphome::network::IPAddresses
std::array< IPAddress, 5 > IPAddresses
Definition
ip_address.h:368
esphome::setup_priority::ETHERNET
constexpr float ETHERNET
Definition
component.h:51
esphome::network::IPAddress
Definition
ip_address.h:108
text_sensor.h
Generated by
1.12.0