mirror of
https://github.com/esphome/esphome.git
synced 2024-11-10 01:07:45 +01:00
PMSA003i Update state_class and async (#2216)
* Update component (state_class and async) * No need to specify empty device class * Remove unused import Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
parent
faf1c8bee8
commit
d2616cbdfc
1 changed files with 44 additions and 23 deletions
|
@ -16,7 +16,7 @@ from esphome.const import (
|
|||
DEVICE_CLASS_PM1,
|
||||
DEVICE_CLASS_PM10,
|
||||
DEVICE_CLASS_PM25,
|
||||
DEVICE_CLASS_EMPTY,
|
||||
STATE_CLASS_MEASUREMENT,
|
||||
)
|
||||
|
||||
CODEOWNERS = ["@sjtrny"]
|
||||
|
@ -39,40 +39,61 @@ CONFIG_SCHEMA = (
|
|||
cv.GenerateID(): cv.declare_id(PMSA003IComponent),
|
||||
cv.Optional(CONF_STANDARD_UNITS, default=True): cv.boolean,
|
||||
cv.Optional(CONF_PM_1_0): sensor.sensor_schema(
|
||||
UNIT_MICROGRAMS_PER_CUBIC_METER,
|
||||
ICON_CHEMICAL_WEAPON,
|
||||
2,
|
||||
DEVICE_CLASS_PM1,
|
||||
unit_of_measurement=UNIT_MICROGRAMS_PER_CUBIC_METER,
|
||||
icon=ICON_CHEMICAL_WEAPON,
|
||||
accuracy_decimals=2,
|
||||
device_class=DEVICE_CLASS_PM1,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
cv.Optional(CONF_PM_2_5): sensor.sensor_schema(
|
||||
UNIT_MICROGRAMS_PER_CUBIC_METER,
|
||||
ICON_CHEMICAL_WEAPON,
|
||||
2,
|
||||
DEVICE_CLASS_PM25,
|
||||
unit_of_measurement=UNIT_MICROGRAMS_PER_CUBIC_METER,
|
||||
icon=ICON_CHEMICAL_WEAPON,
|
||||
accuracy_decimals=2,
|
||||
device_class=DEVICE_CLASS_PM25,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
cv.Optional(CONF_PM_10_0): sensor.sensor_schema(
|
||||
UNIT_MICROGRAMS_PER_CUBIC_METER,
|
||||
ICON_CHEMICAL_WEAPON,
|
||||
2,
|
||||
DEVICE_CLASS_PM10,
|
||||
unit_of_measurement=UNIT_MICROGRAMS_PER_CUBIC_METER,
|
||||
icon=ICON_CHEMICAL_WEAPON,
|
||||
accuracy_decimals=2,
|
||||
device_class=DEVICE_CLASS_PM10,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
cv.Optional(CONF_PMC_0_3): sensor.sensor_schema(
|
||||
UNIT_COUNTS_PER_100ML, ICON_COUNTER, 0, DEVICE_CLASS_EMPTY
|
||||
unit_of_measurement=UNIT_COUNTS_PER_100ML,
|
||||
icon=ICON_COUNTER,
|
||||
accuracy_decimals=0,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
cv.Optional(CONF_PMC_0_5): sensor.sensor_schema(
|
||||
UNIT_COUNTS_PER_100ML, ICON_COUNTER, 0, DEVICE_CLASS_EMPTY
|
||||
unit_of_measurement=UNIT_COUNTS_PER_100ML,
|
||||
icon=ICON_COUNTER,
|
||||
accuracy_decimals=0,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
cv.Optional(CONF_PMC_1_0): sensor.sensor_schema(
|
||||
UNIT_COUNTS_PER_100ML, ICON_COUNTER, 0, DEVICE_CLASS_EMPTY
|
||||
unit_of_measurement=UNIT_COUNTS_PER_100ML,
|
||||
icon=ICON_COUNTER,
|
||||
accuracy_decimals=0,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
cv.Optional(CONF_PMC_2_5): sensor.sensor_schema(
|
||||
UNIT_COUNTS_PER_100ML, ICON_COUNTER, 0, DEVICE_CLASS_EMPTY
|
||||
unit_of_measurement=UNIT_COUNTS_PER_100ML,
|
||||
icon=ICON_COUNTER,
|
||||
accuracy_decimals=0,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
cv.Optional(CONF_PMC_5_0): sensor.sensor_schema(
|
||||
UNIT_COUNTS_PER_100ML, ICON_COUNTER, 0, DEVICE_CLASS_EMPTY
|
||||
unit_of_measurement=UNIT_COUNTS_PER_100ML,
|
||||
icon=ICON_COUNTER,
|
||||
accuracy_decimals=0,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
cv.Optional(CONF_PMC_10_0): sensor.sensor_schema(
|
||||
UNIT_COUNTS_PER_100ML, ICON_COUNTER, 0, DEVICE_CLASS_EMPTY
|
||||
unit_of_measurement=UNIT_COUNTS_PER_100ML,
|
||||
icon=ICON_COUNTER,
|
||||
accuracy_decimals=0,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
}
|
||||
)
|
||||
|
@ -93,15 +114,15 @@ TYPES = {
|
|||
}
|
||||
|
||||
|
||||
def to_code(config):
|
||||
async def to_code(config):
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
yield cg.register_component(var, config)
|
||||
yield i2c.register_i2c_device(var, config)
|
||||
await cg.register_component(var, config)
|
||||
await i2c.register_i2c_device(var, config)
|
||||
|
||||
cg.add(var.set_standard_units(config[CONF_STANDARD_UNITS]))
|
||||
|
||||
for key, funcName in TYPES.items():
|
||||
|
||||
if key in config:
|
||||
sens = yield sensor.new_sensor(config[key])
|
||||
sens = await sensor.new_sensor(config[key])
|
||||
cg.add(getattr(var, funcName)(sens))
|
||||
|
|
Loading…
Reference in a new issue