esphome/esphomeyaml/components/sensor/apds9960.py
2019-01-06 19:38:23 +01:00

35 lines
1 KiB
Python

import voluptuous as vol
from esphomeyaml.components import sensor
from esphomeyaml.components.apds9960 import APDS9960, CONF_APDS9960_ID
import esphomeyaml.config_validation as cv
from esphomeyaml.const import CONF_NAME, CONF_TYPE
from esphomeyaml.cpp_generator import get_variable
DEPENDENCIES = ['apds9960']
TYPES = {
'CLEAR': 'make_clear_channel',
'RED': 'make_red_channel',
'GREEN': 'make_green_channel',
'BLUE': 'make_blue_channel',
'PROXIMITY': 'make_proximity',
}
PLATFORM_SCHEMA = cv.nameable(sensor.SENSOR_PLATFORM_SCHEMA.extend({
cv.GenerateID(): cv.declare_variable_id(sensor.Sensor),
vol.Required(CONF_TYPE): cv.one_of(*TYPES, upper=True),
cv.GenerateID(CONF_APDS9960_ID): cv.use_variable_id(APDS9960)
}))
def to_code(config):
for hub in get_variable(config[CONF_APDS9960_ID]):
yield
func = getattr(hub, TYPES[config[CONF_TYPE]])
rhs = func(config[CONF_NAME])
sensor.register_sensor(rhs, config)
def to_hass_config(data, config):
return sensor.core_to_hass_config(data, config)