diff --git a/esphomeyaml/components/apds9960.py b/esphomeyaml/components/apds9960.py new file mode 100644 index 0000000000..e9f7782b43 --- /dev/null +++ b/esphomeyaml/components/apds9960.py @@ -0,0 +1,33 @@ +import voluptuous as vol + +from esphomeyaml.components import i2c, sensor +import esphomeyaml.config_validation as cv +from esphomeyaml.const import CONF_ADDRESS, CONF_ID, CONF_UPDATE_INTERVAL +from esphomeyaml.cpp_generator import Pvariable, add +from esphomeyaml.cpp_helpers import setup_component +from esphomeyaml.cpp_types import App, PollingComponent + +DEPENDENCIES = ['i2c'] +MULTI_CONF = True + +CONF_APDS9960_ID = 'apds9960_id' +APDS9960 = sensor.sensor_ns.class_('APDS9960', PollingComponent, i2c.I2CDevice) + +CONFIG_SCHEMA = vol.Schema({ + cv.GenerateID(): cv.declare_variable_id(APDS9960), + vol.Optional(CONF_ADDRESS): cv.i2c_address, + vol.Optional(CONF_UPDATE_INTERVAL): cv.update_interval, +}).extend(cv.COMPONENT_SCHEMA.schema) + + +def to_code(config): + rhs = App.make_apds9960(config.get(CONF_UPDATE_INTERVAL)) + var = Pvariable(config[CONF_ID], rhs) + + if CONF_ADDRESS in config: + add(var.set_address(config[CONF_ADDRESS])) + + setup_component(var, config) + + +BUILD_FLAGS = '-DUSE_APDS9960' diff --git a/esphomeyaml/components/binary_sensor/apds9960.py b/esphomeyaml/components/binary_sensor/apds9960.py new file mode 100644 index 0000000000..11444bce88 --- /dev/null +++ b/esphomeyaml/components/binary_sensor/apds9960.py @@ -0,0 +1,36 @@ +import voluptuous as vol + +from esphomeyaml.components import binary_sensor, sensor +from esphomeyaml.components.apds9960 import APDS9960, CONF_APDS9960_ID +import esphomeyaml.config_validation as cv +from esphomeyaml.const import CONF_DIRECTION, CONF_NAME +from esphomeyaml.cpp_generator import get_variable + +DEPENDENCIES = ['apds9960'] +APDS9960GestureDirectionBinarySensor = sensor.sensor_ns.class_( + 'APDS9960GestureDirectionBinarySensor', binary_sensor.BinarySensor) + +DIRECTIONS = { + 'UP': 'make_up_direction', + 'DOWN': 'make_down_direction', + 'LEFT': 'make_left_direction', + 'RIGHT': 'make_right_direction', +} + +PLATFORM_SCHEMA = cv.nameable(binary_sensor.BINARY_SENSOR_PLATFORM_SCHEMA.extend({ + cv.GenerateID(): cv.declare_variable_id(APDS9960GestureDirectionBinarySensor), + vol.Required(CONF_DIRECTION): cv.one_of(*DIRECTIONS, 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, DIRECTIONS[config[CONF_DIRECTION]]) + rhs = func(config[CONF_NAME]) + binary_sensor.register_binary_sensor(rhs, config) + + +def to_hass_config(data, config): + return binary_sensor.core_to_hass_config(data, config) diff --git a/esphomeyaml/components/sensor/apds9960.py b/esphomeyaml/components/sensor/apds9960.py new file mode 100644 index 0000000000..ddd9fd7d5b --- /dev/null +++ b/esphomeyaml/components/sensor/apds9960.py @@ -0,0 +1,35 @@ +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) diff --git a/esphomeyaml/const.py b/esphomeyaml/const.py index a0f7361522..b727c24126 100644 --- a/esphomeyaml/const.py +++ b/esphomeyaml/const.py @@ -395,6 +395,7 @@ CONF_SERVICE = 'service' CONF_ENTITY_ID = 'entity_id' CONF_RESTORE_MODE = 'restore_mode' CONF_INTERVAL = 'interval' +CONF_DIRECTION = 'direction' ALLOWED_NAME_CHARS = u'abcdefghijklmnopqrstuvwxyz0123456789_' ARDUINO_VERSION_ESP32_DEV = 'https://github.com/platformio/platform-espressif32.git#feature/stage' diff --git a/tests/test2.yaml b/tests/test2.yaml index cee34a8cab..4619008b73 100644 --- a/tests/test2.yaml +++ b/tests/test2.yaml @@ -118,6 +118,25 @@ sensor: name: "CSE7766 Current" power: name: "CSE776 Power" + - platform: apds9960 + type: proximity + name: APDS9960 Proximity + - platform: apds9960 + type: clear + name: APDS9960 Clear + - platform: apds9960 + type: red + name: APDS9960 Red + - platform: apds9960 + type: green + name: APDS9960 Green + - platform: apds9960 + type: blue + name: APDS9960 Blue + +apds9960: + address: 0x20 + update_interval: 60s esp32_touch: setup_mode: True @@ -130,6 +149,18 @@ binary_sensor: name: "ESP32 Touch Pad GPIO27" pin: GPIO27 threshold: 1000 + - platform: apds9960 + direction: up + name: APDS9960 Up + - platform: apds9960 + direction: down + name: APDS9960 Down + - platform: apds9960 + direction: left + name: APDS9960 Left + - platform: apds9960 + direction: right + name: APDS9960 Right remote_receiver: pin: GPIO32