mirror of
https://github.com/esphome/esphome.git
synced 2026-10-27 08:22:25 +00:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c8561e3df8 | ||
|
|
b5862ecefc | ||
|
|
ea3b96b3d0 |
No files matched your search
@@ -17,16 +17,20 @@ void IPAddressEthernetInfo::on_ip_state(const network::IPAddresses &ips, const n
|
||||
char buf[network::IP_ADDRESS_BUFFER_SIZE];
|
||||
ips[0].str_to(buf);
|
||||
this->publish_state(buf);
|
||||
#ifdef ETHERNET_INFO_IP_SENSOR_COUNT
|
||||
uint8_t sensor = 0;
|
||||
for (const auto &ip : ips) {
|
||||
if (ip.is_set()) {
|
||||
if (this->ip_sensors_[sensor] != nullptr) {
|
||||
ip.str_to(buf);
|
||||
this->ip_sensors_[sensor]->publish_state(buf);
|
||||
}
|
||||
sensor++;
|
||||
if (!ip.is_set())
|
||||
continue;
|
||||
if (sensor == ETHERNET_INFO_IP_SENSOR_COUNT)
|
||||
break;
|
||||
if (this->ip_sensors_[sensor] != nullptr) {
|
||||
ip.str_to(buf);
|
||||
this->ip_sensors_[sensor]->publish_state(buf);
|
||||
}
|
||||
sensor++;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void DNSAddressEthernetInfo::setup() { ethernet::global_eth_component->add_ip_state_listener(this); }
|
||||
|
||||
@@ -18,14 +18,19 @@ class IPAddressEthernetInfo final : public Component,
|
||||
|
||||
void setup() override;
|
||||
void dump_config() override;
|
||||
#ifdef ETHERNET_INFO_IP_SENSOR_COUNT
|
||||
void add_ip_sensors(uint8_t index, text_sensor::TextSensor *s) { this->ip_sensors_[index] = s; }
|
||||
#endif
|
||||
|
||||
// EthernetIPStateListener interface
|
||||
void on_ip_state(const network::IPAddresses &ips, const network::IPAddress &dns1,
|
||||
const network::IPAddress &dns2) override;
|
||||
|
||||
protected:
|
||||
std::array<text_sensor::TextSensor *, 5> ip_sensors_{};
|
||||
#ifdef ETHERNET_INFO_IP_SENSOR_COUNT
|
||||
// Sized to the highest configured address_N
|
||||
std::array<text_sensor::TextSensor *, ETHERNET_INFO_IP_SENSOR_COUNT> ip_sensors_{};
|
||||
#endif
|
||||
};
|
||||
|
||||
class DNSAddressEthernetInfo final : public Component,
|
||||
|
||||
@@ -57,10 +57,13 @@ async def to_code(config: ConfigType) -> None:
|
||||
if conf := config.get(CONF_IP_ADDRESS):
|
||||
ip_info = await text_sensor.new_text_sensor(config[CONF_IP_ADDRESS])
|
||||
await cg.register_component(ip_info, config[CONF_IP_ADDRESS])
|
||||
for x in range(5):
|
||||
if sensor_conf := conf.get(f"address_{x}"):
|
||||
sens = await text_sensor.new_text_sensor(sensor_conf)
|
||||
cg.add(ip_info.add_ip_sensors(x, sens))
|
||||
indexes = [x for x in range(5) if f"address_{x}" in conf]
|
||||
if indexes:
|
||||
# Sized to the highest index, so add_ip_sensors(x) stays in range
|
||||
cg.add_define("ETHERNET_INFO_IP_SENSOR_COUNT", max(indexes) + 1)
|
||||
for x in indexes:
|
||||
sens = await text_sensor.new_text_sensor(conf[f"address_{x}"])
|
||||
cg.add(ip_info.add_ip_sensors(x, sens))
|
||||
if conf := config.get(CONF_DNS_ADDRESS):
|
||||
dns_info = await text_sensor.new_text_sensor(conf)
|
||||
await cg.register_component(dns_info, conf)
|
||||
|
||||
@@ -110,7 +110,10 @@ async def to_code(config: ConfigType) -> None:
|
||||
if conf := config.get(CONF_IP_ADDRESS):
|
||||
wifi_info = await text_sensor.new_text_sensor(config[CONF_IP_ADDRESS])
|
||||
await cg.register_component(wifi_info, config[CONF_IP_ADDRESS])
|
||||
for x in range(5):
|
||||
if sensor_conf := conf.get(f"address_{x}"):
|
||||
sens = await text_sensor.new_text_sensor(sensor_conf)
|
||||
cg.add(wifi_info.add_ip_sensors(x, sens))
|
||||
indexes = [x for x in range(5) if f"address_{x}" in conf]
|
||||
if indexes:
|
||||
# Sized to the highest index, so add_ip_sensors(x) stays in range
|
||||
cg.add_define("WIFI_INFO_IP_SENSOR_COUNT", max(indexes) + 1)
|
||||
for x in indexes:
|
||||
sens = await text_sensor.new_text_sensor(conf[f"address_{x}"])
|
||||
cg.add(wifi_info.add_ip_sensors(x, sens))
|
||||
@@ -26,16 +26,20 @@ void IPAddressWiFiInfo::on_ip_state(const network::IPAddresses &ips, const netwo
|
||||
char buf[network::IP_ADDRESS_BUFFER_SIZE];
|
||||
ips[0].str_to(buf);
|
||||
this->publish_state(buf);
|
||||
#ifdef WIFI_INFO_IP_SENSOR_COUNT
|
||||
uint8_t sensor = 0;
|
||||
for (const auto &ip : ips) {
|
||||
if (ip.is_set()) {
|
||||
if (this->ip_sensors_[sensor] != nullptr) {
|
||||
ip.str_to(buf);
|
||||
this->ip_sensors_[sensor]->publish_state(buf);
|
||||
}
|
||||
sensor++;
|
||||
if (!ip.is_set())
|
||||
continue;
|
||||
if (sensor == WIFI_INFO_IP_SENSOR_COUNT)
|
||||
break;
|
||||
if (this->ip_sensors_[sensor] != nullptr) {
|
||||
ip.str_to(buf);
|
||||
this->ip_sensors_[sensor]->publish_state(buf);
|
||||
}
|
||||
sensor++;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*********************
|
||||
|
||||
@@ -16,14 +16,19 @@ class IPAddressWiFiInfo final : public Component, public text_sensor::TextSensor
|
||||
public:
|
||||
void setup() override;
|
||||
void dump_config() override;
|
||||
#ifdef WIFI_INFO_IP_SENSOR_COUNT
|
||||
void add_ip_sensors(uint8_t index, text_sensor::TextSensor *s) { this->ip_sensors_[index] = s; }
|
||||
#endif
|
||||
|
||||
// WiFiIPStateListener interface
|
||||
void on_ip_state(const network::IPAddresses &ips, const network::IPAddress &dns1,
|
||||
const network::IPAddress &dns2) override;
|
||||
|
||||
protected:
|
||||
std::array<text_sensor::TextSensor *, 5> ip_sensors_{};
|
||||
#ifdef WIFI_INFO_IP_SENSOR_COUNT
|
||||
// Sized to the highest configured address_N
|
||||
std::array<text_sensor::TextSensor *, WIFI_INFO_IP_SENSOR_COUNT> ip_sensors_{};
|
||||
#endif
|
||||
};
|
||||
|
||||
class DNSAddressWifiInfo final : public Component, public text_sensor::TextSensor, public wifi::WiFiIPStateListener {
|
||||
|
||||
@@ -166,6 +166,7 @@
|
||||
#define LV_USE_LOG 1
|
||||
#define USE_MDNS
|
||||
#define USE_MDNS_STORE_SERVICES
|
||||
#define ETHERNET_INFO_IP_SENSOR_COUNT 5
|
||||
#define GPS_LISTENER_COUNT 1
|
||||
#define HDMI_CEC_MESSAGE_CALLBACK_COUNT 2
|
||||
#define I2C_PORT_FREQUENCY_COUNT 1
|
||||
@@ -193,6 +194,7 @@
|
||||
#define PYLONTECH_SENSOR_CELL_COUNT 2
|
||||
#define REMOTE_BASE_DUMPER_COUNT 1
|
||||
#define REMOTE_BASE_LISTENER_COUNT 1
|
||||
#define WIFI_INFO_IP_SENSOR_COUNT 5
|
||||
#define USE_REMOTE_PROTOCOL_ABBWELCOME
|
||||
#define USE_REMOTE_PROTOCOL_AEHA
|
||||
#define USE_REMOTE_PROTOCOL_AOK
|
||||
|
||||
@@ -17,6 +17,10 @@ text_sensor:
|
||||
- platform: ethernet_info
|
||||
ip_address:
|
||||
name: IP Address
|
||||
address_0:
|
||||
name: IP Address 0
|
||||
address_1:
|
||||
name: IP Address 1
|
||||
dns_address:
|
||||
name: DNS Address
|
||||
mac_address:
|
||||
|
||||
@@ -8,6 +8,8 @@ text_sensor:
|
||||
name: Scan Results
|
||||
ip_address:
|
||||
name: IP Address
|
||||
address_1:
|
||||
name: IP Address 1
|
||||
ssid:
|
||||
name: SSID
|
||||
bssid:
|
||||
|
||||
Reference in new issue
Block a user