Merge branch 'dev' into dev

This commit is contained in:
CptSkippy 2024-08-22 10:21:43 -07:00 committed by GitHub
commit 0004ae59b7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 85 additions and 5 deletions

View file

@ -38,7 +38,7 @@ from esphome.const import (
SECRETS_FILES,
)
from esphome.core import CORE, EsphomeError, coroutine
from esphome.helpers import indent, is_ip_address
from esphome.helpers import indent, is_ip_address, get_bool_env
from esphome.log import Fore, color, setup_log
from esphome.util import (
get_serial_ports,
@ -731,7 +731,11 @@ POST_CONFIG_ACTIONS = {
def parse_args(argv):
options_parser = argparse.ArgumentParser(add_help=False)
options_parser.add_argument(
"-v", "--verbose", help="Enable verbose ESPHome logs.", action="store_true"
"-v",
"--verbose",
help="Enable verbose ESPHome logs.",
action="store_true",
default=get_bool_env("ESPHOME_VERBOSE"),
)
options_parser.add_argument(
"-q", "--quiet", help="Disable all ESPHome logs.", action="store_true"

View file

@ -136,6 +136,9 @@ void Pipsolar::loop() {
if (this->output_source_priority_battery_switch_) {
this->output_source_priority_battery_switch_->publish_state(value_output_source_priority_ == 2);
}
if (this->output_source_priority_hybrid_switch_) {
this->output_source_priority_hybrid_switch_->publish_state(value_output_source_priority_ == 3);
}
if (this->charger_source_priority_) {
this->charger_source_priority_->publish_state(value_charger_source_priority_);
}

View file

@ -174,6 +174,7 @@ class Pipsolar : public uart::UARTDevice, public PollingComponent {
PIPSOLAR_SWITCH(output_source_priority_utility_switch, QPIRI)
PIPSOLAR_SWITCH(output_source_priority_solar_switch, QPIRI)
PIPSOLAR_SWITCH(output_source_priority_battery_switch, QPIRI)
PIPSOLAR_SWITCH(output_source_priority_hybrid_switch, QPIRI)
PIPSOLAR_SWITCH(input_voltage_range_switch, QPIRI)
PIPSOLAR_SWITCH(pv_ok_condition_for_parallel_switch, QPIRI)
PIPSOLAR_SWITCH(pv_power_balance_switch, QPIRI)

View file

@ -9,6 +9,7 @@ DEPENDENCIES = ["uart"]
CONF_OUTPUT_SOURCE_PRIORITY_UTILITY = "output_source_priority_utility"
CONF_OUTPUT_SOURCE_PRIORITY_SOLAR = "output_source_priority_solar"
CONF_OUTPUT_SOURCE_PRIORITY_BATTERY = "output_source_priority_battery"
CONF_OUTPUT_SOURCE_PRIORITY_HYBRID = "output_source_priority_hybrid"
CONF_INPUT_VOLTAGE_RANGE = "input_voltage_range"
CONF_PV_OK_CONDITION_FOR_PARALLEL = "pv_ok_condition_for_parallel"
CONF_PV_POWER_BALANCE = "pv_power_balance"
@ -17,6 +18,7 @@ TYPES = {
CONF_OUTPUT_SOURCE_PRIORITY_UTILITY: ("POP00", None),
CONF_OUTPUT_SOURCE_PRIORITY_SOLAR: ("POP01", None),
CONF_OUTPUT_SOURCE_PRIORITY_BATTERY: ("POP02", None),
CONF_OUTPUT_SOURCE_PRIORITY_HYBRID: ("POP03", None),
CONF_INPUT_VOLTAGE_RANGE: ("PGR01", "PGR00"),
CONF_PV_OK_CONDITION_FOR_PARALLEL: ("PPVOKC1", "PPVOKC0"),
CONF_PV_POWER_BALANCE: ("PSPB1", "PSPB0"),

View file

@ -15,6 +15,7 @@ CONF_DATAPOINT_TYPE = "datapoint_type"
CONF_STATUS_PIN = "status_pin"
tuya_ns = cg.esphome_ns.namespace("tuya")
TuyaDatapointType = tuya_ns.enum("TuyaDatapointType", is_class=True)
Tuya = tuya_ns.class_("Tuya", cg.Component, uart.UARTDevice)
DPTYPE_ANY = "any"

View file

@ -8,18 +8,36 @@ from esphome.const import (
CONF_MIN_VALUE,
CONF_MULTIPLY,
CONF_STEP,
CONF_INITIAL_VALUE,
)
from .. import tuya_ns, CONF_TUYA_ID, Tuya
from .. import tuya_ns, CONF_TUYA_ID, Tuya, TuyaDatapointType
DEPENDENCIES = ["tuya"]
CODEOWNERS = ["@frankiboy1"]
CONF_DATAPOINT_HIDDEN = "datapoint_hidden"
CONF_DATAPOINT_TYPE = "datapoint_type"
TuyaNumber = tuya_ns.class_("TuyaNumber", number.Number, cg.Component)
DATAPOINT_TYPES = {
"int": TuyaDatapointType.INTEGER,
"uint": TuyaDatapointType.INTEGER,
"enum": TuyaDatapointType.ENUM,
}
def validate_min_max(config):
if config[CONF_MAX_VALUE] <= config[CONF_MIN_VALUE]:
max_value = config[CONF_MAX_VALUE]
min_value = config[CONF_MIN_VALUE]
if max_value <= min_value:
raise cv.Invalid("max_value must be greater than min_value")
if hidden_config := config.get(CONF_DATAPOINT_HIDDEN):
if (initial_value := hidden_config.get(CONF_INITIAL_VALUE, None)) is not None:
if (initial_value > max_value) or (initial_value < min_value):
raise cv.Invalid(
f"{CONF_INITIAL_VALUE} must be a value between {CONF_MAX_VALUE} and {CONF_MIN_VALUE}"
)
return config
@ -33,6 +51,16 @@ CONFIG_SCHEMA = cv.All(
cv.Required(CONF_MIN_VALUE): cv.float_,
cv.Required(CONF_STEP): cv.positive_float,
cv.Optional(CONF_MULTIPLY, default=1.0): cv.float_,
cv.Optional(CONF_DATAPOINT_HIDDEN): cv.All(
cv.Schema(
{
cv.Required(CONF_DATAPOINT_TYPE): cv.enum(
DATAPOINT_TYPES, lower=True
),
cv.Optional(CONF_INITIAL_VALUE): cv.float_,
}
)
),
}
)
.extend(cv.COMPONENT_SCHEMA),
@ -56,3 +84,9 @@ async def to_code(config):
cg.add(var.set_tuya_parent(parent))
cg.add(var.set_number_id(config[CONF_NUMBER_DATAPOINT]))
if hidden_config := config.get(CONF_DATAPOINT_HIDDEN):
cg.add(var.set_datapoint_type(hidden_config[CONF_DATAPOINT_TYPE]))
if (
hidden_init_value := hidden_config.get(CONF_INITIAL_VALUE, None)
) is not None:
cg.add(var.set_datapoint_initial_value(hidden_init_value))

View file

@ -15,8 +15,18 @@ void TuyaNumber::setup() {
ESP_LOGV(TAG, "MCU reported number %u is: %u", datapoint.id, datapoint.value_enum);
this->publish_state(datapoint.value_enum);
}
if ((this->type_) && (this->type_ != datapoint.type)) {
ESP_LOGW(TAG, "Reported type (%d) different than previously set (%d)!", static_cast<int>(datapoint.type),
static_cast<int>(*this->type_));
}
this->type_ = datapoint.type;
});
this->parent_->add_on_initialized_callback([this] {
if ((this->initial_value_) && (this->type_)) {
this->control(*this->initial_value_);
}
});
}
void TuyaNumber::control(float value) {
@ -33,6 +43,15 @@ void TuyaNumber::control(float value) {
void TuyaNumber::dump_config() {
LOG_NUMBER("", "Tuya Number", this);
ESP_LOGCONFIG(TAG, " Number has datapoint ID %u", this->number_id_);
if (this->type_) {
ESP_LOGCONFIG(TAG, " Datapoint type is %d", static_cast<int>(*this->type_));
} else {
ESP_LOGCONFIG(TAG, " Datapoint type is unknown");
}
if (this->initial_value_) {
ESP_LOGCONFIG(TAG, " Initial Value: %f", *this->initial_value_);
}
}
} // namespace tuya

View file

@ -3,6 +3,7 @@
#include "esphome/core/component.h"
#include "esphome/components/tuya/tuya.h"
#include "esphome/components/number/number.h"
#include "esphome/core/optional.h"
namespace esphome {
namespace tuya {
@ -13,6 +14,8 @@ class TuyaNumber : public number::Number, public Component {
void dump_config() override;
void set_number_id(uint8_t number_id) { this->number_id_ = number_id; }
void set_write_multiply(float factor) { multiply_by_ = factor; }
void set_datapoint_type(TuyaDatapointType type) { type_ = type; }
void set_datapoint_initial_value(float value) { this->initial_value_ = value; }
void set_tuya_parent(Tuya *parent) { this->parent_ = parent; }
@ -22,7 +25,8 @@ class TuyaNumber : public number::Number, public Component {
Tuya *parent_;
uint8_t number_id_{0};
float multiply_by_{1.0};
TuyaDatapointType type_{};
optional<TuyaDatapointType> type_{};
optional<float> initial_value_{};
};
} // namespace tuya

View file

@ -220,6 +220,8 @@ switch:
name: inverter0_output_source_priority_solar
output_source_priority_battery:
name: inverter0_output_source_priority_battery
output_source_priority_hybrid:
name: inverter0_output_source_priority_hybrid
input_voltage_range:
name: inverter0_input_voltage_range
pv_ok_condition_for_parallel:

View file

@ -220,6 +220,8 @@ switch:
name: inverter0_output_source_priority_solar
output_source_priority_battery:
name: inverter0_output_source_priority_battery
output_source_priority_hybrid:
name: inverter0_output_source_priority_hybrid
input_voltage_range:
name: inverter0_input_voltage_range
pv_ok_condition_for_parallel:

View file

@ -220,6 +220,8 @@ switch:
name: inverter0_output_source_priority_solar
output_source_priority_battery:
name: inverter0_output_source_priority_battery
output_source_priority_hybrid:
name: inverter0_output_source_priority_hybrid
input_voltage_range:
name: inverter0_input_voltage_range
pv_ok_condition_for_parallel:

View file

@ -220,6 +220,8 @@ switch:
name: inverter0_output_source_priority_solar
output_source_priority_battery:
name: inverter0_output_source_priority_battery
output_source_priority_hybrid:
name: inverter0_output_source_priority_hybrid
input_voltage_range:
name: inverter0_input_voltage_range
pv_ok_condition_for_parallel:

View file

@ -220,6 +220,8 @@ switch:
name: inverter0_output_source_priority_solar
output_source_priority_battery:
name: inverter0_output_source_priority_battery
output_source_priority_hybrid:
name: inverter0_output_source_priority_hybrid
input_voltage_range:
name: inverter0_input_voltage_range
pv_ok_condition_for_parallel:

View file

@ -220,6 +220,8 @@ switch:
name: inverter0_output_source_priority_solar
output_source_priority_battery:
name: inverter0_output_source_priority_battery
output_source_priority_hybrid:
name: inverter0_output_source_priority_hybrid
input_voltage_range:
name: inverter0_input_voltage_range
pv_ok_condition_for_parallel: