[packages] Restore remote shorthand vars and !remove in early package contents validation (#12158)

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Javier Peletier
2025-11-28 19:24:09 +01:00
committed by GitHub
parent e15f3a08ae
commit d6ca01775e
4 changed files with 24 additions and 3 deletions

View File

@@ -2,7 +2,8 @@ import logging
from pathlib import Path
from esphome import git, yaml_util
from esphome.config_helpers import merge_config
from esphome.components.substitutions.jinja import has_jinja
from esphome.config_helpers import Remove, merge_config
import esphome.config_validation as cv
from esphome.const import (
CONF_ESPHOME,
@@ -39,10 +40,15 @@ def valid_package_contents(package_config: dict):
for k, v in package_config.items():
if not isinstance(k, str):
raise cv.Invalid("Package content keys must be strings")
if isinstance(v, (dict, list)):
continue # e.g. script: [] or logger: {level: debug}
if isinstance(v, (dict, list, Remove)):
continue # e.g. script: [], psram: !remove, logger: {level: debug}
if v is None:
continue # e.g. web_server:
if isinstance(v, str) and has_jinja(v):
# e.g: remote package shorthand:
# package_name: github://esphome/repo/file.yaml@${ branch }
continue
raise cv.Invalid("Invalid component content in package definition")
return package_config

View File

@@ -23,3 +23,8 @@ values_from_repo1_main:
y: 10
z: 11
volume: 990
- package_name: default
x: 10
y: 20
z: 5
volume: 1000

View File

@@ -35,3 +35,9 @@ packages:
b: 10
c: 11
ref: main
package5: !include
file: remote_package_shorthand.yaml
vars:
repo: repo1
file: file1.yaml
ref: main

View File

@@ -0,0 +1,4 @@
# acts as a proxy to be able to include a remote package
# in which the shorthand comes from a substitution
packages:
- github://esphome/${repo}/${file}@${ref}