mirror of
https://github.com/esphome/esphome.git
synced 2024-12-22 21:44:55 +01:00
Add final validate for i2c with mix/max frequency (#3727)
Co-authored-by: MrEditor97 <mr.samuel.hughes@gmail.com>
This commit is contained in:
parent
b4bbe3d7b5
commit
d546ef941f
1 changed files with 25 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
|||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
import esphome.final_validate as fv
|
||||
from esphome import pins
|
||||
from esphome.const import (
|
||||
CONF_FREQUENCY,
|
||||
|
@ -110,3 +111,27 @@ async def register_i2c_device(var, config):
|
|||
parent = await cg.get_variable(config[CONF_I2C_ID])
|
||||
cg.add(var.set_i2c_bus(parent))
|
||||
cg.add(var.set_i2c_address(config[CONF_ADDRESS]))
|
||||
|
||||
|
||||
def final_validate_device_schema(
|
||||
name: str, *, min_frequency: cv.frequency = None, max_frequency: cv.frequency = None
|
||||
):
|
||||
hub_schema = {}
|
||||
if min_frequency is not None:
|
||||
hub_schema[cv.Required(CONF_FREQUENCY)] = cv.Range(
|
||||
min=cv.frequency(min_frequency),
|
||||
min_included=True,
|
||||
msg=f"Component {name} requires a minimum frequency of {min_frequency} for the I2C bus",
|
||||
)
|
||||
|
||||
if max_frequency is not None:
|
||||
hub_schema[cv.Required(CONF_FREQUENCY)] = cv.Range(
|
||||
max=cv.frequency(max_frequency),
|
||||
max_included=True,
|
||||
msg=f"Component {name} cannot be used with a frequency of over {max_frequency} for the I2C bus",
|
||||
)
|
||||
|
||||
return cv.Schema(
|
||||
{cv.Required(CONF_I2C_ID): fv.id_declaration_match_schema(hub_schema)},
|
||||
extra=cv.ALLOW_EXTRA,
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue