mirror of
https://github.com/esphome/esphome.git
synced 2025-03-15 07:08:20 +00:00
Refactore ppd42x.py
This commit is contained in:
parent
788af8a58a
commit
0000b47704
@ -18,7 +18,7 @@ CONF_PPD42NS = 'PPD42NS'
|
|||||||
|
|
||||||
PPD42XType = sensor.sensor_ns.enum('PPD42XType')
|
PPD42XType = sensor.sensor_ns.enum('PPD42XType')
|
||||||
PPD42X_TYPES = {
|
PPD42X_TYPES = {
|
||||||
CONF_PPD42__: PPD42XType.PPD42_TYPE___,
|
CONF_PPD42__: PPD42XType.PPD42X_TYPE___,
|
||||||
CONF_PPD42NS: PPD42XType.PPD42X_TYPE_NS,
|
CONF_PPD42NS: PPD42XType.PPD42X_TYPE_NS,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,18 +52,18 @@ PLATFORM_SCHEMA = cv.nameable(sensor.PLATFORM_SCHEMA.extend({
|
|||||||
|
|
||||||
def to_code(config):
|
def to_code(config):
|
||||||
rhs = App.make_ppd42x(config[CONF_NAME], PPD42X_TYPES[config[CONF_TYPE]])
|
rhs = App.make_ppd42x(config[CONF_NAME], PPD42X_TYPES[config[CONF_TYPE]])
|
||||||
pms = Pvariable(config[CONF_ID], rhs)
|
ppd = Pvariable(config[CONF_ID], rhs)
|
||||||
if CONF_PM_2_5 in config:
|
if CONF_PM_2_5 in config:
|
||||||
conf = config[CONF_PM_2_5]
|
conf = config[CONF_PM_2_5]
|
||||||
for pm_02_5 in get_variable(conf[CONF_PIN]):
|
for pm_02_5 in get_variable(conf[CONF_PIN]):
|
||||||
yield
|
yield
|
||||||
sensor.register_sensor(pms.make_pm_2_5_sensor(conf[CONF_NAME]), conf)
|
sensor.register_sensor(ppd.make_pm_02_5_sensor(conf[CONF_NAME]), pm_02_5)
|
||||||
if CONF_PM_10_0 in config:
|
if CONF_PM_10_0 in config:
|
||||||
conf = config[CONF_PM_10_0]
|
conf = config[CONF_PM_10_0]
|
||||||
for pm_10_0 in get_variable(conf[CONF_PIN]):
|
for pm_10_0 in get_variable(conf[CONF_PIN]):
|
||||||
yield
|
yield
|
||||||
sensor.register_sensor(pms.make_pm_10_0_sensor(conf[CONF_NAME]), conf)
|
sensor.register_sensor(ppd.make_pm_10_0_sensor(conf[CONF_NAME]), pm_10_0)
|
||||||
setup_component(pms, config)
|
setup_component(ppd, config)
|
||||||
|
|
||||||
|
|
||||||
BUILD_FLAGS = '-DUSE_PPD42X'
|
BUILD_FLAGS = '-DUSE_PPD42X'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user