mirror of
https://github.com/esphome/esphome.git
synced 2024-11-22 11:47:30 +01:00
[ota-esphome] Validate for multiple esphome ota instances (#6984)
This commit is contained in:
parent
fb9844463b
commit
d8a5c1ea0c
@ -1,10 +1,14 @@
|
|||||||
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
|
||||||
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.const import (
|
from esphome.const import (
|
||||||
|
CONF_ESPHOME,
|
||||||
CONF_ID,
|
CONF_ID,
|
||||||
CONF_NUM_ATTEMPTS,
|
CONF_NUM_ATTEMPTS,
|
||||||
|
CONF_OTA,
|
||||||
CONF_PASSWORD,
|
CONF_PASSWORD,
|
||||||
|
CONF_PLATFORM,
|
||||||
CONF_PORT,
|
CONF_PORT,
|
||||||
CONF_REBOOT_TIMEOUT,
|
CONF_REBOOT_TIMEOUT,
|
||||||
CONF_SAFE_MODE,
|
CONF_SAFE_MODE,
|
||||||
@ -21,6 +25,19 @@ esphome = cg.esphome_ns.namespace("esphome")
|
|||||||
ESPHomeOTAComponent = esphome.class_("ESPHomeOTAComponent", OTAComponent)
|
ESPHomeOTAComponent = esphome.class_("ESPHomeOTAComponent", OTAComponent)
|
||||||
|
|
||||||
|
|
||||||
|
def ota_esphome_final_validate(config):
|
||||||
|
fconf = fv.full_config.get()[CONF_OTA]
|
||||||
|
used_ports = []
|
||||||
|
for ota_conf in fconf:
|
||||||
|
if ota_conf.get(CONF_PLATFORM) == CONF_ESPHOME:
|
||||||
|
if (plat_port := ota_conf.get(CONF_PORT)) not in used_ports:
|
||||||
|
used_ports.append(plat_port)
|
||||||
|
else:
|
||||||
|
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"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
CONFIG_SCHEMA = (
|
CONFIG_SCHEMA = (
|
||||||
cv.Schema(
|
cv.Schema(
|
||||||
{
|
{
|
||||||
@ -50,6 +67,8 @@ CONFIG_SCHEMA = (
|
|||||||
.extend(cv.COMPONENT_SCHEMA)
|
.extend(cv.COMPONENT_SCHEMA)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
FINAL_VALIDATE_SCHEMA = ota_esphome_final_validate
|
||||||
|
|
||||||
|
|
||||||
@coroutine_with_priority(52.0)
|
@coroutine_with_priority(52.0)
|
||||||
async def to_code(config):
|
async def to_code(config):
|
||||||
|
Loading…
Reference in New Issue
Block a user