ESPHome
2023.5.5
esphome
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_FRAMEWORK_ARDUINO
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
ip =
ethernet::global_eth_component
->
get_ip_address
();
16
if
(ip != this->
last_ip_
) {
17
this->
last_ip_
= ip;
18
this->
publish_state
(
network::IPAddress
(ip).str());
19
}
20
}
21
22
float
get_setup_priority
()
const override
{
return
setup_priority::ETHERNET
; }
23
std::string
unique_id
()
override
{
return
get_mac_address
() +
"-ethernetinfo"
; }
24
void
dump_config
()
override
;
25
26
protected
:
27
network::IPAddress
last_ip_
;
28
};
29
30
}
// namespace ethernet_info
31
}
// namespace esphome
32
33
#endif // USE_ESP32_FRAMEWORK_ARDUINO
esphome::ethernet::EthernetComponent::get_ip_address
network::IPAddress get_ip_address()
Definition:
ethernet_component.cpp:194
esphome::ethernet_info::IPAddressEthernetInfo
Definition:
ethernet_info_text_sensor.h:12
esphome::PollingComponent
This class simplifies creating components that periodically check a state.
Definition:
component.h:282
esphome::text_sensor::TextSensor::publish_state
void publish_state(const std::string &state)
Definition:
text_sensor.cpp:9
esphome::ethernet_info::IPAddressEthernetInfo::unique_id
std::string unique_id() override
Definition:
ethernet_info_text_sensor.h:23
esphome::ethernet::global_eth_component
EthernetComponent * global_eth_component
Definition:
ethernet_component.cpp:16
text_sensor.h
esphome::ethernet_info::IPAddressEthernetInfo::last_ip_
network::IPAddress last_ip_
Definition:
ethernet_info_text_sensor.h:27
esphome::text_sensor::TextSensor
Definition:
text_sensor.h:31
esphome::ethernet_info::IPAddressEthernetInfo::update
void update() override
Definition:
ethernet_info_text_sensor.h:14
esphome::get_mac_address
std::string get_mac_address()
Get the device MAC address as a string, in lowercase hex notation.
Definition:
helpers.cpp:480
esphome::network::IPAddress
Definition:
ip_address.h:10
esphome::setup_priority::ETHERNET
const float ETHERNET
Definition:
component.cpp:23
esphome::ethernet_info::IPAddressEthernetInfo::get_setup_priority
float get_setup_priority() const override
Definition:
ethernet_info_text_sensor.h:22
esphome::ethernet_info::IPAddressEthernetInfo::dump_config
void dump_config() override
Definition:
ethernet_info_text_sensor.cpp:11
esphome
Definition:
a4988.cpp:4
component.h
ethernet_component.h
Generated by
1.8.13