mirror of
https://github.com/esphome/esphome.git
synced 2025-09-06 13:22:19 +01:00
Add cv.require_esphome_version helper (#3103)
This commit is contained in:
@@ -63,7 +63,7 @@ from esphome.jsonschema import (
|
||||
jschema_registry,
|
||||
jschema_typed,
|
||||
)
|
||||
|
||||
from esphome.util import parse_esphome_version
|
||||
from esphome.voluptuous_schema import _Schema
|
||||
from esphome.yaml_util import make_data_base
|
||||
|
||||
@@ -1742,6 +1742,19 @@ def require_framework_version(
|
||||
return validator
|
||||
|
||||
|
||||
def require_esphome_version(year, month, patch):
|
||||
def validator(value):
|
||||
esphome_version = parse_esphome_version()
|
||||
if esphome_version < (year, month, patch):
|
||||
requires_version = f"{year}.{month}.{patch}"
|
||||
raise Invalid(
|
||||
f"This component requires at least ESPHome version {requires_version}"
|
||||
)
|
||||
return value
|
||||
|
||||
return validator
|
||||
|
||||
|
||||
@contextmanager
|
||||
def suppress_invalid():
|
||||
try:
|
||||
|
Reference in New Issue
Block a user