[ota-esphome] Validate for multiple esphome ota instances (#6984)

This commit is contained in:
Keith Burzinski 2024-06-25 15:57:15 -05:00 committed by GitHub
parent fb9844463b
commit d8a5c1ea0c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,10 +1,14 @@
import esphome.codegen as cg
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.const import (
CONF_ESPHOME,
CONF_ID,
CONF_NUM_ATTEMPTS,
CONF_OTA,
CONF_PASSWORD,
CONF_PLATFORM,
CONF_PORT,
CONF_REBOOT_TIMEOUT,
CONF_SAFE_MODE,
@ -21,6 +25,19 @@ esphome = cg.esphome_ns.namespace("esphome")
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 = (
cv.Schema(
{
@ -50,6 +67,8 @@ CONFIG_SCHEMA = (
.extend(cv.COMPONENT_SCHEMA)
)
FINAL_VALIDATE_SCHEMA = ota_esphome_final_validate
@coroutine_with_priority(52.0)
async def to_code(config):