model check in yaml

This commit is contained in:
Anton Viktorov 2024-05-14 02:41:48 +02:00
parent 677abcf815
commit 803b66b20d
3 changed files with 28 additions and 0 deletions

View File

@ -66,6 +66,32 @@ ADC_SAMPLES = {
1024: AdcAvgSamples.ADC_AVG_SAMPLES_1024,
}
SENSOR_MODEL_OPTIONS = {
CONF_ENERGY: ["INA228", "INA229"],
CONF_ENERGY_JOULES: ["INA228", "INA229"],
CONF_CHARGE: ["INA228", "INA229"],
CONF_CHARGE_COULOMBS: ["INA228", "INA229"],
}
def validate_model_config(config):
model = config[CONF_MODEL]
for key in config:
if key in SENSOR_MODEL_OPTIONS:
if model not in SENSOR_MODEL_OPTIONS[key]:
raise cv.Invalid(
f"Device model '{model}' does not support '{key}' sensor"
)
tempco = config[CONF_TEMPERATURE_COEFFICIENT]
if tempco > 0 and model not in ["INA228", "INA229"]:
raise cv.Invalid(
f"Device model '{model}' does not support temperature coefficient"
)
return config
def validate_adc_time(value):
value = cv.positive_time_period_microseconds(value).total_microseconds

View File

@ -24,6 +24,7 @@ CONFIG_SCHEMA = cv.All(
cv.Required(CONF_MODEL): cv.enum(INA_MODELS, upper=True),
}
).extend(i2c.i2c_device_schema(0x40)),
ina2xx_base.validate_model_config,
)

View File

@ -23,6 +23,7 @@ CONFIG_SCHEMA = cv.All(
cv.Required(CONF_MODEL): cv.enum(INA_MODELS, upper=True),
}
).extend(spi.spi_device_schema(cs_pin_required=True)),
ina2xx_base.validate_model_config,
)