mirror of https://github.com/esphome/esphome.git
model check in yaml
This commit is contained in:
parent
677abcf815
commit
803b66b20d
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -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,
|
||||
)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue