mirror of
https://github.com/esphome/esphome.git
synced 2024-11-21 22:48:10 +01:00
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:
parent
4ac72d7d08
commit
41b5cb06d3
8 changed files with 92 additions and 0 deletions
|
@ -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
|
||||||
|
|
1
esphome/components/ethernet_info/__init__.py
Normal file
1
esphome/components/ethernet_info/__init__.py
Normal file
|
@ -0,0 +1 @@
|
||||||
|
CODEOWNERS = ["@gtjadsonsantos"]
|
|
@ -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
|
35
esphome/components/ethernet_info/ethernet_info_text_sensor.h
Normal file
35
esphome/components/ethernet_info/ethernet_info_text_sensor.h
Normal 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
|
34
esphome/components/ethernet_info/text_sensor.py
Normal file
34
esphome/components/ethernet_info/text_sensor.py
Normal 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)
|
|
@ -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;
|
||||||
|
|
|
@ -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.
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue