mirror of
https://github.com/esphome/esphome.git
synced 2024-11-26 17:05:21 +01:00
commit
341fddb9aa
6 changed files with 40 additions and 12 deletions
|
@ -45,6 +45,7 @@ void HLW8012Component::dump_config() {
|
||||||
LOG_SENSOR(" ", "Voltage", this->voltage_sensor_)
|
LOG_SENSOR(" ", "Voltage", this->voltage_sensor_)
|
||||||
LOG_SENSOR(" ", "Current", this->current_sensor_)
|
LOG_SENSOR(" ", "Current", this->current_sensor_)
|
||||||
LOG_SENSOR(" ", "Power", this->power_sensor_)
|
LOG_SENSOR(" ", "Power", this->power_sensor_)
|
||||||
|
LOG_SENSOR(" ", "Energy", this->energy_sensor_)
|
||||||
}
|
}
|
||||||
float HLW8012Component::get_setup_priority() const { return setup_priority::DATA; }
|
float HLW8012Component::get_setup_priority() const { return setup_priority::DATA; }
|
||||||
void HLW8012Component::update() {
|
void HLW8012Component::update() {
|
||||||
|
|
|
@ -1,7 +1,15 @@
|
||||||
import esphome.codegen as cg
|
import esphome.codegen as cg
|
||||||
import esphome.config_validation as cv
|
import esphome.config_validation as cv
|
||||||
from esphome.components import sensor, time
|
from esphome.components import sensor, time
|
||||||
from esphome.const import CONF_ID, CONF_TIME_ID
|
from esphome.const import (
|
||||||
|
CONF_ID,
|
||||||
|
CONF_TIME_ID,
|
||||||
|
DEVICE_CLASS_ENERGY,
|
||||||
|
ICON_EMPTY,
|
||||||
|
LAST_RESET_TYPE_AUTO,
|
||||||
|
STATE_CLASS_MEASUREMENT,
|
||||||
|
UNIT_EMPTY,
|
||||||
|
)
|
||||||
|
|
||||||
DEPENDENCIES = ["time"]
|
DEPENDENCIES = ["time"]
|
||||||
|
|
||||||
|
@ -11,13 +19,24 @@ TotalDailyEnergy = total_daily_energy_ns.class_(
|
||||||
"TotalDailyEnergy", sensor.Sensor, cg.Component
|
"TotalDailyEnergy", sensor.Sensor, cg.Component
|
||||||
)
|
)
|
||||||
|
|
||||||
CONFIG_SCHEMA = sensor.SENSOR_SCHEMA.extend(
|
CONFIG_SCHEMA = (
|
||||||
{
|
sensor.sensor_schema(
|
||||||
cv.GenerateID(): cv.declare_id(TotalDailyEnergy),
|
UNIT_EMPTY,
|
||||||
cv.GenerateID(CONF_TIME_ID): cv.use_id(time.RealTimeClock),
|
ICON_EMPTY,
|
||||||
cv.Required(CONF_POWER_ID): cv.use_id(sensor.Sensor),
|
0,
|
||||||
}
|
DEVICE_CLASS_ENERGY,
|
||||||
).extend(cv.COMPONENT_SCHEMA)
|
STATE_CLASS_MEASUREMENT,
|
||||||
|
LAST_RESET_TYPE_AUTO,
|
||||||
|
)
|
||||||
|
.extend(
|
||||||
|
{
|
||||||
|
cv.GenerateID(): cv.declare_id(TotalDailyEnergy),
|
||||||
|
cv.GenerateID(CONF_TIME_ID): cv.use_id(time.RealTimeClock),
|
||||||
|
cv.Required(CONF_POWER_ID): cv.use_id(sensor.Sensor),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.extend(cv.COMPONENT_SCHEMA)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def to_code(config):
|
async def to_code(config):
|
||||||
|
|
|
@ -7,7 +7,7 @@ namespace esphome {
|
||||||
namespace tuya {
|
namespace tuya {
|
||||||
|
|
||||||
static const char *const TAG = "tuya";
|
static const char *const TAG = "tuya";
|
||||||
static const int COMMAND_DELAY = 50;
|
static const int COMMAND_DELAY = 10;
|
||||||
static const int RECEIVE_TIMEOUT = 300;
|
static const int RECEIVE_TIMEOUT = 300;
|
||||||
|
|
||||||
void Tuya::setup() {
|
void Tuya::setup() {
|
||||||
|
@ -114,6 +114,8 @@ void Tuya::handle_char_(uint8_t c) {
|
||||||
this->rx_message_.push_back(c);
|
this->rx_message_.push_back(c);
|
||||||
if (!this->validate_message_()) {
|
if (!this->validate_message_()) {
|
||||||
this->rx_message_.clear();
|
this->rx_message_.clear();
|
||||||
|
} else {
|
||||||
|
this->last_rx_char_timestamp_ = millis();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -357,7 +359,12 @@ void Tuya::send_raw_command_(TuyaCommand command) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tuya::process_command_queue_() {
|
void Tuya::process_command_queue_() {
|
||||||
uint32_t delay = millis() - this->last_command_timestamp_;
|
uint32_t now = millis();
|
||||||
|
uint32_t delay = now - this->last_command_timestamp_;
|
||||||
|
|
||||||
|
if (now - this->last_rx_char_timestamp_ > RECEIVE_TIMEOUT) {
|
||||||
|
this->rx_message_.clear();
|
||||||
|
}
|
||||||
|
|
||||||
if (this->expected_response_.has_value() && delay > RECEIVE_TIMEOUT) {
|
if (this->expected_response_.has_value() && delay > RECEIVE_TIMEOUT) {
|
||||||
this->expected_response_.reset();
|
this->expected_response_.reset();
|
||||||
|
|
|
@ -107,6 +107,7 @@ class Tuya : public Component, public uart::UARTDevice {
|
||||||
int gpio_status_ = -1;
|
int gpio_status_ = -1;
|
||||||
int gpio_reset_ = -1;
|
int gpio_reset_ = -1;
|
||||||
uint32_t last_command_timestamp_ = 0;
|
uint32_t last_command_timestamp_ = 0;
|
||||||
|
uint32_t last_rx_char_timestamp_ = 0;
|
||||||
std::string product_ = "";
|
std::string product_ = "";
|
||||||
std::vector<TuyaDatapointListener> listeners_;
|
std::vector<TuyaDatapointListener> listeners_;
|
||||||
std::vector<TuyaDatapoint> datapoints_;
|
std::vector<TuyaDatapoint> datapoints_;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
"""Constants used by esphome."""
|
"""Constants used by esphome."""
|
||||||
|
|
||||||
__version__ = "1.20.1"
|
__version__ = "1.20.2"
|
||||||
|
|
||||||
ESP_PLATFORM_ESP32 = "ESP32"
|
ESP_PLATFORM_ESP32 = "ESP32"
|
||||||
ESP_PLATFORM_ESP8266 = "ESP8266"
|
ESP_PLATFORM_ESP8266 = "ESP8266"
|
||||||
|
|
|
@ -11,4 +11,4 @@ ifaddr==0.1.7
|
||||||
platformio==5.1.1
|
platformio==5.1.1
|
||||||
esptool==2.8
|
esptool==2.8
|
||||||
click==7.1.2
|
click==7.1.2
|
||||||
esphome-dashboard==20210719.0
|
esphome-dashboard==20210728.0
|
||||||
|
|
Loading…
Reference in a new issue