New platform ethernet_info from component text_sensor (#3811)

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
Jadson Santos 2022-10-18 21:44:48 -03:00 committed by GitHub
parent 4ac72d7d08
commit 41b5cb06d3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 92 additions and 0 deletions

View file

@ -76,6 +76,7 @@ esphome/components/esp32_camera_web_server/* @ayufan
esphome/components/esp32_can/* @Sympatron esphome/components/esp32_can/* @Sympatron
esphome/components/esp32_improv/* @jesserockz esphome/components/esp32_improv/* @jesserockz
esphome/components/esp8266/* @esphome/core esphome/components/esp8266/* @esphome/core
esphome/components/ethernet_info/* @gtjadsonsantos
esphome/components/exposure_notifications/* @OttoWinter esphome/components/exposure_notifications/* @OttoWinter
esphome/components/ezo/* @ssieb esphome/components/ezo/* @ssieb
esphome/components/factory_reset/* @anatoly-savchenkov esphome/components/factory_reset/* @anatoly-savchenkov

View file

@ -0,0 +1 @@
CODEOWNERS = ["@gtjadsonsantos"]

View file

@ -0,0 +1,16 @@
#include "ethernet_info_text_sensor.h"
#include "esphome/core/log.h"
#ifdef USE_ESP32_FRAMEWORK_ARDUINO
namespace esphome {
namespace ethernet_info {
static const char *const TAG = "ethernet_info";
void IPAddressEthernetInfo::dump_config() { LOG_TEXT_SENSOR("", "EthernetInfo IPAddress", this); }
} // namespace ethernet_info
} // namespace esphome
#endif // USE_ESP32_FRAMEWORK_ARDUINO

View file

@ -0,0 +1,35 @@
#pragma once
#include "esphome/core/component.h"
#include "esphome/components/text_sensor/text_sensor.h"
#include "esphome/components/ethernet/ethernet_component.h"
#ifdef USE_ESP32_FRAMEWORK_ARDUINO
namespace esphome {
namespace ethernet_info {
class IPAddressEthernetInfo : public PollingComponent, public text_sensor::TextSensor {
public:
void update() override {
tcpip_adapter_ip_info_t tcpip;
tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_ETH, &tcpip);
auto ip = tcpip.ip.addr;
if (ip != this->last_ip_) {
this->last_ip_ = ip;
this->publish_state(network::IPAddress(ip).str());
}
}
float get_setup_priority() const override { return setup_priority::ETHERNET; }
std::string unique_id() override { return get_mac_address() + "-ethernetinfo"; }
void dump_config() override;
protected:
network::IPAddress last_ip_;
};
} // namespace ethernet_info
} // namespace esphome
#endif // USE_ESP32_FRAMEWORK_ARDUINO

View file

@ -0,0 +1,34 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import text_sensor
from esphome.const import (
CONF_IP_ADDRESS,
ENTITY_CATEGORY_DIAGNOSTIC,
)
DEPENDENCIES = ["ethernet"]
ethernet_info_ns = cg.esphome_ns.namespace("ethernet_info")
IPAddressEsthernetInfo = ethernet_info_ns.class_(
"IPAddressEthernetInfo", text_sensor.TextSensor, cg.PollingComponent
)
CONFIG_SCHEMA = cv.Schema(
{
cv.Optional(CONF_IP_ADDRESS): text_sensor.text_sensor_schema(
IPAddressEsthernetInfo, entity_category=ENTITY_CATEGORY_DIAGNOSTIC
).extend(cv.polling_component_schema("1s"))
}
)
async def setup_conf(config, key):
if key in config:
conf = config[key]
var = await text_sensor.new_text_sensor(conf)
await cg.register_component(var, conf)
async def to_code(config):
await setup_conf(config, CONF_IP_ADDRESS)

View file

@ -20,6 +20,7 @@ const float PROCESSOR = 400.0;
const float BLUETOOTH = 350.0f; const float BLUETOOTH = 350.0f;
const float AFTER_BLUETOOTH = 300.0f; const float AFTER_BLUETOOTH = 300.0f;
const float WIFI = 250.0f; const float WIFI = 250.0f;
const float ETHERNET = 250.0f;
const float BEFORE_CONNECTION = 220.0f; const float BEFORE_CONNECTION = 220.0f;
const float AFTER_WIFI = 200.0f; const float AFTER_WIFI = 200.0f;
const float AFTER_CONNECTION = 100.0f; const float AFTER_CONNECTION = 100.0f;

View file

@ -29,6 +29,7 @@ extern const float PROCESSOR;
extern const float BLUETOOTH; extern const float BLUETOOTH;
extern const float AFTER_BLUETOOTH; extern const float AFTER_BLUETOOTH;
extern const float WIFI; extern const float WIFI;
extern const float ETHERNET;
/// For components that should be initialized after WiFi and before API is connected. /// For components that should be initialized after WiFi and before API is connected.
extern const float BEFORE_CONNECTION; extern const float BEFORE_CONNECTION;
/// For components that should be initialized after WiFi is connected. /// For components that should be initialized after WiFi is connected.

View file

@ -532,6 +532,9 @@ text_sensor:
- platform: copy - platform: copy
source_id: inverter0_device_mode source_id: inverter0_device_mode
name: Inverter Text Sensor Copy name: Inverter Text Sensor Copy
- platform: ethernet_info
ip_address:
name: IP Address
output: output:
- platform: pipsolar - platform: pipsolar