[mics_4514] Move consts to consts.py (#7528)

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
from esphome.components import i2c, sensor
import esphome.config_validation as cv
from esphome.components import sensor, i2c
from esphome.const import (
CONF_AMMONIA,
CONF_CARBON_MONOXIDE,
CONF_ETHANOL,
CONF_HYDROGEN,
CONF_ID,
CONF_METHANE,
CONF_NITROGEN_DIOXIDE,
STATE_CLASS_MEASUREMENT,
UNIT_PARTS_PER_MILLION,
)
@ -12,13 +16,6 @@ from esphome.const import (
CODEOWNERS = ["@jesserockz"]
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")
MICS4514Component = mics_4514_ns.class_(
@ -31,6 +28,7 @@ SENSORS = [
CONF_ETHANOL,
CONF_HYDROGEN,
CONF_AMMONIA,
CONF_NITROGEN_DIOXIDE,
]
common_sensor_schema = sensor.sensor_schema(
@ -40,16 +38,7 @@ common_sensor_schema = sensor.sensor_schema(
)
CONFIG_SCHEMA = (
cv.Schema(
{
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,
),
}
)
cv.Schema({cv.GenerateID(): cv.declare_id(MICS4514Component)})
.extend({cv.Optional(sensor_type): common_sensor_schema for sensor_type in SENSORS})
.extend(i2c.i2c_device_schema(0x75))
.extend(cv.polling_component_schema("60s"))
@ -62,10 +51,6 @@ async def to_code(config):
await i2c.register_i2c_device(var, config)
for sensor_type in SENSORS:
if sensor_type in config:
sens = await sensor.new_sensor(config[sensor_type])
if sensor_config := config.get(sensor_type):
sens = await sensor.new_sensor(sensor_config)
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_ALTITUDE = "altitude"
CONF_AMBIENT_LIGHT = "ambient_light"
CONF_AMMONIA = "ammonia"
CONF_ANALOG = "analog"
CONF_AND = "and"
CONF_ANGLE = "angle"
@ -110,6 +111,7 @@ CONF_CALIBRATE_LINEAR = "calibrate_linear"
CONF_CALIBRATION = "calibration"
CONF_CAPACITANCE = "capacitance"
CONF_CAPACITY = "capacity"
CONF_CARBON_MONOXIDE = "carbon_monoxide"
CONF_CARRIER_DUTY_PERCENT = "carrier_duty_percent"
CONF_CARRIER_FREQUENCY = "carrier_frequency"
CONF_CERTIFICATE = "certificate"
@ -263,6 +265,7 @@ CONF_ENUM_DATAPOINT = "enum_datapoint"
CONF_EQUATION = "equation"
CONF_ESP8266_DISABLE_SSL_SUPPORT = "esp8266_disable_ssl_support"
CONF_ESPHOME = "esphome"
CONF_ETHANOL = "ethanol"
CONF_ETHERNET = "ethernet"
CONF_EVENT = "event"
CONF_EVENT_TYPE = "event_type"
@ -361,6 +364,7 @@ CONF_HOURS = "hours"
CONF_HSYNC_PIN = "hsync_pin"
CONF_HUMIDITY = "humidity"
CONF_HUMIDITY_SENSOR = "humidity_sensor"
CONF_HYDROGEN = "hydrogen"
CONF_HYSTERESIS = "hysteresis"
CONF_I2C = "i2c"
CONF_I2C_ID = "i2c_id"
@ -477,6 +481,7 @@ CONF_MEDIA_PLAYER = "media_player"
CONF_MEDIUM = "medium"
CONF_MEMORY_BLOCKS = "memory_blocks"
CONF_MESSAGE = "message"
CONF_METHANE = "methane"
CONF_METHOD = "method"
CONF_MICROPHONE = "microphone"
CONF_MIN_BRIGHTNESS = "min_brightness"
@ -523,6 +528,7 @@ CONF_NBITS = "nbits"
CONF_NEC = "nec"
CONF_NETWORKS = "networks"
CONF_NEW_PASSWORD = "new_password"
CONF_NITROGEN_DIOXIDE = "nitrogen_dioxide"
CONF_NOISE_LEVEL = "noise_level"
CONF_NUM_ATTEMPTS = "num_attempts"
CONF_NUM_CHANNELS = "num_channels"