[mics_4514] Move consts to consts.py (#7528)
Some checks are pending
CI / Create common environment (push) Waiting to run
CI / Check black (push) Blocked by required conditions
CI / Check flake8 (push) Blocked by required conditions
CI / Check pylint (push) Blocked by required conditions
CI / Check pyupgrade (push) Blocked by required conditions
CI / Run script/ci-custom (push) Blocked by required conditions
CI / Run pytest (push) Blocked by required conditions
CI / Check clang-format (push) Blocked by required conditions
CI / Run script/clang-tidy for ESP32 Arduino 1/4 (push) Blocked by required conditions
CI / Run script/clang-tidy for ESP32 Arduino 2/4 (push) Blocked by required conditions
CI / Run script/clang-tidy for ESP32 Arduino 3/4 (push) Blocked by required conditions
CI / Run script/clang-tidy for ESP32 Arduino 4/4 (push) Blocked by required conditions
CI / Run script/clang-tidy for ESP32 IDF (push) Blocked by required conditions
CI / Run script/clang-tidy for ESP8266 (push) Blocked by required conditions
CI / list-components (push) Blocked by required conditions
CI / Component test (push) Blocked by required conditions
CI / Split components for testing into 20 groups maximum (push) Blocked by required conditions
CI / Test split components (push) Blocked by required conditions
CI / CI Status (push) Blocked by required conditions

This commit is contained in:
Jesse Hills 2024-10-02 22:27:32 +13:00 committed by GitHub
parent 0d80286bb3
commit 361b6ab961
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 26 deletions

View file

@ -1,10 +1,14 @@
import esphome.codegen as cg import esphome.codegen as cg
from esphome.components import i2c, sensor
import esphome.config_validation as cv import esphome.config_validation as cv
from esphome.components import sensor, i2c
from esphome.const import ( from esphome.const import (
CONF_AMMONIA,
CONF_CARBON_MONOXIDE,
CONF_ETHANOL,
CONF_HYDROGEN,
CONF_ID, CONF_ID,
CONF_METHANE,
CONF_NITROGEN_DIOXIDE,
STATE_CLASS_MEASUREMENT, STATE_CLASS_MEASUREMENT,
UNIT_PARTS_PER_MILLION, UNIT_PARTS_PER_MILLION,
) )
@ -12,13 +16,6 @@ from esphome.const import (
CODEOWNERS = ["@jesserockz"] CODEOWNERS = ["@jesserockz"]
DEPENDENCIES = ["i2c"] DEPENDENCIES = ["i2c"]
CONF_CARBON_MONOXIDE = "carbon_monoxide"
CONF_NITROGEN_DIOXIDE = "nitrogen_dioxide"
CONF_METHANE = "methane"
CONF_ETHANOL = "ethanol"
CONF_HYDROGEN = "hydrogen"
CONF_AMMONIA = "ammonia"
mics_4514_ns = cg.esphome_ns.namespace("mics_4514") mics_4514_ns = cg.esphome_ns.namespace("mics_4514")
MICS4514Component = mics_4514_ns.class_( MICS4514Component = mics_4514_ns.class_(
@ -31,6 +28,7 @@ SENSORS = [
CONF_ETHANOL, CONF_ETHANOL,
CONF_HYDROGEN, CONF_HYDROGEN,
CONF_AMMONIA, CONF_AMMONIA,
CONF_NITROGEN_DIOXIDE,
] ]
common_sensor_schema = sensor.sensor_schema( common_sensor_schema = sensor.sensor_schema(
@ -40,16 +38,7 @@ common_sensor_schema = sensor.sensor_schema(
) )
CONFIG_SCHEMA = ( CONFIG_SCHEMA = (
cv.Schema( cv.Schema({cv.GenerateID(): cv.declare_id(MICS4514Component)})
{
cv.GenerateID(): cv.declare_id(MICS4514Component),
cv.Optional(CONF_NITROGEN_DIOXIDE): sensor.sensor_schema(
unit_of_measurement=UNIT_PARTS_PER_MILLION,
state_class=STATE_CLASS_MEASUREMENT,
accuracy_decimals=2,
),
}
)
.extend({cv.Optional(sensor_type): common_sensor_schema for sensor_type in SENSORS}) .extend({cv.Optional(sensor_type): common_sensor_schema for sensor_type in SENSORS})
.extend(i2c.i2c_device_schema(0x75)) .extend(i2c.i2c_device_schema(0x75))
.extend(cv.polling_component_schema("60s")) .extend(cv.polling_component_schema("60s"))
@ -62,10 +51,6 @@ async def to_code(config):
await i2c.register_i2c_device(var, config) await i2c.register_i2c_device(var, config)
for sensor_type in SENSORS: for sensor_type in SENSORS:
if sensor_type in config: if sensor_config := config.get(sensor_type):
sens = await sensor.new_sensor(config[sensor_type]) sens = await sensor.new_sensor(sensor_config)
cg.add(getattr(var, f"set_{sensor_type}_sensor")(sens)) cg.add(getattr(var, f"set_{sensor_type}_sensor")(sens))
if CONF_NITROGEN_DIOXIDE in config:
sens = await sensor.new_sensor(config[CONF_NITROGEN_DIOXIDE])
cg.add(var.set_nitrogen_dioxide_sensor(sens))

View file

@ -53,6 +53,7 @@ CONF_ALLOW_OTHER_USES = "allow_other_uses"
CONF_ALPHA = "alpha" CONF_ALPHA = "alpha"
CONF_ALTITUDE = "altitude" CONF_ALTITUDE = "altitude"
CONF_AMBIENT_LIGHT = "ambient_light" CONF_AMBIENT_LIGHT = "ambient_light"
CONF_AMMONIA = "ammonia"
CONF_ANALOG = "analog" CONF_ANALOG = "analog"
CONF_AND = "and" CONF_AND = "and"
CONF_ANGLE = "angle" CONF_ANGLE = "angle"
@ -110,6 +111,7 @@ CONF_CALIBRATE_LINEAR = "calibrate_linear"
CONF_CALIBRATION = "calibration" CONF_CALIBRATION = "calibration"
CONF_CAPACITANCE = "capacitance" CONF_CAPACITANCE = "capacitance"
CONF_CAPACITY = "capacity" CONF_CAPACITY = "capacity"
CONF_CARBON_MONOXIDE = "carbon_monoxide"
CONF_CARRIER_DUTY_PERCENT = "carrier_duty_percent" CONF_CARRIER_DUTY_PERCENT = "carrier_duty_percent"
CONF_CARRIER_FREQUENCY = "carrier_frequency" CONF_CARRIER_FREQUENCY = "carrier_frequency"
CONF_CERTIFICATE = "certificate" CONF_CERTIFICATE = "certificate"
@ -263,6 +265,7 @@ CONF_ENUM_DATAPOINT = "enum_datapoint"
CONF_EQUATION = "equation" CONF_EQUATION = "equation"
CONF_ESP8266_DISABLE_SSL_SUPPORT = "esp8266_disable_ssl_support" CONF_ESP8266_DISABLE_SSL_SUPPORT = "esp8266_disable_ssl_support"
CONF_ESPHOME = "esphome" CONF_ESPHOME = "esphome"
CONF_ETHANOL = "ethanol"
CONF_ETHERNET = "ethernet" CONF_ETHERNET = "ethernet"
CONF_EVENT = "event" CONF_EVENT = "event"
CONF_EVENT_TYPE = "event_type" CONF_EVENT_TYPE = "event_type"
@ -361,6 +364,7 @@ CONF_HOURS = "hours"
CONF_HSYNC_PIN = "hsync_pin" CONF_HSYNC_PIN = "hsync_pin"
CONF_HUMIDITY = "humidity" CONF_HUMIDITY = "humidity"
CONF_HUMIDITY_SENSOR = "humidity_sensor" CONF_HUMIDITY_SENSOR = "humidity_sensor"
CONF_HYDROGEN = "hydrogen"
CONF_HYSTERESIS = "hysteresis" CONF_HYSTERESIS = "hysteresis"
CONF_I2C = "i2c" CONF_I2C = "i2c"
CONF_I2C_ID = "i2c_id" CONF_I2C_ID = "i2c_id"
@ -477,6 +481,7 @@ CONF_MEDIA_PLAYER = "media_player"
CONF_MEDIUM = "medium" CONF_MEDIUM = "medium"
CONF_MEMORY_BLOCKS = "memory_blocks" CONF_MEMORY_BLOCKS = "memory_blocks"
CONF_MESSAGE = "message" CONF_MESSAGE = "message"
CONF_METHANE = "methane"
CONF_METHOD = "method" CONF_METHOD = "method"
CONF_MICROPHONE = "microphone" CONF_MICROPHONE = "microphone"
CONF_MIN_BRIGHTNESS = "min_brightness" CONF_MIN_BRIGHTNESS = "min_brightness"
@ -523,6 +528,7 @@ CONF_NBITS = "nbits"
CONF_NEC = "nec" CONF_NEC = "nec"
CONF_NETWORKS = "networks" CONF_NETWORKS = "networks"
CONF_NEW_PASSWORD = "new_password" CONF_NEW_PASSWORD = "new_password"
CONF_NITROGEN_DIOXIDE = "nitrogen_dioxide"
CONF_NOISE_LEVEL = "noise_level" CONF_NOISE_LEVEL = "noise_level"
CONF_NUM_ATTEMPTS = "num_attempts" CONF_NUM_ATTEMPTS = "num_attempts"
CONF_NUM_CHANNELS = "num_channels" CONF_NUM_CHANNELS = "num_channels"