Skip to content

Commit

Permalink
[mics_4514] Move consts to consts.py (esphome#7528)
Browse files Browse the repository at this point in the history
  • Loading branch information
jesserockz authored Oct 2, 2024
1 parent 0d80286 commit 361b6ab
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 26 deletions.
37 changes: 11 additions & 26 deletions esphome/components/mics_4514/sensor.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
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,
)

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_(
Expand All @@ -31,6 +28,7 @@
CONF_ETHANOL,
CONF_HYDROGEN,
CONF_AMMONIA,
CONF_NITROGEN_DIOXIDE,
]

common_sensor_schema = sensor.sensor_schema(
Expand All @@ -40,16 +38,7 @@
)

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"))
Expand All @@ -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))
6 changes: 6 additions & 0 deletions esphome/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
CONF_ALPHA = "alpha"
CONF_ALTITUDE = "altitude"
CONF_AMBIENT_LIGHT = "ambient_light"
CONF_AMMONIA = "ammonia"
CONF_ANALOG = "analog"
CONF_AND = "and"
CONF_ANGLE = "angle"
Expand Down Expand Up @@ -110,6 +111,7 @@
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"
Expand Down Expand Up @@ -263,6 +265,7 @@
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"
Expand Down Expand Up @@ -361,6 +364,7 @@
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"
Expand Down Expand Up @@ -477,6 +481,7 @@
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"
Expand Down Expand Up @@ -523,6 +528,7 @@
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"
Expand Down

0 comments on commit 361b6ab

Please sign in to comment.