Compare commits
7 Commits
jesserockz
...
remove-uni
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5fd8676151 | ||
|
|
f614655af5 | ||
|
|
cdb67fc90e | ||
|
|
78cb098691 | ||
|
|
45152ad55e | ||
|
|
45879e3100 | ||
|
|
c4adb30ab2 |
@@ -1,6 +1,6 @@
|
||||
#include "adc_sensor.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
#ifdef USE_ESP8266
|
||||
#ifdef USE_ADC_SENSOR_VCC
|
||||
@@ -254,9 +254,5 @@ float ADCSensor::sample() {
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef USE_ESP8266
|
||||
std::string ADCSensor::unique_id() { return get_mac_address() + "-adc"; }
|
||||
#endif
|
||||
|
||||
} // namespace adc
|
||||
} // namespace esphome
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/core/hal.h"
|
||||
#include "esphome/core/defines.h"
|
||||
#include "esphome/components/sensor/sensor.h"
|
||||
#include "esphome/components/voltage_sampler/voltage_sampler.h"
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/core/defines.h"
|
||||
#include "esphome/core/hal.h"
|
||||
|
||||
#ifdef USE_ESP32
|
||||
#include "driver/adc.h"
|
||||
#include <esp_adc_cal.h>
|
||||
#include "driver/adc.h"
|
||||
#endif
|
||||
|
||||
namespace esphome {
|
||||
@@ -41,10 +41,6 @@ class ADCSensor : public sensor::Sensor, public PollingComponent, public voltage
|
||||
void set_output_raw(bool output_raw) { output_raw_ = output_raw; }
|
||||
float sample() override;
|
||||
|
||||
#ifdef USE_ESP8266
|
||||
std::string unique_id() override;
|
||||
#endif
|
||||
|
||||
#ifdef USE_RP2040
|
||||
void set_is_temperature() { is_temperature_ = true; }
|
||||
#endif
|
||||
|
||||
@@ -161,7 +161,7 @@ void APIConnection::loop() {
|
||||
}
|
||||
|
||||
std::string get_default_unique_id(const std::string &component_type, EntityBase *entity) {
|
||||
return App.get_name() + component_type + entity->get_object_id();
|
||||
return get_mac_address_pretty() + "-" + component_type + "-" + entity->get_object_id();
|
||||
}
|
||||
|
||||
DisconnectResponse APIConnection::disconnect(const DisconnectRequest &msg) {
|
||||
@@ -437,9 +437,7 @@ bool APIConnection::send_sensor_info(sensor::Sensor *sensor) {
|
||||
msg.object_id = sensor->get_object_id();
|
||||
if (sensor->has_own_name())
|
||||
msg.name = sensor->get_name();
|
||||
msg.unique_id = sensor->unique_id();
|
||||
if (msg.unique_id.empty())
|
||||
msg.unique_id = get_default_unique_id("sensor", sensor);
|
||||
msg.unique_id = get_default_unique_id("sensor", sensor);
|
||||
msg.icon = sensor->get_icon();
|
||||
msg.unit_of_measurement = sensor->get_unit_of_measurement();
|
||||
msg.accuracy_decimals = sensor->get_accuracy_decimals();
|
||||
@@ -505,9 +503,7 @@ bool APIConnection::send_text_sensor_info(text_sensor::TextSensor *text_sensor)
|
||||
msg.key = text_sensor->get_object_id_hash();
|
||||
msg.object_id = text_sensor->get_object_id();
|
||||
msg.name = text_sensor->get_name();
|
||||
msg.unique_id = text_sensor->unique_id();
|
||||
if (msg.unique_id.empty())
|
||||
msg.unique_id = get_default_unique_id("text_sensor", text_sensor);
|
||||
msg.unique_id = get_default_unique_id("text_sensor", text_sensor);
|
||||
msg.icon = text_sensor->get_icon();
|
||||
msg.disabled_by_default = text_sensor->is_disabled_by_default();
|
||||
msg.entity_category = static_cast<enums::EntityCategory>(text_sensor->get_entity_category());
|
||||
|
||||
@@ -273,7 +273,6 @@ float DallasTemperatureSensor::get_temp_c() {
|
||||
|
||||
return temp / 128.0f;
|
||||
}
|
||||
std::string DallasTemperatureSensor::unique_id() { return "dallas-" + str_lower_case(format_hex(this->address_)); }
|
||||
|
||||
} // namespace dallas
|
||||
} // namespace esphome
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/components/sensor/sensor.h"
|
||||
#include "esp_one_wire.h"
|
||||
#include "esphome/components/sensor/sensor.h"
|
||||
#include "esphome/core/component.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
@@ -60,8 +60,6 @@ class DallasTemperatureSensor : public sensor::Sensor {
|
||||
|
||||
float get_temp_c();
|
||||
|
||||
std::string unique_id() override;
|
||||
|
||||
protected:
|
||||
DallasComponent *parent_;
|
||||
uint64_t address_;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#ifdef USE_ESP32
|
||||
#include "esp32_hall.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/core/hal.h"
|
||||
#include <driver/adc.h>
|
||||
#include "esphome/core/hal.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace esp32_hall {
|
||||
@@ -16,7 +16,6 @@ void ESP32HallSensor::update() {
|
||||
ESP_LOGD(TAG, "'%s': Got reading %.0f µT", this->name_.c_str(), value);
|
||||
this->publish_state(value);
|
||||
}
|
||||
std::string ESP32HallSensor::unique_id() { return get_mac_address() + "-hall"; }
|
||||
void ESP32HallSensor::dump_config() { LOG_SENSOR("", "ESP32 Hall Sensor", this); }
|
||||
|
||||
} // namespace esp32_hall
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/components/sensor/sensor.h"
|
||||
#include "esphome/core/component.h"
|
||||
|
||||
#ifdef USE_ESP32
|
||||
|
||||
@@ -13,8 +13,6 @@ class ESP32HallSensor : public sensor::Sensor, public PollingComponent {
|
||||
void dump_config() override;
|
||||
|
||||
void update() override;
|
||||
|
||||
std::string unique_id() override;
|
||||
};
|
||||
|
||||
} // namespace esp32_hall
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/components/text_sensor/text_sensor.h"
|
||||
#include "esphome/components/ethernet/ethernet_component.h"
|
||||
#include "esphome/components/text_sensor/text_sensor.h"
|
||||
#include "esphome/core/component.h"
|
||||
|
||||
#ifdef USE_ESP32
|
||||
|
||||
@@ -20,7 +20,6 @@ class IPAddressEthernetInfo : public PollingComponent, public text_sensor::TextS
|
||||
}
|
||||
|
||||
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:
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
#ifdef USE_MQTT
|
||||
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/core/application.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/core/version.h"
|
||||
|
||||
#include "mqtt_const.h"
|
||||
@@ -111,21 +111,16 @@ bool MQTTComponent::send_discovery_() {
|
||||
root[MQTT_PAYLOAD_NOT_AVAILABLE] = this->availability_->payload_not_available;
|
||||
}
|
||||
|
||||
std::string unique_id = this->unique_id();
|
||||
const MQTTDiscoveryInfo &discovery_info = global_mqtt_client->get_discovery_info();
|
||||
if (!unique_id.empty()) {
|
||||
root[MQTT_UNIQUE_ID] = unique_id;
|
||||
if (discovery_info.unique_id_generator == MQTT_MAC_ADDRESS_UNIQUE_ID_GENERATOR) {
|
||||
char friendly_name_hash[9];
|
||||
sprintf(friendly_name_hash, "%08" PRIx32, fnv1_hash(this->friendly_name()));
|
||||
friendly_name_hash[8] = 0; // ensure the hash-string ends with null
|
||||
root[MQTT_UNIQUE_ID] = get_mac_address() + "-" + this->component_type() + "-" + friendly_name_hash;
|
||||
} else {
|
||||
if (discovery_info.unique_id_generator == MQTT_MAC_ADDRESS_UNIQUE_ID_GENERATOR) {
|
||||
char friendly_name_hash[9];
|
||||
sprintf(friendly_name_hash, "%08" PRIx32, fnv1_hash(this->friendly_name()));
|
||||
friendly_name_hash[8] = 0; // ensure the hash-string ends with null
|
||||
root[MQTT_UNIQUE_ID] = get_mac_address() + "-" + this->component_type() + "-" + friendly_name_hash;
|
||||
} else {
|
||||
// default to almost-unique ID. It's a hack but the only way to get that
|
||||
// gorgeous device registry view.
|
||||
root[MQTT_UNIQUE_ID] = "ESP" + this->component_type() + this->get_default_object_id_();
|
||||
}
|
||||
// default to almost-unique ID. It's a hack but the only way to get that
|
||||
// gorgeous device registry view.
|
||||
root[MQTT_UNIQUE_ID] = "ESP" + this->component_type() + this->get_default_object_id_();
|
||||
}
|
||||
|
||||
const std::string &node_name = App.get_name();
|
||||
@@ -233,7 +228,6 @@ void MQTTComponent::call_dump_config() {
|
||||
this->dump_config();
|
||||
}
|
||||
void MQTTComponent::schedule_resend_state() { this->resend_state_ = true; }
|
||||
std::string MQTTComponent::unique_id() { return ""; }
|
||||
bool MQTTComponent::is_connected_() const { return global_mqtt_client->is_connected(); }
|
||||
|
||||
// Pull these properties from EntityBase if not overridden
|
||||
|
||||
@@ -156,13 +156,6 @@ class MQTTComponent : public Component {
|
||||
*/
|
||||
virtual const EntityBase *get_entity() const = 0;
|
||||
|
||||
/** A unique ID for this MQTT component, empty for no unique id. See unique ID requirements:
|
||||
* https://developers.home-assistant.io/docs/en/entity_registry_index.html#unique-id-requirements
|
||||
*
|
||||
* @return The unique id as a string.
|
||||
*/
|
||||
virtual std::string unique_id();
|
||||
|
||||
/// Get the friendly name of this MQTT component.
|
||||
virtual std::string friendly_name() const;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <cinttypes>
|
||||
#include "mqtt_sensor.h"
|
||||
#include <cinttypes>
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
#include "mqtt_const.h"
|
||||
@@ -72,7 +72,6 @@ bool MQTTSensorComponent::publish_state(float value) {
|
||||
int8_t accuracy = this->sensor_->get_accuracy_decimals();
|
||||
return this->publish(this->get_state_topic_(), value_accuracy_to_string(value, accuracy));
|
||||
}
|
||||
std::string MQTTSensorComponent::unique_id() { return this->sensor_->unique_id(); }
|
||||
|
||||
} // namespace mqtt
|
||||
} // namespace esphome
|
||||
|
||||
@@ -46,7 +46,6 @@ class MQTTSensorComponent : public mqtt::MQTTComponent {
|
||||
/// Override for MQTTComponent, returns "sensor".
|
||||
std::string component_type() const override;
|
||||
const EntityBase *get_entity() const override;
|
||||
std::string unique_id() override;
|
||||
|
||||
sensor::Sensor *sensor_;
|
||||
optional<uint32_t> expire_after_; // Override the expire after advertised to Home Assistant
|
||||
|
||||
@@ -34,7 +34,6 @@ bool MQTTTextSensor::send_initial_state() {
|
||||
}
|
||||
std::string MQTTTextSensor::component_type() const { return "sensor"; }
|
||||
const EntityBase *MQTTTextSensor::get_entity() const { return this->sensor_; }
|
||||
std::string MQTTTextSensor::unique_id() { return this->sensor_->unique_id(); }
|
||||
|
||||
} // namespace mqtt
|
||||
} // namespace esphome
|
||||
|
||||
@@ -28,7 +28,6 @@ class MQTTTextSensor : public mqtt::MQTTComponent {
|
||||
protected:
|
||||
std::string component_type() const override;
|
||||
const EntityBase *get_entity() const override;
|
||||
std::string unique_id() override;
|
||||
|
||||
text_sensor::TextSensor *sensor_;
|
||||
};
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components.esp32 import add_idf_sdkconfig_option
|
||||
from esphome.components.esp32 import add_idf_sdkconfig_option, get_esp32_variant
|
||||
from esphome.core import CORE
|
||||
from esphome.const import (
|
||||
CONF_ID,
|
||||
CONF_MODE,
|
||||
CONF_SPEED,
|
||||
)
|
||||
|
||||
CODEOWNERS = ["@esphome/core"]
|
||||
@@ -11,8 +13,26 @@ CODEOWNERS = ["@esphome/core"]
|
||||
psram_ns = cg.esphome_ns.namespace("psram")
|
||||
PsramComponent = psram_ns.class_("PsramComponent", cg.Component)
|
||||
|
||||
SPIRAM_MODES = {
|
||||
"quad": "CONFIG_SPIRAM_MODE_QUAD",
|
||||
"octal": "CONFIG_SPIRAM_MODE_OCT",
|
||||
}
|
||||
|
||||
SPIRAM_SPEEDS = {
|
||||
40e6: "CONFIG_SPIRAM_SPEED_40M",
|
||||
80e6: "CONFIG_SPIRAM_SPEED_80M",
|
||||
120e6: "CONFIG_SPIRAM_SPEED_120M",
|
||||
}
|
||||
|
||||
CONFIG_SCHEMA = cv.All(
|
||||
cv.Schema({cv.GenerateID(): cv.declare_id(PsramComponent)}), cv.only_on_esp32
|
||||
cv.Schema(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(PsramComponent),
|
||||
cv.Optional(CONF_MODE): cv.enum(SPIRAM_MODES, lower=True),
|
||||
cv.Optional(CONF_SPEED): cv.All(cv.frequency, cv.one_of(*SPIRAM_SPEEDS)),
|
||||
}
|
||||
),
|
||||
cv.only_on_esp32,
|
||||
)
|
||||
|
||||
|
||||
@@ -21,9 +41,18 @@ async def to_code(config):
|
||||
cg.add_build_flag("-DBOARD_HAS_PSRAM")
|
||||
|
||||
if CORE.using_esp_idf:
|
||||
add_idf_sdkconfig_option("CONFIG_ESP32_SPIRAM_SUPPORT", True)
|
||||
add_idf_sdkconfig_option(
|
||||
f"CONFIG_{get_esp32_variant().upper()}_SPIRAM_SUPPORT", True
|
||||
)
|
||||
add_idf_sdkconfig_option("CONFIG_SPIRAM", True)
|
||||
add_idf_sdkconfig_option("CONFIG_SPIRAM_USE", True)
|
||||
add_idf_sdkconfig_option("CONFIG_SPIRAM_USE_CAPS_ALLOC", True)
|
||||
add_idf_sdkconfig_option("CONFIG_SPIRAM_IGNORE_NOTFOUND", True)
|
||||
|
||||
if CONF_MODE in config:
|
||||
add_idf_sdkconfig_option(f"{SPIRAM_MODES[config[CONF_MODE]]}", True)
|
||||
if CONF_SPEED in config:
|
||||
add_idf_sdkconfig_option(f"{SPIRAM_SPEEDS[config[CONF_SPEED]]}", True)
|
||||
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
await cg.register_component(var, config)
|
||||
|
||||
@@ -85,7 +85,6 @@ void Sensor::clear_filters() {
|
||||
}
|
||||
float Sensor::get_state() const { return this->state; }
|
||||
float Sensor::get_raw_state() const { return this->raw_state; }
|
||||
std::string Sensor::unique_id() { return ""; }
|
||||
|
||||
void Sensor::internal_send_state_to_frontend(float state) {
|
||||
this->has_state_ = true;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/components/sensor/filter.h"
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/core/entity_base.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/components/sensor/filter.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
@@ -23,9 +23,6 @@ namespace sensor {
|
||||
if (!(obj)->get_icon().empty()) { \
|
||||
ESP_LOGCONFIG(TAG, "%s Icon: '%s'", prefix, (obj)->get_icon().c_str()); \
|
||||
} \
|
||||
if (!(obj)->unique_id().empty()) { \
|
||||
ESP_LOGV(TAG, "%s Unique ID: '%s'", prefix, (obj)->unique_id().c_str()); \
|
||||
} \
|
||||
if ((obj)->get_force_update()) { \
|
||||
ESP_LOGV(TAG, "%s Force Update: YES", prefix); \
|
||||
} \
|
||||
@@ -139,12 +136,6 @@ class Sensor : public EntityBase, public EntityBase_DeviceClass, public EntityBa
|
||||
/// Return whether this sensor has gotten a full state (that passed through all filters) yet.
|
||||
bool has_state() const;
|
||||
|
||||
/** Override this method to set the unique ID of this sensor.
|
||||
*
|
||||
* @deprecated Do not use for new sensors, a suitable unique ID is automatically generated (2023.4).
|
||||
*/
|
||||
virtual std::string unique_id();
|
||||
|
||||
void internal_send_state_to_frontend(float state);
|
||||
|
||||
protected:
|
||||
|
||||
@@ -19,6 +19,7 @@ void ST7789V::setup() {
|
||||
|
||||
this->write_command_(ST7789_SLPOUT); // Sleep out
|
||||
delay(120); // NOLINT
|
||||
this->write_command_(ST7789_SLPOUT); //
|
||||
|
||||
this->write_command_(ST7789_NORON); // Normal display mode on
|
||||
|
||||
|
||||
@@ -65,7 +65,6 @@ void TextSensor::internal_send_state_to_frontend(const std::string &state) {
|
||||
this->callback_.call(state);
|
||||
}
|
||||
|
||||
std::string TextSensor::unique_id() { return ""; }
|
||||
bool TextSensor::has_state() { return this->has_state_; }
|
||||
|
||||
} // namespace text_sensor
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/text_sensor/filter.h"
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/core/entity_base.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/components/text_sensor/filter.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
@@ -16,9 +16,6 @@ namespace text_sensor {
|
||||
if (!(obj)->get_icon().empty()) { \
|
||||
ESP_LOGCONFIG(TAG, "%s Icon: '%s'", prefix, (obj)->get_icon().c_str()); \
|
||||
} \
|
||||
if (!(obj)->unique_id().empty()) { \
|
||||
ESP_LOGV(TAG, "%s Unique ID: '%s'", prefix, (obj)->unique_id().c_str()); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define SUB_TEXT_SENSOR(name) \
|
||||
@@ -58,12 +55,6 @@ class TextSensor : public EntityBase {
|
||||
|
||||
// ========== INTERNAL METHODS ==========
|
||||
// (In most use cases you won't need these)
|
||||
/** Override this method to set the unique ID of this sensor.
|
||||
*
|
||||
* @deprecated Do not use for new sensors, a suitable unique ID is automatically generated (2023.4).
|
||||
*/
|
||||
virtual std::string unique_id();
|
||||
|
||||
bool has_state();
|
||||
|
||||
void internal_send_state_to_frontend(const std::string &state);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "uptime_sensor.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/core/hal.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace uptime {
|
||||
@@ -26,7 +26,6 @@ void UptimeSensor::update() {
|
||||
const float seconds = float(seconds_int) + (this->uptime_ % 1000ULL) / 1000.0f;
|
||||
this->publish_state(seconds);
|
||||
}
|
||||
std::string UptimeSensor::unique_id() { return get_mac_address() + "-uptime"; }
|
||||
float UptimeSensor::get_setup_priority() const { return setup_priority::HARDWARE; }
|
||||
void UptimeSensor::dump_config() { LOG_SENSOR("", "Uptime Sensor", this); }
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/components/sensor/sensor.h"
|
||||
#include "esphome/core/component.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace uptime {
|
||||
@@ -13,8 +13,6 @@ class UptimeSensor : public sensor::Sensor, public PollingComponent {
|
||||
|
||||
float get_setup_priority() const override;
|
||||
|
||||
std::string unique_id() override;
|
||||
|
||||
protected:
|
||||
uint64_t uptime_{0};
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "version_text_sensor.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/core/application.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/core/version.h"
|
||||
|
||||
namespace esphome {
|
||||
@@ -17,7 +17,6 @@ void VersionTextSensor::setup() {
|
||||
}
|
||||
float VersionTextSensor::get_setup_priority() const { return setup_priority::DATA; }
|
||||
void VersionTextSensor::set_hide_timestamp(bool hide_timestamp) { this->hide_timestamp_ = hide_timestamp; }
|
||||
std::string VersionTextSensor::unique_id() { return get_mac_address() + "-version"; }
|
||||
void VersionTextSensor::dump_config() { LOG_TEXT_SENSOR("", "Version Text Sensor", this); }
|
||||
|
||||
} // namespace version
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/components/text_sensor/text_sensor.h"
|
||||
#include "esphome/core/component.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace version {
|
||||
@@ -12,7 +12,6 @@ class VersionTextSensor : public text_sensor::TextSensor, public Component {
|
||||
void setup() override;
|
||||
void dump_config() override;
|
||||
float get_setup_priority() const override;
|
||||
std::string unique_id() override;
|
||||
|
||||
protected:
|
||||
bool hide_timestamp_{false};
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/components/text_sensor/text_sensor.h"
|
||||
#include "esphome/components/wifi/wifi_component.h"
|
||||
#include "esphome/core/component.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace wifi_info {
|
||||
@@ -17,7 +17,6 @@ class IPAddressWiFiInfo : public PollingComponent, public text_sensor::TextSenso
|
||||
}
|
||||
}
|
||||
float get_setup_priority() const override { return setup_priority::AFTER_WIFI; }
|
||||
std::string unique_id() override { return get_mac_address() + "-wifiinfo-ip"; }
|
||||
void dump_config() override;
|
||||
|
||||
protected:
|
||||
@@ -43,7 +42,6 @@ class DNSAddressWifiInfo : public PollingComponent, public text_sensor::TextSens
|
||||
}
|
||||
}
|
||||
float get_setup_priority() const override { return setup_priority::AFTER_WIFI; }
|
||||
std::string unique_id() override { return get_mac_address() + "-wifiinfo-dns"; }
|
||||
void dump_config() override;
|
||||
|
||||
protected:
|
||||
@@ -72,7 +70,6 @@ class ScanResultsWiFiInfo : public PollingComponent, public text_sensor::TextSen
|
||||
}
|
||||
}
|
||||
float get_setup_priority() const override { return setup_priority::AFTER_WIFI; }
|
||||
std::string unique_id() override { return get_mac_address() + "-wifiinfo-scanresults"; }
|
||||
void dump_config() override;
|
||||
|
||||
protected:
|
||||
@@ -89,7 +86,6 @@ class SSIDWiFiInfo : public PollingComponent, public text_sensor::TextSensor {
|
||||
}
|
||||
}
|
||||
float get_setup_priority() const override { return setup_priority::AFTER_WIFI; }
|
||||
std::string unique_id() override { return get_mac_address() + "-wifiinfo-ssid"; }
|
||||
void dump_config() override;
|
||||
|
||||
protected:
|
||||
@@ -108,7 +104,6 @@ class BSSIDWiFiInfo : public PollingComponent, public text_sensor::TextSensor {
|
||||
}
|
||||
}
|
||||
float get_setup_priority() const override { return setup_priority::AFTER_WIFI; }
|
||||
std::string unique_id() override { return get_mac_address() + "-wifiinfo-bssid"; }
|
||||
void dump_config() override;
|
||||
|
||||
protected:
|
||||
@@ -118,7 +113,6 @@ class BSSIDWiFiInfo : public PollingComponent, public text_sensor::TextSensor {
|
||||
class MacAddressWifiInfo : public Component, public text_sensor::TextSensor {
|
||||
public:
|
||||
void setup() override { this->publish_state(get_mac_address_pretty()); }
|
||||
std::string unique_id() override { return get_mac_address() + "-wifiinfo-macadr"; }
|
||||
void dump_config() override;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/components/sensor/sensor.h"
|
||||
#include "esphome/components/wifi/wifi_component.h"
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace wifi_signal {
|
||||
@@ -12,8 +12,6 @@ class WiFiSignalSensor : public sensor::Sensor, public PollingComponent {
|
||||
public:
|
||||
void update() override { this->publish_state(wifi::global_wifi_component->wifi_rssi()); }
|
||||
void dump_config() override;
|
||||
|
||||
std::string unique_id() override { return get_mac_address() + "-wifisignal"; }
|
||||
float get_setup_priority() const override { return setup_priority::AFTER_WIFI; }
|
||||
};
|
||||
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
import logging
|
||||
import socket
|
||||
import threading
|
||||
import time
|
||||
from typing import Optional
|
||||
import logging
|
||||
from dataclasses import dataclass
|
||||
from typing import Optional
|
||||
|
||||
from zeroconf import (
|
||||
DNSAddress,
|
||||
DNSOutgoing,
|
||||
DNSRecord,
|
||||
DNSQuestion,
|
||||
RecordUpdate,
|
||||
RecordUpdateListener,
|
||||
Zeroconf,
|
||||
ServiceBrowser,
|
||||
ServiceStateChange,
|
||||
Zeroconf,
|
||||
current_time_millis,
|
||||
)
|
||||
|
||||
@@ -24,17 +24,28 @@ _LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class HostResolver(RecordUpdateListener):
|
||||
"""Resolve a host name to an IP address."""
|
||||
|
||||
def __init__(self, name: str):
|
||||
self.name = name
|
||||
self.address: Optional[bytes] = None
|
||||
|
||||
def update_record(self, zc: Zeroconf, now: float, record: DNSRecord) -> None:
|
||||
if record is None:
|
||||
return
|
||||
if record.type == _TYPE_A:
|
||||
assert isinstance(record, DNSAddress)
|
||||
if record.name == self.name:
|
||||
self.address = record.address
|
||||
def async_update_records(
|
||||
self, zc: Zeroconf, now: float, records: list[RecordUpdate]
|
||||
) -> None:
|
||||
"""Update multiple records in one shot.
|
||||
|
||||
This will run in zeroconf's event loop thread so it
|
||||
must be thread-safe.
|
||||
"""
|
||||
for record_update in records:
|
||||
record, _ = record_update
|
||||
if record is None:
|
||||
continue
|
||||
if record.type == _TYPE_A:
|
||||
assert isinstance(record, DNSAddress)
|
||||
if record.name == self.name:
|
||||
self.address = record.address
|
||||
|
||||
def request(self, zc: Zeroconf, timeout: float) -> bool:
|
||||
now = time.time()
|
||||
|
||||
@@ -11,7 +11,7 @@ esptool==4.6.2
|
||||
click==8.1.7
|
||||
esphome-dashboard==20230711.0
|
||||
aioesphomeapi==15.0.0
|
||||
zeroconf==0.80.0
|
||||
zeroconf==0.86.0
|
||||
|
||||
# esp-idf requires this, but doesn't bundle it by default
|
||||
# https://github.com/espressif/esp-idf/blob/220590d599e134d7a5e7f1e683cc4550349ffbf8/requirements.txt#L24
|
||||
|
||||
Reference in New Issue
Block a user