Skip to content

Commit

Permalink
Add optional minimum esphome version to microWakeWord manifest (#6240)
Browse files Browse the repository at this point in the history
  • Loading branch information
jesserockz committed Feb 19, 2024
1 parent 29ec40d commit 6eb3c65
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
4 changes: 4 additions & 0 deletions esphome/components/micro_wake_word/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def _process_git_source(config):
KEY_WEBSITE = "website"
KEY_VERSION = "version"
KEY_MICRO = "micro"
KEY_MINIMUM_ESPHOME_VERSION = "minimum_esphome_version"

MANIFEST_SCHEMA_V1 = cv.Schema(
{
Expand All @@ -116,6 +117,9 @@ def _process_git_source(config):
{
cv.Required(CONF_PROBABILITY_CUTOFF): cv.float_,
cv.Required(CONF_SLIDING_WINDOW_AVERAGE_SIZE): cv.positive_int,
cv.Optional(KEY_MINIMUM_ESPHOME_VERSION): cv.All(
cv.version_number, cv.validate_esphome_version
),
}
),
}
Expand Down
11 changes: 11 additions & 0 deletions esphome/config_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
TYPE_GIT,
TYPE_LOCAL,
VALID_SUBSTITUTIONS_CHARACTERS,
__version__ as ESPHOME_VERSION,
)
from esphome.core import (
CORE,
Expand Down Expand Up @@ -1895,6 +1896,16 @@ def version_number(value):
raise Invalid("Not a valid version number") from e


def validate_esphome_version(value: str):
min_version = Version.parse(value)
current_version = Version.parse(ESPHOME_VERSION)
if current_version < min_version:
raise Invalid(
f"Your ESPHome version is too old. Please update to at least {min_version}"
)
return value


def platformio_version_constraint(value):
# for documentation on valid version constraints:
# https://docs.platformio.org/en/latest/core/userguide/platforms/cmd_install.html#cmd-platform-install
Expand Down
12 changes: 1 addition & 11 deletions esphome/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,6 @@ def valid_project_name(value: str):
return value


def validate_version(value: str):
min_version = cv.Version.parse(value)
current_version = cv.Version.parse(ESPHOME_VERSION)
if current_version < min_version:
raise cv.Invalid(
f"Your ESPHome version is too old. Please update to at least {min_version}"
)
return value


if "ESPHOME_DEFAULT_COMPILE_PROCESS_LIMIT" in os.environ:
_compile_process_limit_default = min(
int(os.environ["ESPHOME_DEFAULT_COMPILE_PROCESS_LIMIT"]),
Expand Down Expand Up @@ -164,7 +154,7 @@ def validate_version(value: str):
}
),
cv.Optional(CONF_MIN_VERSION, default=ESPHOME_VERSION): cv.All(
cv.version_number, validate_version
cv.version_number, cv.validate_esphome_version
),
cv.Optional(
CONF_COMPILE_PROCESS_LIMIT, default=_compile_process_limit_default
Expand Down

0 comments on commit 6eb3c65

Please sign in to comment.