COVER_OPEN = cover_ns.COVER_OPEN COVER_CLOSED = cover_ns.COVER_CLOSED validate_cover_state = cv.one_of('OPEN', 'CLOSED', upper=True) COVER_STATES = { 'OPEN': COVER_OPEN, 'CLOSED': COVER_CLOSED, } # Actions OpenAction = cover_ns.class_('OpenAction', Action) CloseAction = cover_ns.class_('CloseAction', Action) StopAction = cover_ns.class_('StopAction', Action) COVER_SCHEMA = cv.MQTT_COMMAND_COMPONENT_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(Cover), cv.GenerateID(CONF_MQTT_ID): cv.declare_variable_id(MQTTCoverComponent), }) COVER_PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(COVER_SCHEMA.schema) def setup_cover_core_(cover_var, config): if CONF_INTERNAL in config: add(cover_var.set_internal(config[CONF_INTERNAL])) setup_mqtt_component(cover_var.Pget_mqtt(), config) def setup_cover(cover_obj, config): CORE.add_job(setup_cover_core_, cover_obj, config)
from esphome.automation import ACTION_REGISTRY from esphome.components import sensor import esphome.config_validation as cv from esphome.const import CONF_ID, CONF_LAMBDA, CONF_NAME, CONF_STATE, CONF_UPDATE_INTERVAL from esphome.cpp_generator import Pvariable, add, get_variable, process_lambda, templatable from esphome.cpp_helpers import setup_component from esphome.cpp_types import Action, App, float_, optional TemplateSensor = sensor.sensor_ns.class_('TemplateSensor', sensor.PollingSensorComponent) SensorPublishAction = sensor.sensor_ns.class_('SensorPublishAction', Action) PLATFORM_SCHEMA = cv.nameable( sensor.SENSOR_PLATFORM_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(TemplateSensor), vol.Optional(CONF_LAMBDA): cv.lambda_, vol.Optional(CONF_UPDATE_INTERVAL): cv.update_interval, }).extend(cv.COMPONENT_SCHEMA.schema)) def to_code(config): rhs = App.make_template_sensor(config[CONF_NAME], config.get(CONF_UPDATE_INTERVAL)) template = Pvariable(config[CONF_ID], rhs) sensor.setup_sensor(template, config) setup_component(template, config)
import esphome.config_validation as cv from esphome.const import CONF_ID, CONF_NAME, CONF_UPDATE_INTERVAL, ESP_PLATFORM_ESP32 from esphome.cpp_generator import Pvariable from esphome.cpp_helpers import setup_component from esphome.cpp_types import App, Application ESP_PLATFORMS = [ESP_PLATFORM_ESP32] MakeESP32HallSensor = Application.struct('MakeESP32HallSensor') ESP32HallSensor = sensor.sensor_ns.class_('ESP32HallSensor', sensor.PollingSensorComponent) PLATFORM_SCHEMA = cv.nameable( sensor.SENSOR_PLATFORM_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(ESP32HallSensor), vol.Optional(CONF_UPDATE_INTERVAL): cv.update_interval, }).extend(cv.COMPONENT_SCHEMA.schema)) def to_code(config): rhs = App.make_esp32_hall_sensor(config[CONF_NAME], config.get(CONF_UPDATE_INTERVAL)) hall = Pvariable(config[CONF_ID], rhs) sensor.setup_sensor(hall, config) setup_component(hall, config) BUILD_FLAGS = '-DUSE_ESP32_HALL_SENSOR'
from esphome.components import switch import esphome.config_validation as cv from esphome.const import CONF_ASSUMED_STATE, CONF_ID, CONF_LAMBDA, CONF_NAME, CONF_OPTIMISTIC, \ CONF_RESTORE_STATE, CONF_STATE, CONF_TURN_OFF_ACTION, CONF_TURN_ON_ACTION from esphome.cpp_generator import Pvariable, add, get_variable, process_lambda, templatable from esphome.cpp_helpers import setup_component from esphome.cpp_types import Action, App, Component, bool_, optional TemplateSwitch = switch.switch_ns.class_('TemplateSwitch', switch.Switch, Component) SwitchPublishAction = switch.switch_ns.class_('SwitchPublishAction', Action) PLATFORM_SCHEMA = cv.nameable( switch.SWITCH_PLATFORM_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(TemplateSwitch), vol.Optional(CONF_LAMBDA): cv.lambda_, vol.Optional(CONF_OPTIMISTIC): cv.boolean, vol.Optional(CONF_ASSUMED_STATE): cv.boolean, vol.Optional(CONF_TURN_OFF_ACTION): automation.validate_automation(single=True), vol.Optional(CONF_TURN_ON_ACTION): automation.validate_automation(single=True), vol.Optional(CONF_RESTORE_STATE): cv.boolean, }).extend(cv.COMPONENT_SCHEMA.schema))
try: import pytz return convert_tz(pytz.timezone(value)) except Exception: # pylint: disable=broad-except return value TIME_PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Optional(CONF_TIMEZONE, default=detect_tz): validate_tz, vol.Optional(CONF_ON_TIME): automation.validate_automation( { cv.GenerateID(CONF_TRIGGER_ID): cv.declare_variable_id(CronTrigger), vol.Optional(CONF_SECONDS): validate_cron_seconds, vol.Optional(CONF_MINUTES): validate_cron_minutes, vol.Optional(CONF_HOURS): validate_cron_hours, vol.Optional(CONF_DAYS_OF_MONTH): validate_cron_days_of_month, vol.Optional(CONF_MONTHS): validate_cron_months, vol.Optional(CONF_DAYS_OF_WEEK): validate_cron_days_of_week, vol.Optional(CONF_CRON): validate_cron_raw, }, validate_cron_keys), }) def setup_time_core_(time_var, config): add(time_var.set_timezone(config[CONF_TIMEZONE])) for conf in config.get(CONF_ON_TIME, []):
def validate(config): if CONF_USE_ADDRESS not in config: if CONF_MANUAL_IP in config: use_address = str(config[CONF_MANUAL_IP][CONF_STATIC_IP]) else: use_address = CORE.name + config[CONF_DOMAIN] config[CONF_USE_ADDRESS] = use_address return config CONFIG_SCHEMA = vol.All( vol.Schema({ cv.GenerateID(): cv.declare_variable_id(EthernetComponent), vol.Required(CONF_TYPE): cv.one_of(*ETHERNET_TYPES, upper=True), vol.Required(CONF_MDC_PIN): pins.output_pin, vol.Required(CONF_MDIO_PIN): pins.input_output_pin, vol.Optional(CONF_CLK_MODE, default='GPIO0_IN'): cv.one_of(*CLK_MODES, upper=True, space='_'), vol.Optional(CONF_PHY_ADDR, default=0): vol.All(cv.int_, vol.Range(min=0, max=31)), vol.Optional(CONF_POWER_PIN): pins.gpio_output_pin_schema, vol.Optional(CONF_MANUAL_IP): wifi.STA_MANUAL_IP_SCHEMA, vol.Optional(CONF_DOMAIN, default='.local'):
import voluptuous as vol from esphome import pins import esphome.config_validation as cv from esphome.const import CONF_ENABLE_TIME, CONF_ID, CONF_KEEP_ON_TIME, CONF_PIN from esphome.cpp_generator import Pvariable, add from esphome.cpp_helpers import gpio_output_pin_expression, setup_component from esphome.cpp_types import App, Component, esphome_ns PowerSupplyComponent = esphome_ns.class_('PowerSupplyComponent', Component) MULTI_CONF = True CONFIG_SCHEMA = vol.Schema({ vol.Required(CONF_ID): cv.declare_variable_id(PowerSupplyComponent), vol.Required(CONF_PIN): pins.gpio_output_pin_schema, vol.Optional(CONF_ENABLE_TIME): cv.positive_time_period_milliseconds, vol.Optional(CONF_KEEP_ON_TIME): cv.positive_time_period_milliseconds, }).extend(cv.COMPONENT_SCHEMA.schema) def to_code(config): for pin in gpio_output_pin_expression(config[CONF_PIN]): yield rhs = App.make_power_supply(pin) psu = Pvariable(config[CONF_ID], rhs) if CONF_ENABLE_TIME in config: add(psu.set_enable_time(config[CONF_ENABLE_TIME])) if CONF_KEEP_ON_TIME in config: add(psu.set_keep_on_time(config[CONF_KEEP_ON_TIME]))
'INVERT_WAKEUP': WakeupPinMode.WAKEUP_PIN_MODE_INVERT_WAKEUP, } esp_sleep_ext1_wakeup_mode_t = global_ns.enum('esp_sleep_ext1_wakeup_mode_t') Ext1Wakeup = esphome_ns.struct('Ext1Wakeup') EXT1_WAKEUP_MODES = { 'ALL_LOW': esp_sleep_ext1_wakeup_mode_t.ESP_EXT1_WAKEUP_ALL_LOW, 'ANY_HIGH': esp_sleep_ext1_wakeup_mode_t.ESP_EXT1_WAKEUP_ANY_HIGH, } CONF_WAKEUP_PIN_MODE = 'wakeup_pin_mode' CONF_ESP32_EXT1_WAKEUP = 'esp32_ext1_wakeup' CONFIG_SCHEMA = cv.Schema({ cv.GenerateID(): cv.declare_variable_id(DeepSleepComponent), vol.Optional(CONF_SLEEP_DURATION): cv.positive_time_period_milliseconds, vol.Optional(CONF_WAKEUP_PIN): vol.All(cv.only_on_esp32, pins.internal_gpio_input_pin_schema, validate_pin_number), vol.Optional(CONF_WAKEUP_PIN_MODE): vol.All(cv.only_on_esp32, cv.one_of(*WAKEUP_PIN_MODES), upper=True), vol.Optional(CONF_ESP32_EXT1_WAKEUP): vol.All( cv.only_on_esp32, cv.Schema({ vol.Required(CONF_PINS): cv.ensure_list(pins.shorthand_input_pin, validate_pin_number), vol.Required(CONF_MODE): cv.one_of(*EXT1_WAKEUP_MODES, upper=True),
import voluptuous as vol from esphome import pins import esphome.config_validation as cv from esphome.const import CONF_BAUD_RATE, CONF_ID, CONF_RX_PIN, CONF_TX_PIN from esphome.cpp_generator import Pvariable, add from esphome.cpp_helpers import setup_component from esphome.cpp_types import App, Component, esphome_ns UARTComponent = esphome_ns.class_('UARTComponent', Component) UARTDevice = esphome_ns.class_('UARTDevice') MULTI_CONF = True CONFIG_SCHEMA = vol.All(vol.Schema({ cv.GenerateID(): cv.declare_variable_id(UARTComponent), vol.Optional(CONF_TX_PIN): pins.output_pin, vol.Optional(CONF_RX_PIN): pins.input_pin, vol.Required(CONF_BAUD_RATE): cv.positive_int, }).extend(cv.COMPONENT_SCHEMA.schema), cv.has_at_least_one_key(CONF_TX_PIN, CONF_RX_PIN)) def to_code(config): rhs = App.init_uart(config[CONF_BAUD_RATE]) var = Pvariable(config[CONF_ID], rhs) if CONF_TX_PIN in config: add(var.set_tx_pin(config[CONF_TX_PIN])) if CONF_RX_PIN in config: add(var.set_rx_pin(config[CONF_RX_PIN])) setup_component(var, config)
import voluptuous as vol from esphome.components import output from esphome.components.pca9685 import PCA9685OutputComponent import esphome.config_validation as cv from esphome.const import CONF_CHANNEL, CONF_ID, CONF_PCA9685_ID, CONF_POWER_SUPPLY from esphome.cpp_generator import Pvariable, get_variable DEPENDENCIES = ['pca9685'] Channel = PCA9685OutputComponent.class_('Channel', output.FloatOutput) PLATFORM_SCHEMA = output.FLOAT_OUTPUT_PLATFORM_SCHEMA.extend({ vol.Required(CONF_ID): cv.declare_variable_id(Channel), vol.Required(CONF_CHANNEL): vol.All(vol.Coerce(int), vol.Range(min=0, max=15)), cv.GenerateID(CONF_PCA9685_ID): cv.use_variable_id(PCA9685OutputComponent), }) def to_code(config): power_supply = None if CONF_POWER_SUPPLY in config: for power_supply in get_variable(config[CONF_POWER_SUPPLY]): yield for pca9685 in get_variable(config[CONF_PCA9685_ID]): yield rhs = pca9685.create_channel(config[CONF_CHANNEL], power_supply) out = Pvariable(config[CONF_ID], rhs)
from esphome.cpp_generator import Pvariable, get_variable from esphome.cpp_helpers import setup_component from esphome.cpp_types import App, PollingComponent DEPENDENCIES = ['uart'] CSE7766Component = sensor.sensor_ns.class_('CSE7766Component', PollingComponent, uart.UARTDevice) CSE7766VoltageSensor = sensor.sensor_ns.class_('CSE7766VoltageSensor', sensor.EmptySensor) CSE7766CurrentSensor = sensor.sensor_ns.class_('CSE7766CurrentSensor', sensor.EmptySensor) CSE7766PowerSensor = sensor.sensor_ns.class_('CSE7766PowerSensor', sensor.EmptySensor) PLATFORM_SCHEMA = vol.All(sensor.PLATFORM_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(CSE7766Component), cv.GenerateID(CONF_UART_ID): cv.use_variable_id(UARTComponent), vol.Optional(CONF_VOLTAGE): cv.nameable(sensor.SENSOR_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(CSE7766VoltageSensor), })), vol.Optional(CONF_CURRENT): cv.nameable(sensor.SENSOR_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(CSE7766CurrentSensor), })), vol.Optional(CONF_POWER): cv.nameable(sensor.SENSOR_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(CSE7766PowerSensor), })), vol.Optional(CONF_UPDATE_INTERVAL): cv.update_interval, }).extend(cv.COMPONENT_SCHEMA.schema), cv.has_at_least_one_key(CONF_VOLTAGE, CONF_CURRENT, CONF_POWER))
from esphome import config_validation as cv from esphome.components import sensor from esphome.const import CONF_ID, CONF_SCAN_INTERVAL, ESP_PLATFORM_ESP32 from esphome.core import HexInt from esphome.cpp_generator import Pvariable, add from esphome.cpp_helpers import setup_component from esphome.cpp_types import App, Component, esphome_ns ESP_PLATFORMS = [ESP_PLATFORM_ESP32] CONF_ESP32_BLE_ID = 'esp32_ble_id' ESP32BLETracker = esphome_ns.class_('ESP32BLETracker', Component) XiaomiSensor = esphome_ns.class_('XiaomiSensor', sensor.Sensor) XiaomiDevice = esphome_ns.class_('XiaomiDevice') XIAOMI_SENSOR_SCHEMA = sensor.SENSOR_SCHEMA.extend( {cv.GenerateID(): cv.declare_variable_id(XiaomiSensor)}) CONFIG_SCHEMA = vol.Schema({ cv.GenerateID(): cv.declare_variable_id(ESP32BLETracker), vol.Optional(CONF_SCAN_INTERVAL): cv.positive_time_period_seconds, }).extend(cv.COMPONENT_SCHEMA.schema) def make_address_array(address): return [HexInt(i) for i in address.parts] def to_code(config): rhs = App.make_esp32_ble_tracker()
PartitionLightOutput = light.light_ns.class_('PartitionLightOutput', AddressableLight) MakePartitionLight = Application.struct('MakePartitionLight') def validate_from_to(value): if value[CONF_FROM] > value[CONF_TO]: raise vol.Invalid(u"From ({}) must not be larger than to ({})" u"".format(value[CONF_FROM], value[CONF_TO])) return value PLATFORM_SCHEMA = cv.nameable( light.LIGHT_PLATFORM_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(light.AddressableLightState), cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(MakePartitionLight), vol.Required(CONF_SEGMENTS): vol.All( cv.ensure_list( { vol.Required(CONF_ID): cv.use_variable_id(light.AddressableLightState), vol.Required(CONF_FROM): cv.positive_int, vol.Required(CONF_TO): cv.positive_int, }, validate_from_to), vol.Length(min=1)), vol.Optional(CONF_GAMMA_CORRECT): cv.positive_float,
from esphome.components import binary_sensor from esphome.components.esp32_ble_tracker import CONF_ESP32_BLE_ID, ESP32BLETracker, \ make_address_array import esphome.config_validation as cv from esphome.const import CONF_MAC_ADDRESS, CONF_NAME from esphome.cpp_generator import get_variable from esphome.cpp_types import esphome_ns DEPENDENCIES = ['esp32_ble_tracker'] ESP32BLEPresenceDevice = esphome_ns.class_('ESP32BLEPresenceDevice', binary_sensor.BinarySensor) PLATFORM_SCHEMA = cv.nameable( binary_sensor.BINARY_SENSOR_PLATFORM_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(ESP32BLEPresenceDevice), vol.Required(CONF_MAC_ADDRESS): cv.mac_address, cv.GenerateID(CONF_ESP32_BLE_ID): cv.use_variable_id(ESP32BLETracker) })) def to_code(config): for hub in get_variable(config[CONF_ESP32_BLE_ID]): yield rhs = hub.make_presence_sensor( config[CONF_NAME], make_address_array(config[CONF_MAC_ADDRESS])) binary_sensor.register_binary_sensor(rhs, config)
import voluptuous as vol from esphome.components import text_sensor import esphome.config_validation as cv from esphome.const import CONF_ID, CONF_LAMBDA, CONF_NAME, CONF_TEXT_SENSORS from esphome.cpp_generator import add, process_lambda, variable from esphome.cpp_types import std_vector CustomTextSensorConstructor = text_sensor.text_sensor_ns.class_( 'CustomTextSensorConstructor') PLATFORM_SCHEMA = text_sensor.PLATFORM_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(CustomTextSensorConstructor), vol.Required(CONF_LAMBDA): cv.lambda_, vol.Required(CONF_TEXT_SENSORS): cv.ensure_list( text_sensor.TEXT_SENSOR_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(text_sensor.TextSensor), })), }) def to_code(config): for template_ in process_lambda(config[CONF_LAMBDA], [], return_type=std_vector.template( text_sensor.TextSensorPtr)): yield
BMP280_OVERSAMPLING_SENSOR_SCHEMA = sensor.SENSOR_SCHEMA.extend({ vol.Optional(CONF_OVERSAMPLING): cv.one_of(*OVERSAMPLING_OPTIONS, upper=True), }) BMP280Component = sensor.sensor_ns.class_('BMP280Component', PollingComponent, i2c.I2CDevice) BMP280TemperatureSensor = sensor.sensor_ns.class_( 'BMP280TemperatureSensor', sensor.EmptyPollingParentSensor) BMP280PressureSensor = sensor.sensor_ns.class_('BMP280PressureSensor', sensor.EmptyPollingParentSensor) PLATFORM_SCHEMA = sensor.PLATFORM_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(BMP280Component), vol.Optional(CONF_ADDRESS, default=0x77): cv.i2c_address, vol.Required(CONF_TEMPERATURE): cv.nameable( BMP280_OVERSAMPLING_SENSOR_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(BMP280TemperatureSensor), })), vol.Required(CONF_PRESSURE): cv.nameable( BMP280_OVERSAMPLING_SENSOR_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(BMP280PressureSensor), })), vol.Optional(CONF_IIR_FILTER):
from esphome.components import text_sensor import esphome.config_validation as cv from esphome.const import CONF_ENTITY_ID, CONF_ID, CONF_NAME from esphome.cpp_generator import Pvariable from esphome.cpp_types import App, Component DEPENDENCIES = ['api'] HomeassistantTextSensor = text_sensor.text_sensor_ns.class_( 'HomeassistantTextSensor', text_sensor.TextSensor, Component) PLATFORM_SCHEMA = cv.nameable( text_sensor.TEXT_SENSOR_PLATFORM_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(HomeassistantTextSensor), vol.Required(CONF_ENTITY_ID): cv.entity_id, })) def to_code(config): rhs = App.make_homeassistant_text_sensor(config[CONF_NAME], config[CONF_ENTITY_ID]) sensor_ = Pvariable(config[CONF_ID], rhs) text_sensor.setup_text_sensor(sensor_, config) BUILD_FLAGS = '-DUSE_HOMEASSISTANT_TEXT_SENSOR'
import voluptuous as vol from esphome.components import light, output from esphome.components.light.rgbww import validate_cold_white_colder, \ validate_color_temperature import esphome.config_validation as cv from esphome.const import CONF_COLD_WHITE, CONF_COLD_WHITE_COLOR_TEMPERATURE, \ CONF_DEFAULT_TRANSITION_LENGTH, CONF_EFFECTS, CONF_GAMMA_CORRECT, CONF_MAKE_ID, \ CONF_NAME, CONF_WARM_WHITE, CONF_WARM_WHITE_COLOR_TEMPERATURE from esphome.cpp_generator import get_variable, variable from esphome.cpp_helpers import setup_component from esphome.cpp_types import App PLATFORM_SCHEMA = cv.nameable(light.LIGHT_PLATFORM_SCHEMA.extend({ cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(light.MakeLight), vol.Required(CONF_COLD_WHITE): cv.use_variable_id(output.FloatOutput), vol.Required(CONF_WARM_WHITE): cv.use_variable_id(output.FloatOutput), vol.Required(CONF_COLD_WHITE_COLOR_TEMPERATURE): validate_color_temperature, vol.Required(CONF_WARM_WHITE_COLOR_TEMPERATURE): validate_color_temperature, vol.Optional(CONF_GAMMA_CORRECT): cv.positive_float, vol.Optional(CONF_DEFAULT_TRANSITION_LENGTH): cv.positive_time_period_milliseconds, vol.Optional(CONF_EFFECTS): light.validate_effects(light.MONOCHROMATIC_EFFECTS), }).extend(cv.COMPONENT_SCHEMA.schema), validate_cold_white_colder) def to_code(config): for cold_white in get_variable(config[CONF_COLD_WHITE]): yield for warm_white in get_variable(config[CONF_WARM_WHITE]): yield
810: HMC5883LRange.HMC5883L_RANGE_810_UT, } def validate_range(value): value = cv.string(value) if value.endswith(u'µT') or value.endswith('uT'): value = value[:-2] return cv.one_of(*HMC5883L_RANGES, int=True)(value) SENSOR_KEYS = [CONF_FIELD_STRENGTH_X, CONF_FIELD_STRENGTH_Y, CONF_FIELD_STRENGTH_Z, CONF_HEADING] PLATFORM_SCHEMA = vol.All(sensor.PLATFORM_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(HMC5883LComponent), vol.Optional(CONF_ADDRESS): cv.i2c_address, vol.Optional(CONF_FIELD_STRENGTH_X): cv.nameable(sensor.SENSOR_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(HMC5883LFieldStrengthSensor), })), vol.Optional(CONF_FIELD_STRENGTH_Y): cv.nameable(sensor.SENSOR_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(HMC5883LFieldStrengthSensor), })), vol.Optional(CONF_FIELD_STRENGTH_Z): cv.nameable(sensor.SENSOR_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(HMC5883LFieldStrengthSensor), })), vol.Optional(CONF_HEADING): cv.nameable(sensor.SENSOR_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(HMC5883LHeadingSensor), })), vol.Optional(CONF_UPDATE_INTERVAL): cv.update_interval, vol.Optional(CONF_RANGE): validate_range,
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)
import voluptuous as vol from esphome.components import sensor import esphome.config_validation as cv from esphome.const import CONF_ID, CONF_NAME, CONF_QOS, CONF_TOPIC from esphome.cpp_generator import Pvariable, add from esphome.cpp_helpers import setup_component from esphome.cpp_types import App, Component DEPENDENCIES = ['mqtt'] MQTTSubscribeSensor = sensor.sensor_ns.class_('MQTTSubscribeSensor', sensor.Sensor, Component) PLATFORM_SCHEMA = cv.nameable(sensor.SENSOR_PLATFORM_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(MQTTSubscribeSensor), vol.Required(CONF_TOPIC): cv.subscribe_topic, vol.Optional(CONF_QOS): cv.mqtt_qos, }).extend(cv.COMPONENT_SCHEMA.schema)) def to_code(config): rhs = App.make_mqtt_subscribe_sensor(config[CONF_NAME], config[CONF_TOPIC]) subs = Pvariable(config[CONF_ID], rhs) if CONF_QOS in config: add(subs.set_qos(config[CONF_QOS])) sensor.setup_sensor(subs, config) setup_component(subs, config)
from esphome.cpp_generator import Pvariable from esphome.cpp_helpers import setup_component from esphome.cpp_types import App, PollingComponent DEPENDENCIES = ['i2c'] SHT3XDComponent = sensor.sensor_ns.class_('SHT3XDComponent', PollingComponent, i2c.I2CDevice) SHT3XDTemperatureSensor = sensor.sensor_ns.class_( 'SHT3XDTemperatureSensor', sensor.EmptyPollingParentSensor) SHT3XDHumiditySensor = sensor.sensor_ns.class_('SHT3XDHumiditySensor', sensor.EmptyPollingParentSensor) PLATFORM_SCHEMA = sensor.PLATFORM_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(SHT3XDComponent), vol.Required(CONF_TEMPERATURE): cv.nameable( sensor.SENSOR_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(SHT3XDTemperatureSensor), })), vol.Required(CONF_HUMIDITY): cv.nameable( sensor.SENSOR_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(SHT3XDHumiditySensor), })), vol.Optional(CONF_ADDRESS, default=0x44): cv.i2c_address, vol.Optional(CONF_UPDATE_INTERVAL):
DEPENDENCIES = ['i2c'] MULTI_CONF = True CAT9554GPIOMode = io_ns.enum('CAT9554GPIOMode') CAT9554_GPIO_MODES = { 'INPUT': CAT9554GPIOMode.CAT9554_INPUT, 'INPUT_PULLUP': CAT9554GPIOMode.CAT9554_INPUT_PULLUP, 'OUTPUT': CAT9554GPIOMode.CAT9554_OUTPUT, } CAT9554GPIOInputPin = io_ns.class_('CAT9554GPIOInputPin', GPIOInputPin) CAT9554GPIOOutputPin = io_ns.class_('CAT9554GPIOOutputPin', GPIOOutputPin) CONFIG_SCHEMA = cv.Schema({ vol.Required(CONF_ID): cv.declare_variable_id(pins.CAT9554Component), vol.Required('irq'): pins.input_pin, vol.Optional(CONF_ADDRESS, default=0x20): cv.i2c_address, }).extend(cv.COMPONENT_SCHEMA.schema) def to_code(config): rhs = App.make_cat9554_component(config[CONF_ADDRESS], config['irq']) var = Pvariable(config[CONF_ID], rhs) setup_component(var, config) BUILD_FLAGS = '-DUSE_CAT9554'
from esphome.components import i2c, sensor import esphome.config_validation as cv from esphome.const import CONF_ADDRESS, CONF_ID, CONF_UPDATE_INTERVAL from esphome.cpp_generator import Pvariable, add from esphome.cpp_helpers import setup_component from esphome.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 = cv.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)
from esphome import pins from esphome.components import sensor, spi from esphome.components.spi import SPIComponent import esphome.config_validation as cv from esphome.const import CONF_CS_PIN, CONF_ID, CONF_NAME, CONF_SPI_ID, \ CONF_UPDATE_INTERVAL from esphome.cpp_generator import Pvariable, get_variable from esphome.cpp_helpers import gpio_output_pin_expression, setup_component from esphome.cpp_types import App MAX6675Sensor = sensor.sensor_ns.class_('MAX6675Sensor', sensor.PollingSensorComponent, spi.SPIDevice) PLATFORM_SCHEMA = cv.nameable(sensor.SENSOR_PLATFORM_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(MAX6675Sensor), cv.GenerateID(CONF_SPI_ID): cv.use_variable_id(SPIComponent), vol.Required(CONF_CS_PIN): pins.gpio_output_pin_schema, vol.Optional(CONF_UPDATE_INTERVAL): cv.update_interval, }).extend(cv.COMPONENT_SCHEMA.schema)) def to_code(config): for spi_ in get_variable(config[CONF_SPI_ID]): yield for cs in gpio_output_pin_expression(config[CONF_CS_PIN]): yield rhs = App.make_max6675_sensor(config[CONF_NAME], spi_, cs, config.get(CONF_UPDATE_INTERVAL)) max6675 = Pvariable(config[CONF_ID], rhs) sensor.setup_sensor(max6675, config)
import voluptuous as vol from esphome.components import output import esphome.config_validation as cv from esphome.const import CONF_ID, CONF_LAMBDA, CONF_OUTPUTS, CONF_TYPE from esphome.cpp_generator import process_lambda, variable from esphome.cpp_types import std_vector CustomBinaryOutputConstructor = output.output_ns.class_( 'CustomBinaryOutputConstructor') CustomFloatOutputConstructor = output.output_ns.class_( 'CustomFloatOutputConstructor') BINARY_SCHEMA = output.PLATFORM_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(CustomBinaryOutputConstructor), vol.Required(CONF_LAMBDA): cv.lambda_, vol.Required(CONF_TYPE): 'binary', vol.Required(CONF_OUTPUTS): cv.ensure_list( output.BINARY_OUTPUT_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(output.BinaryOutput), })), }) FLOAT_SCHEMA = output.PLATFORM_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(CustomFloatOutputConstructor),
import voluptuous as vol from esphome.components import output, switch import esphome.config_validation as cv from esphome.const import CONF_ID, CONF_NAME, CONF_OUTPUT from esphome.cpp_generator import Pvariable, get_variable from esphome.cpp_helpers import setup_component from esphome.cpp_types import App, Component OutputSwitch = switch.switch_ns.class_('OutputSwitch', switch.Switch, Component) PLATFORM_SCHEMA = cv.nameable( switch.SWITCH_PLATFORM_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(OutputSwitch), vol.Required(CONF_OUTPUT): cv.use_variable_id(output.BinaryOutput), }).extend(cv.COMPONENT_SCHEMA.schema)) def to_code(config): for output_ in get_variable(config[CONF_OUTPUT]): yield rhs = App.make_output_switch(config[CONF_NAME], output_) switch_ = Pvariable(config[CONF_ID], rhs) switch.setup_switch(switch_, config) setup_component(switch, config)
import voluptuous as vol import esphome.config_validation as cv from esphome.const import CONF_COMPONENTS, CONF_ID, CONF_LAMBDA from esphome.cpp_generator import Pvariable, process_lambda, variable from esphome.cpp_helpers import setup_component from esphome.cpp_types import Component, ComponentPtr, esphome_ns, std_vector CustomComponentConstructor = esphome_ns.class_('CustomComponentConstructor') MULTI_CONF = True CONFIG_SCHEMA = vol.Schema({ cv.GenerateID(): cv.declare_variable_id(CustomComponentConstructor), vol.Required(CONF_LAMBDA): cv.lambda_, vol.Optional(CONF_COMPONENTS): cv.ensure_list( vol.Schema({ cv.GenerateID(): cv.declare_variable_id(Component) }).extend(cv.COMPONENT_SCHEMA.schema)), }) def to_code(config): for template_ in process_lambda( config[CONF_LAMBDA], [], return_type=std_vector.template(ComponentPtr)): yield rhs = CustomComponentConstructor(template_)
AP_MANUAL_IP_SCHEMA = vol.Schema({ vol.Required(CONF_STATIC_IP): cv.ipv4, vol.Required(CONF_GATEWAY): cv.ipv4, vol.Required(CONF_SUBNET): cv.ipv4, }) STA_MANUAL_IP_SCHEMA = AP_MANUAL_IP_SCHEMA.extend({ vol.Optional(CONF_DNS1, default="1.1.1.1"): cv.ipv4, vol.Optional(CONF_DNS2, default="1.0.0.1"): cv.ipv4, }) WIFI_NETWORK_BASE = vol.Schema({ cv.GenerateID(): cv.declare_variable_id(WiFiAP), vol.Optional(CONF_SSID): cv.ssid, vol.Optional(CONF_PASSWORD): validate_password, vol.Optional(CONF_CHANNEL): validate_channel, vol.Optional(CONF_MANUAL_IP): STA_MANUAL_IP_SCHEMA, }) WIFI_NETWORK_AP = WIFI_NETWORK_BASE.extend({}) WIFI_NETWORK_STA = WIFI_NETWORK_BASE.extend({ vol.Optional(CONF_BSSID): cv.mac_address,
import voluptuous as vol from esphome import config_validation as cv from esphome.const import CONF_ID, CONF_INITIAL_VALUE, CONF_RESTORE_VALUE, CONF_TYPE from esphome.cpp_generator import Pvariable, RawExpression, TemplateArguments, add from esphome.cpp_helpers import setup_component from esphome.cpp_types import App, Component, esphome_ns GlobalVariableComponent = esphome_ns.class_('GlobalVariableComponent', Component) MULTI_CONF = True CONFIG_SCHEMA = cv.Schema({ vol.Required(CONF_ID): cv.declare_variable_id(GlobalVariableComponent), vol.Required(CONF_TYPE): cv.string_strict, vol.Optional(CONF_INITIAL_VALUE): cv.string_strict, vol.Optional(CONF_RESTORE_VALUE): cv.boolean, }).extend(cv.COMPONENT_SCHEMA.schema) def to_code(config): type_ = RawExpression(config[CONF_TYPE]) template_args = TemplateArguments(type_) res_type = GlobalVariableComponent.template(template_args) initial_value = None if CONF_INITIAL_VALUE in config: