mirror of
https://github.com/esphome/esphome.git
synced 2024-11-10 01:07:45 +01:00
commit
7b3d6747d5
3 changed files with 63 additions and 9 deletions
|
@ -1,7 +1,10 @@
|
||||||
|
import logging
|
||||||
|
|
||||||
import esphome.codegen as cg
|
import esphome.codegen as cg
|
||||||
import esphome.config_validation as cv
|
import esphome.config_validation as cv
|
||||||
import esphome.final_validate as fv
|
import esphome.final_validate as fv
|
||||||
from esphome.components.ota import BASE_OTA_SCHEMA, ota_to_code, OTAComponent
|
from esphome.components.ota import BASE_OTA_SCHEMA, ota_to_code, OTAComponent
|
||||||
|
from esphome.config_helpers import merge_config
|
||||||
from esphome.const import (
|
from esphome.const import (
|
||||||
CONF_ESPHOME,
|
CONF_ESPHOME,
|
||||||
CONF_ID,
|
CONF_ID,
|
||||||
|
@ -16,6 +19,8 @@ from esphome.const import (
|
||||||
)
|
)
|
||||||
from esphome.core import coroutine_with_priority
|
from esphome.core import coroutine_with_priority
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
CODEOWNERS = ["@esphome/core"]
|
CODEOWNERS = ["@esphome/core"]
|
||||||
AUTO_LOAD = ["md5", "socket"]
|
AUTO_LOAD = ["md5", "socket"]
|
||||||
|
@ -26,15 +31,61 @@ ESPHomeOTAComponent = esphome.class_("ESPHomeOTAComponent", OTAComponent)
|
||||||
|
|
||||||
|
|
||||||
def ota_esphome_final_validate(config):
|
def ota_esphome_final_validate(config):
|
||||||
fconf = fv.full_config.get()[CONF_OTA]
|
full_conf = fv.full_config.get()
|
||||||
used_ports = []
|
full_ota_conf = full_conf[CONF_OTA]
|
||||||
for ota_conf in fconf:
|
new_ota_conf = []
|
||||||
|
merged_ota_esphome_configs_by_port = {}
|
||||||
|
ports_with_merged_configs = []
|
||||||
|
for ota_conf in full_ota_conf:
|
||||||
if ota_conf.get(CONF_PLATFORM) == CONF_ESPHOME:
|
if ota_conf.get(CONF_PLATFORM) == CONF_ESPHOME:
|
||||||
if (plat_port := ota_conf.get(CONF_PORT)) not in used_ports:
|
if (
|
||||||
used_ports.append(plat_port)
|
conf_port := ota_conf.get(CONF_PORT)
|
||||||
|
) not in merged_ota_esphome_configs_by_port:
|
||||||
|
merged_ota_esphome_configs_by_port[conf_port] = ota_conf
|
||||||
else:
|
else:
|
||||||
|
if merged_ota_esphome_configs_by_port[conf_port][
|
||||||
|
CONF_VERSION
|
||||||
|
] != ota_conf.get(CONF_VERSION):
|
||||||
raise cv.Invalid(
|
raise cv.Invalid(
|
||||||
f"Only one instance of the {CONF_ESPHOME} {CONF_OTA} {CONF_PLATFORM} is allowed per port. Note that this error may result from OTA specified in packages"
|
f"Found multiple configurations but {CONF_VERSION} is inconsistent"
|
||||||
|
)
|
||||||
|
if (
|
||||||
|
merged_ota_esphome_configs_by_port[conf_port][CONF_ID].is_manual
|
||||||
|
and ota_conf.get(CONF_ID).is_manual
|
||||||
|
):
|
||||||
|
raise cv.Invalid(
|
||||||
|
f"Found multiple configurations but {CONF_ID} is inconsistent"
|
||||||
|
)
|
||||||
|
if (
|
||||||
|
CONF_PASSWORD in merged_ota_esphome_configs_by_port[conf_port]
|
||||||
|
and CONF_PASSWORD in ota_conf
|
||||||
|
and merged_ota_esphome_configs_by_port[conf_port][CONF_PASSWORD]
|
||||||
|
!= ota_conf.get(CONF_PASSWORD)
|
||||||
|
):
|
||||||
|
raise cv.Invalid(
|
||||||
|
f"Found multiple configurations but {CONF_PASSWORD} is inconsistent"
|
||||||
|
)
|
||||||
|
|
||||||
|
ports_with_merged_configs.append(conf_port)
|
||||||
|
merged_ota_esphome_configs_by_port[conf_port] = merge_config(
|
||||||
|
merged_ota_esphome_configs_by_port[conf_port], ota_conf
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
new_ota_conf.append(ota_conf)
|
||||||
|
|
||||||
|
for port_conf in merged_ota_esphome_configs_by_port.values():
|
||||||
|
new_ota_conf.append(port_conf)
|
||||||
|
|
||||||
|
full_conf[CONF_OTA] = new_ota_conf
|
||||||
|
fv.full_config.set(full_conf)
|
||||||
|
|
||||||
|
if len(ports_with_merged_configs) > 0:
|
||||||
|
_LOGGER.warning(
|
||||||
|
"Found and merged multiple configurations for %s %s %s port(s) %s",
|
||||||
|
CONF_OTA,
|
||||||
|
CONF_PLATFORM,
|
||||||
|
CONF_ESPHOME,
|
||||||
|
ports_with_merged_configs,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -115,12 +115,15 @@ void LEDCOutput::write_state(float state) {
|
||||||
const uint32_t max_duty = (uint32_t(1) << this->bit_depth_) - 1;
|
const uint32_t max_duty = (uint32_t(1) << this->bit_depth_) - 1;
|
||||||
const float duty_rounded = roundf(state * max_duty);
|
const float duty_rounded = roundf(state * max_duty);
|
||||||
auto duty = static_cast<uint32_t>(duty_rounded);
|
auto duty = static_cast<uint32_t>(duty_rounded);
|
||||||
|
|
||||||
#ifdef USE_ARDUINO
|
#ifdef USE_ARDUINO
|
||||||
ESP_LOGV(TAG, "Setting duty: %u on channel %u", duty, this->channel_);
|
ESP_LOGV(TAG, "Setting duty: %u on channel %u", duty, this->channel_);
|
||||||
ledcWrite(this->channel_, duty);
|
ledcWrite(this->channel_, duty);
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_ESP_IDF
|
#ifdef USE_ESP_IDF
|
||||||
|
// ensure that 100% on is not 99.975% on
|
||||||
|
if ((duty == max_duty) && (max_duty != 1)) {
|
||||||
|
duty = max_duty + 1;
|
||||||
|
}
|
||||||
auto speed_mode = get_speed_mode(channel_);
|
auto speed_mode = get_speed_mode(channel_);
|
||||||
auto chan_num = static_cast<ledc_channel_t>(channel_ % 8);
|
auto chan_num = static_cast<ledc_channel_t>(channel_ % 8);
|
||||||
int hpoint = ledc_angle_to_htop(this->phase_angle_, this->bit_depth_);
|
int hpoint = ledc_angle_to_htop(this->phase_angle_, this->bit_depth_);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
"""Constants used by esphome."""
|
"""Constants used by esphome."""
|
||||||
|
|
||||||
__version__ = "2024.6.3"
|
__version__ = "2024.6.4"
|
||||||
|
|
||||||
ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"
|
ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"
|
||||||
VALID_SUBSTITUTIONS_CHARACTERS = (
|
VALID_SUBSTITUTIONS_CHARACTERS = (
|
||||||
|
|
Loading…
Reference in a new issue