ESPHome
2025.9.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_ESP32
8
9
namespace
esphome
{
10
namespace
ethernet_info {
11
12
class
IPAddressEthernetInfo
:
public
PollingComponent
,
public
text_sensor::TextSensor
{
13
public
:
14
void
update
()
override
{
15
auto
ips =
ethernet::global_eth_component
->
get_ip_addresses
();
16
if
(ips != this->
last_ips_
) {
17
this->
last_ips_
= ips;
18
this->
publish_state
(ips[0].str());
19
uint8_t sensor = 0;
20
for
(
auto
&ip : ips) {
21
if
(ip.is_set()) {
22
if
(this->
ip_sensors_
[sensor] !=
nullptr
) {
23
this->
ip_sensors_
[sensor]->publish_state(ip.str());
24
}
25
sensor++;
26
}
27
}
28
}
29
}
30
31
float
get_setup_priority
()
const override
{
return
setup_priority::ETHERNET
; }
32
void
dump_config
()
override
;
33
void
add_ip_sensors
(uint8_t index,
text_sensor::TextSensor
*s) { this->
ip_sensors_
[index] = s; }
34
35
protected
:
36
network::IPAddresses
last_ips_
;
37
std::array<text_sensor::TextSensor *, 5>
ip_sensors_
;
38
};
39
40
class
DNSAddressEthernetInfo
:
public
PollingComponent
,
public
text_sensor::TextSensor
{
41
public
:
42
void
update
()
override
{
43
auto
dns_one =
ethernet::global_eth_component
->
get_dns_address
(0);
44
auto
dns_two =
ethernet::global_eth_component
->
get_dns_address
(1);
45
46
std::string dns_results = dns_one.
str
() +
" "
+ dns_two.str();
47
48
if
(dns_results != this->
last_results_
) {
49
this->
last_results_
= dns_results;
50
this->
publish_state
(dns_results);
51
}
52
}
53
float
get_setup_priority
()
const override
{
return
setup_priority::ETHERNET
; }
54
void
dump_config
()
override
;
55
56
protected
:
57
std::string
last_results_
;
58
};
59
60
class
MACAddressEthernetInfo
:
public
Component
,
public
text_sensor::TextSensor
{
61
public
:
62
void
setup
()
override
{ this->
publish_state
(
ethernet::global_eth_component
->get_eth_mac_address_pretty()); }
63
float
get_setup_priority
()
const override
{
return
setup_priority::ETHERNET
; }
64
void
dump_config
()
override
;
65
};
66
67
}
// namespace ethernet_info
68
}
// namespace esphome
69
70
#endif
// USE_ESP32
esphome::Component
Definition
component.h:71
esphome::PollingComponent
This class simplifies creating components that periodically check a state.
Definition
component.h:425
esphome::ethernet::EthernetComponent::get_ip_addresses
network::IPAddresses get_ip_addresses()
Definition
ethernet_component.cpp:397
esphome::ethernet::EthernetComponent::get_dns_address
network::IPAddress get_dns_address(uint8_t num)
Definition
ethernet_component.cpp:421
esphome::ethernet_info::DNSAddressEthernetInfo
Definition
ethernet_info_text_sensor.h:40
esphome::ethernet_info::DNSAddressEthernetInfo::update
void update() override
Definition
ethernet_info_text_sensor.h:42
esphome::ethernet_info::DNSAddressEthernetInfo::get_setup_priority
float get_setup_priority() const override
Definition
ethernet_info_text_sensor.h:53
esphome::ethernet_info::DNSAddressEthernetInfo::last_results_
std::string last_results_
Definition
ethernet_info_text_sensor.h:57
esphome::ethernet_info::DNSAddressEthernetInfo::dump_config
void dump_config() override
Definition
ethernet_info_text_sensor.cpp:12
esphome::ethernet_info::IPAddressEthernetInfo
Definition
ethernet_info_text_sensor.h:12
esphome::ethernet_info::IPAddressEthernetInfo::dump_config
void dump_config() override
Definition
ethernet_info_text_sensor.cpp:11
esphome::ethernet_info::IPAddressEthernetInfo::last_ips_
network::IPAddresses last_ips_
Definition
ethernet_info_text_sensor.h:36
esphome::ethernet_info::IPAddressEthernetInfo::update
void update() override
Definition
ethernet_info_text_sensor.h:14
esphome::ethernet_info::IPAddressEthernetInfo::get_setup_priority
float get_setup_priority() const override
Definition
ethernet_info_text_sensor.h:31
esphome::ethernet_info::IPAddressEthernetInfo::ip_sensors_
std::array< text_sensor::TextSensor *, 5 > ip_sensors_
Definition
ethernet_info_text_sensor.h:37
esphome::ethernet_info::IPAddressEthernetInfo::add_ip_sensors
void add_ip_sensors(uint8_t index, text_sensor::TextSensor *s)
Definition
ethernet_info_text_sensor.h:33
esphome::ethernet_info::MACAddressEthernetInfo
Definition
ethernet_info_text_sensor.h:60
esphome::ethernet_info::MACAddressEthernetInfo::get_setup_priority
float get_setup_priority() const override
Definition
ethernet_info_text_sensor.h:63
esphome::ethernet_info::MACAddressEthernetInfo::setup
void setup() override
Definition
ethernet_info_text_sensor.h:62
esphome::ethernet_info::MACAddressEthernetInfo::dump_config
void dump_config() override
Definition
ethernet_info_text_sensor.cpp:13
esphome::text_sensor::TextSensor
Definition
text_sensor.h:32
esphome::text_sensor::TextSensor::publish_state
void publish_state(const std::string &state)
Definition
text_sensor.cpp:9
component.h
ethernet_component.h
esphome::ethernet::global_eth_component
EthernetComponent * global_eth_component
Definition
ethernet_component.cpp:38
esphome::network::IPAddresses
std::array< IPAddress, 5 > IPAddresses
Definition
ip_address.h:144
esphome::setup_priority::ETHERNET
const float ETHERNET
Definition
component.cpp:55
esphome
Providing packet encoding functions for exchanging data with a remote host.
Definition
a01nyub.cpp:7
esphome::network::IPAddress::str
std::string str() const
Definition
ip_address.h:52
text_sensor.h
Generated by
1.12.0