ESPHome
2026.11.0-dev
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
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
31
class
DNSAddressEthernetInfo
final :
public
Component
,
32
public
text_sensor::TextSensor
,
33
public
ethernet::EthernetIPStateListener
{
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
44
class
MACAddressEthernetInfo
final :
public
Component
,
public
text_sensor::TextSensor
{
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
esphome::Component
Definition
component.h:147
esphome::ethernet::EthernetIPStateListener
Listener interface for Ethernet IP state changes.
Definition
ethernet_component.h:68
esphome::ethernet_info::DNSAddressEthernetInfo
Definition
ethernet_info_text_sensor.h:33
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:36
esphome::ethernet_info::DNSAddressEthernetInfo::setup
void setup() override
Definition
ethernet_info_text_sensor.cpp:32
esphome::ethernet_info::DNSAddressEthernetInfo::dump_config
void dump_config() override
Definition
ethernet_info_text_sensor.cpp:34
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::ip_sensors_
std::array< text_sensor::TextSensor *, 5 > ip_sensors_
Definition
ethernet_info_text_sensor.h:28
esphome::ethernet_info::IPAddressEthernetInfo::setup
void setup() override
Definition
ethernet_info_text_sensor.cpp:11
esphome::ethernet_info::IPAddressEthernetInfo::add_ip_sensors
void add_ip_sensors(uint8_t index, text_sensor::TextSensor *s)
Definition
ethernet_info_text_sensor.h:21
esphome::ethernet_info::MACAddressEthernetInfo
Definition
ethernet_info_text_sensor.h:44
esphome::ethernet_info::MACAddressEthernetInfo::get_setup_priority
float get_setup_priority() const override
Definition
ethernet_info_text_sensor.h:50
esphome::ethernet_info::MACAddressEthernetInfo::setup
void setup() override
Definition
ethernet_info_text_sensor.h:46
esphome::ethernet_info::MACAddressEthernetInfo::dump_config
void dump_config() override
Definition
ethernet_info_text_sensor.cpp:48
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:369
esphome::setup_priority::ETHERNET
constexpr float ETHERNET
Definition
component.h:51
esphome::network::IPAddress
Definition
ip_address.h:109
text_sensor.h
Generated by
1.12.0