Пример #1
0
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)

Пример #2
0
def validate_adc_pin(value):
    vcc = str(value).upper()
    if vcc == 'VCC':
        return cv.only_on_esp8266(vcc)
    return pins.analog_pin(value)


ADCSensorComponent = sensor.sensor_ns.class_('ADCSensorComponent',
                                             sensor.PollingSensorComponent)

PLATFORM_SCHEMA = cv.nameable(
    sensor.SENSOR_PLATFORM_SCHEMA.extend({
        cv.GenerateID():
        cv.declare_variable_id(ADCSensorComponent),
        vol.Required(CONF_PIN):
        validate_adc_pin,
        vol.Optional(CONF_ATTENUATION):
        vol.All(cv.only_on_esp32, cv.one_of(*ATTENUATION_MODES, lower=True)),
        vol.Optional(CONF_UPDATE_INTERVAL):
        cv.update_interval,
    }).extend(cv.COMPONENT_SCHEMA.schema))


def to_code(config):
    pin = config[CONF_PIN]
    if pin == 'VCC':
        pin = 0
    rhs = App.make_adc_sensor(config[CONF_NAME], pin,
                              config.get(CONF_UPDATE_INTERVAL))
    adc = Pvariable(config[CONF_ID], rhs)
    if CONF_ATTENUATION in config:
Пример #3
0
from esphome.components import sensor
from esphome.components.apds9960 import APDS9960, CONF_APDS9960_ID
import esphome.config_validation as cv
from esphome.const import CONF_NAME, CONF_TYPE
from esphome.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)
Пример #4
0
    cw = value[CONF_COLD_WHITE_COLOR_TEMPERATURE]
    ww = value[CONF_WARM_WHITE_COLOR_TEMPERATURE]
    if cw > ww:
        raise vol.Invalid("Cold white color temperature cannot be higher than warm white")
    if cw == ww:
        raise vol.Invalid("Cold white color temperature cannot be the same as warm white")
    return value


PLATFORM_SCHEMA = cv.nameable(light.LIGHT_PLATFORM_SCHEMA.extend({
    cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(light.MakeLight),
    vol.Required(CONF_RED): cv.use_variable_id(output.FloatOutput),
    vol.Required(CONF_GREEN): cv.use_variable_id(output.FloatOutput),
    vol.Required(CONF_BLUE): cv.use_variable_id(output.FloatOutput),
    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.RGB_EFFECTS),
}).extend(cv.COMPONENT_SCHEMA.schema), validate_cold_white_colder)


def to_code(config):
    for red in get_variable(config[CONF_RED]):
        yield
    for green in get_variable(config[CONF_GREEN]):
        yield
    for blue in get_variable(config[CONF_BLUE]):
        yield
Пример #5
0
def validate_mux(value):
    value = cv.string(value).upper()
    value = value.replace(' ', '_')
    return cv.one_of(*MUX)(value)


ADS1115Sensor = sensor.sensor_ns.class_('ADS1115Sensor', sensor.EmptySensor)

PLATFORM_SCHEMA = cv.nameable(
    sensor.SENSOR_PLATFORM_SCHEMA.extend({
        cv.GenerateID():
        cv.declare_variable_id(ADS1115Sensor),
        vol.Required(CONF_MULTIPLEXER):
        validate_mux,
        vol.Required(CONF_GAIN):
        validate_gain,
        cv.GenerateID(CONF_ADS1115_ID):
        cv.use_variable_id(ADS1115Component),
        vol.Optional(CONF_UPDATE_INTERVAL):
        cv.update_interval,
    }))


def to_code(config):
    for hub in get_variable(config[CONF_ADS1115_ID]):
        yield

    mux = MUX[config[CONF_MULTIPLEXER]]
    gain = GAIN[config[CONF_GAIN]]
    rhs = hub.get_sensor(config[CONF_NAME], mux, gain,
Пример #6
0
INA219Component = sensor.sensor_ns.class_('INA219Component', PollingComponent, i2c.I2CDevice)
INA219VoltageSensor = sensor.sensor_ns.class_('INA219VoltageSensor',
                                              sensor.EmptyPollingParentSensor)
INA219CurrentSensor = sensor.sensor_ns.class_('INA219CurrentSensor',
                                              sensor.EmptyPollingParentSensor)
INA219PowerSensor = sensor.sensor_ns.class_('INA219PowerSensor', sensor.EmptyPollingParentSensor)

SENSOR_KEYS = [CONF_BUS_VOLTAGE, CONF_SHUNT_VOLTAGE, CONF_CURRENT,
               CONF_POWER]

PLATFORM_SCHEMA = vol.All(sensor.PLATFORM_SCHEMA.extend({
    cv.GenerateID(): cv.declare_variable_id(INA219Component),
    vol.Optional(CONF_ADDRESS, default=0x40): cv.i2c_address,
    vol.Optional(CONF_BUS_VOLTAGE): cv.nameable(sensor.SENSOR_SCHEMA.extend({
        cv.GenerateID(): cv.declare_variable_id(INA219VoltageSensor),
    })),
    vol.Optional(CONF_SHUNT_VOLTAGE): cv.nameable(sensor.SENSOR_SCHEMA.extend({
        cv.GenerateID(): cv.declare_variable_id(INA219VoltageSensor),
    })),
    vol.Optional(CONF_CURRENT): cv.nameable(sensor.SENSOR_SCHEMA.extend({
        cv.GenerateID(): cv.declare_variable_id(INA219CurrentSensor),
    })),
    vol.Optional(CONF_POWER): cv.nameable(sensor.SENSOR_SCHEMA.extend({
        cv.GenerateID(): cv.declare_variable_id(INA219PowerSensor),
    })),
    vol.Optional(CONF_SHUNT_RESISTANCE, default=0.1): vol.All(cv.resistance,
                                                              vol.Range(min=0.0, max=32.0)),
    vol.Optional(CONF_MAX_VOLTAGE, default=32.0): vol.All(cv.voltage, vol.Range(min=0.0, max=32.0)),
    vol.Optional(CONF_MAX_CURRENT, default=3.2): vol.All(cv.current, vol.Range(min=0.0)),
    vol.Optional(CONF_UPDATE_INTERVAL): cv.update_interval,
Пример #7
0
import voluptuous as vol

from esphome.components import fan, output
import esphome.config_validation as cv
from esphome.const import CONF_MAKE_ID, CONF_NAME, CONF_OSCILLATION_OUTPUT, CONF_OUTPUT
from esphome.cpp_generator import add, get_variable, variable
from esphome.cpp_helpers import setup_component
from esphome.cpp_types import App

PLATFORM_SCHEMA = cv.nameable(
    fan.FAN_PLATFORM_SCHEMA.extend({
        cv.GenerateID(CONF_MAKE_ID):
        cv.declare_variable_id(fan.MakeFan),
        vol.Required(CONF_OUTPUT):
        cv.use_variable_id(output.BinaryOutput),
        vol.Optional(CONF_OSCILLATION_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_fan(config[CONF_NAME])
    fan_struct = variable(config[CONF_MAKE_ID], rhs)
    add(fan_struct.Poutput.set_binary(output_))
    if CONF_OSCILLATION_OUTPUT in config:
        for oscillation_output in get_variable(
                config[CONF_OSCILLATION_OUTPUT]):
            yield
Пример #8
0
from esphome.components import binary_sensor
import esphome.config_validation as cv
from esphome.const import CONF_ID, CONF_NAME
from esphome.cpp_generator import Pvariable
from esphome.cpp_helpers import setup_component
from esphome.cpp_types import App, Component

StatusBinarySensor = binary_sensor.binary_sensor_ns.class_(
    'StatusBinarySensor', binary_sensor.BinarySensor, Component)

PLATFORM_SCHEMA = cv.nameable(
    binary_sensor.BINARY_SENSOR_PLATFORM_SCHEMA.extend({
        cv.GenerateID():
        cv.declare_variable_id(StatusBinarySensor),
    }).extend(cv.COMPONENT_SCHEMA.schema))


def to_code(config):
    rhs = App.make_status_binary_sensor(config[CONF_NAME])
    status = Pvariable(config[CONF_ID], rhs)
    binary_sensor.setup_binary_sensor(status, config)
    setup_component(status, config)


BUILD_FLAGS = '-DUSE_STATUS_BINARY_SENSOR'


def to_hass_config(data, config):
    return binary_sensor.core_to_hass_config(data, config)
Пример #9
0
from esphome.const import CONF_COMPONENT_ID, CONF_NAME, CONF_PAGE_ID
from esphome.cpp_generator import get_variable

DEPENDENCIES = ['display']

CONF_NEXTION_ID = 'nextion_id'

NextionTouchComponent = display.display_ns.class_('NextionTouchComponent',
                                                  binary_sensor.BinarySensor)

PLATFORM_SCHEMA = cv.nameable(
    binary_sensor.BINARY_SENSOR_PLATFORM_SCHEMA.extend({
        cv.GenerateID():
        cv.declare_variable_id(NextionTouchComponent),
        vol.Required(CONF_PAGE_ID):
        cv.uint8_t,
        vol.Required(CONF_COMPONENT_ID):
        cv.uint8_t,
        cv.GenerateID(CONF_NEXTION_ID):
        cv.use_variable_id(Nextion)
    }))


def to_code(config):
    for hub in get_variable(config[CONF_NEXTION_ID]):
        yield
    rhs = hub.make_touch_component(config[CONF_NAME], config[CONF_PAGE_ID],
                                   config[CONF_COMPONENT_ID])
    binary_sensor.register_binary_sensor(rhs, config)

Пример #10
0
def validate_touch_pad(value):
    value = validate_gpio_pin(value)
    if value not in TOUCH_PADS:
        raise vol.Invalid("Pin {} does not support touch pads.".format(value))
    return value


ESP32TouchBinarySensor = binary_sensor.binary_sensor_ns.class_(
    'ESP32TouchBinarySensor', binary_sensor.BinarySensor)

PLATFORM_SCHEMA = cv.nameable(
    binary_sensor.BINARY_SENSOR_PLATFORM_SCHEMA.extend({
        cv.GenerateID():
        cv.declare_variable_id(ESP32TouchBinarySensor),
        vol.Required(CONF_PIN):
        validate_touch_pad,
        vol.Required(CONF_THRESHOLD):
        cv.uint16_t,
        cv.GenerateID(CONF_ESP32_TOUCH_ID):
        cv.use_variable_id(ESP32TouchComponent),
    }))


def to_code(config):
    hub = None
    for hub in get_variable(config[CONF_ESP32_TOUCH_ID]):
        yield
    touch_pad = TOUCH_PADS[config[CONF_PIN]]
    rhs = hub.make_touch_pad(config[CONF_NAME], touch_pad,
                             config[CONF_THRESHOLD])
    binary_sensor.register_binary_sensor(rhs, config)
Пример #11
0
import voluptuous as vol

from esphome.components import switch
import esphome.config_validation as cv
from esphome.const import CONF_ID, CONF_INVERTED, CONF_NAME
from esphome.cpp_generator import Pvariable
from esphome.cpp_types import App

RestartSwitch = switch.switch_ns.class_('RestartSwitch', switch.Switch)

PLATFORM_SCHEMA = cv.nameable(switch.SWITCH_PLATFORM_SCHEMA.extend({
    cv.GenerateID(): cv.declare_variable_id(RestartSwitch),
    vol.Optional(CONF_INVERTED): cv.invalid("Restart switches do not support inverted mode!"),
}))


def to_code(config):
    rhs = App.make_restart_switch(config[CONF_NAME])
    restart = Pvariable(config[CONF_ID], rhs)
    switch.setup_switch(restart, config)


BUILD_FLAGS = '-DUSE_RESTART_SWITCH'
Пример #12
0
from esphome.components import sensor
import esphome.config_validation as cv
from esphome.const import CONF_ECHO_PIN, CONF_ID, CONF_NAME, CONF_TIMEOUT_METER, \
    CONF_TIMEOUT_TIME, CONF_TRIGGER_PIN, CONF_UPDATE_INTERVAL
from esphome.cpp_generator import Pvariable, add
from esphome.cpp_helpers import gpio_input_pin_expression, gpio_output_pin_expression, \
    setup_component
from esphome.cpp_types import App

UltrasonicSensorComponent = sensor.sensor_ns.class_('UltrasonicSensorComponent',
                                                    sensor.PollingSensorComponent)

PLATFORM_SCHEMA = cv.nameable(sensor.SENSOR_PLATFORM_SCHEMA.extend({
    cv.GenerateID(): cv.declare_variable_id(UltrasonicSensorComponent),
    vol.Required(CONF_TRIGGER_PIN): pins.gpio_output_pin_schema,
    vol.Required(CONF_ECHO_PIN): pins.internal_gpio_input_pin_schema,
    vol.Exclusive(CONF_TIMEOUT_METER, 'timeout'): cv.positive_float,
    vol.Exclusive(CONF_TIMEOUT_TIME, 'timeout'): cv.positive_time_period_microseconds,
    vol.Optional(CONF_UPDATE_INTERVAL): cv.update_interval,
}))


def to_code(config):
    for trigger in gpio_output_pin_expression(config[CONF_TRIGGER_PIN]):
        yield
    for echo in gpio_input_pin_expression(config[CONF_ECHO_PIN]):
        yield
    rhs = App.make_ultrasonic_sensor(config[CONF_NAME], trigger, echo,
                                     config.get(CONF_UPDATE_INTERVAL))
    ultrasonic = Pvariable(config[CONF_ID], rhs)

    if CONF_TIMEOUT_TIME in config:
Пример #13
0
                                             sensor.EmptyPollingParentSensor)

PLATFORM_SCHEMA = vol.All(
    sensor.PLATFORM_SCHEMA.extend({
        cv.GenerateID():
        cv.declare_variable_id(HLW8012Component),
        vol.Required(CONF_SEL_PIN):
        pins.gpio_output_pin_schema,
        vol.Required(CONF_CF_PIN):
        pins.input_pin,
        vol.Required(CONF_CF1_PIN):
        pins.input_pin,
        vol.Optional(CONF_VOLTAGE):
        cv.nameable(
            sensor.SENSOR_SCHEMA.extend({
                cv.GenerateID():
                cv.declare_variable_id(HLW8012VoltageSensor),
            })),
        vol.Optional(CONF_CURRENT):
        cv.nameable(
            sensor.SENSOR_SCHEMA.extend({
                cv.GenerateID():
                cv.declare_variable_id(HLW8012CurrentSensor),
            })),
        vol.Optional(CONF_POWER):
        cv.nameable(
            sensor.SENSOR_SCHEMA.extend({
                cv.GenerateID():
                cv.declare_variable_id(HLW8012PowerSensor),
            })),
        vol.Optional(CONF_CURRENT_RESISTOR):
Пример #14
0
from esphome.cpp_helpers import setup_component
from esphome.cpp_types import App, Application, PollingComponent

DEPENDENCIES = ['i2c']

MakeHTU21DSensor = Application.struct('MakeHTU21DSensor')
HTU21DComponent = sensor.sensor_ns.class_('HTU21DComponent', PollingComponent, i2c.I2CDevice)
HTU21DTemperatureSensor = sensor.sensor_ns.class_('HTU21DTemperatureSensor',
                                                  sensor.EmptyPollingParentSensor)
HTU21DHumiditySensor = sensor.sensor_ns.class_('HTU21DHumiditySensor',
                                               sensor.EmptyPollingParentSensor)

PLATFORM_SCHEMA = sensor.PLATFORM_SCHEMA.extend({
    cv.GenerateID(): cv.declare_variable_id(HTU21DComponent),
    vol.Required(CONF_TEMPERATURE): cv.nameable(sensor.SENSOR_SCHEMA.extend({
        cv.GenerateID(): cv.declare_variable_id(HTU21DTemperatureSensor),
    })),
    vol.Required(CONF_HUMIDITY): cv.nameable(sensor.SENSOR_SCHEMA.extend({
        cv.GenerateID(): cv.declare_variable_id(HTU21DHumiditySensor),
    })),
    vol.Optional(CONF_UPDATE_INTERVAL): cv.update_interval,
}).extend(cv.COMPONENT_SCHEMA.schema)


def to_code(config):
    rhs = App.make_htu21d_sensor(config[CONF_TEMPERATURE][CONF_NAME],
                                 config[CONF_HUMIDITY][CONF_NAME],
                                 config.get(CONF_UPDATE_INTERVAL))
    htu21d = Pvariable(config[CONF_ID], rhs)

    sensor.setup_sensor(htu21d.Pget_temperature_sensor(), config[CONF_TEMPERATURE])
Пример #15
0
from esphome.cpp_helpers import setup_component
from esphome.cpp_types import Action, App, optional
from esphome.py_compat import string_types

TemplateCover = cover.cover_ns.class_('TemplateCover', cover.Cover)
CoverPublishAction = cover.cover_ns.class_('CoverPublishAction', Action)

PLATFORM_SCHEMA = cv.nameable(
    cover.COVER_PLATFORM_SCHEMA.extend({
        cv.GenerateID():
        cv.declare_variable_id(TemplateCover),
        vol.Optional(CONF_LAMBDA):
        cv.lambda_,
        vol.Optional(CONF_OPTIMISTIC):
        cv.boolean,
        vol.Optional(CONF_ASSUMED_STATE):
        cv.boolean,
        vol.Optional(CONF_OPEN_ACTION):
        automation.validate_automation(single=True),
        vol.Optional(CONF_CLOSE_ACTION):
        automation.validate_automation(single=True),
        vol.Optional(CONF_STOP_ACTION):
        automation.validate_automation(single=True),
    }).extend(cv.COMPONENT_SCHEMA.schema))


def to_code(config):
    rhs = App.make_template_cover(config[CONF_NAME])
    var = Pvariable(config[CONF_ID], rhs)

    cover.setup_cover(var, config)
Пример #16
0
BME280TemperatureSensor = sensor.sensor_ns.class_(
    'BME280TemperatureSensor', sensor.EmptyPollingParentSensor)
BME280PressureSensor = sensor.sensor_ns.class_('BME280PressureSensor',
                                               sensor.EmptyPollingParentSensor)
BME280HumiditySensor = sensor.sensor_ns.class_('BME280HumiditySensor',
                                               sensor.EmptyPollingParentSensor)

PLATFORM_SCHEMA = sensor.PLATFORM_SCHEMA.extend({
    cv.GenerateID():
    cv.declare_variable_id(BME280Component),
    vol.Optional(CONF_ADDRESS, default=0x77):
    cv.i2c_address,
    vol.Required(CONF_TEMPERATURE):
    cv.nameable(
        BME280_OVERSAMPLING_SENSOR_SCHEMA.extend({
            cv.GenerateID():
            cv.declare_variable_id(BME280TemperatureSensor),
        })),
    vol.Required(CONF_PRESSURE):
    cv.nameable(
        BME280_OVERSAMPLING_SENSOR_SCHEMA.extend({
            cv.GenerateID():
            cv.declare_variable_id(BME280PressureSensor),
        })),
    vol.Required(CONF_HUMIDITY):
    cv.nameable(
        BME280_OVERSAMPLING_SENSOR_SCHEMA.extend({
            cv.GenerateID():
            cv.declare_variable_id(BME280HumiditySensor),
        })),
    vol.Optional(CONF_IIR_FILTER):
Пример #17
0
    value = pins.internal_gpio_input_pin_schema(value)
    if CORE.is_esp8266 and value[CONF_NUMBER] >= 16:
        raise vol.Invalid(
            "Pins GPIO16 and GPIO17 cannot be used as pulse counters on ESP8266."
        )
    return value


PLATFORM_SCHEMA = cv.nameable(
    sensor.SENSOR_PLATFORM_SCHEMA.extend({
        cv.GenerateID():
        cv.declare_variable_id(PulseCounterSensorComponent),
        vol.Required(CONF_PIN):
        validate_pulse_counter_pin,
        vol.Optional(CONF_COUNT_MODE):
        cv.Schema({
            vol.Required(CONF_RISING_EDGE): COUNT_MODE_SCHEMA,
            vol.Required(CONF_FALLING_EDGE): COUNT_MODE_SCHEMA,
        }),
        vol.Optional(CONF_INTERNAL_FILTER):
        validate_internal_filter,
        vol.Optional(CONF_UPDATE_INTERVAL):
        cv.update_interval,
    }).extend(cv.COMPONENT_SCHEMA.schema))


def to_code(config):
    for pin in gpio_input_pin_expression(config[CONF_PIN]):
        yield
    rhs = App.make_pulse_counter_sensor(config[CONF_NAME], pin,
                                        config.get(CONF_UPDATE_INTERVAL))
    pcnt = Pvariable(config[CONF_ID], rhs)
Пример #18
0
DEPENDENCIES = ['i2c']

HDC1080Component = sensor.sensor_ns.class_('HDC1080Component',
                                           PollingComponent, i2c.I2CDevice)
HDC1080TemperatureSensor = sensor.sensor_ns.class_(
    'HDC1080TemperatureSensor', sensor.EmptyPollingParentSensor)
HDC1080HumiditySensor = sensor.sensor_ns.class_(
    'HDC1080HumiditySensor', sensor.EmptyPollingParentSensor)

PLATFORM_SCHEMA = sensor.PLATFORM_SCHEMA.extend({
    cv.GenerateID():
    cv.declare_variable_id(HDC1080Component),
    vol.Required(CONF_TEMPERATURE):
    cv.nameable(
        sensor.SENSOR_SCHEMA.extend({
            cv.GenerateID():
            cv.declare_variable_id(HDC1080TemperatureSensor),
        })),
    vol.Required(CONF_HUMIDITY):
    cv.nameable(
        sensor.SENSOR_SCHEMA.extend({
            cv.GenerateID():
            cv.declare_variable_id(HDC1080HumiditySensor),
        })),
    vol.Optional(CONF_UPDATE_INTERVAL):
    cv.update_interval,
}).extend(cv.COMPONENT_SCHEMA.schema)


def to_code(config):
    rhs = App.make_hdc1080_sensor(config[CONF_TEMPERATURE][CONF_NAME],
Пример #19
0
MakeFastLEDLight = Application.struct('MakeFastLEDLight')

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(MakeFastLEDLight),
        vol.Required(CONF_CHIPSET):
        cv.one_of(*TYPES, upper=True),
        vol.Required(CONF_PIN):
        pins.output_pin,
        vol.Required(CONF_NUM_LEDS):
        cv.positive_not_null_int,
        vol.Optional(CONF_MAX_REFRESH_RATE):
        cv.positive_time_period_microseconds,
        vol.Optional(CONF_RGB_ORDER):
        cv.one_of(*RGB_ORDERS, upper=True),
        vol.Optional(CONF_GAMMA_CORRECT):
        cv.positive_float,
        vol.Optional(CONF_COLOR_CORRECT):
        vol.All([cv.percentage], vol.Length(min=3, max=3)),
        vol.Optional(CONF_DEFAULT_TRANSITION_LENGTH):
        cv.positive_time_period_milliseconds,
        vol.Optional(CONF_POWER_SUPPLY):
        cv.use_variable_id(PowerSupplyComponent),
        vol.Optional(CONF_EFFECTS):
        light.validate_effects(light.ADDRESSABLE_EFFECTS),
    }).extend(cv.COMPONENT_SCHEMA.schema), validate)

Пример #20
0
SENSOR_KEYS = [
    CONF_ACCEL_X, CONF_ACCEL_Y, CONF_ACCEL_Z, CONF_GYRO_X, CONF_GYRO_Y,
    CONF_GYRO_Z
]

PLATFORM_SCHEMA = vol.All(
    sensor.PLATFORM_SCHEMA.extend({
        cv.GenerateID():
        cv.declare_variable_id(MPU6050Component),
        vol.Optional(CONF_ADDRESS, default=0x68):
        cv.i2c_address,
        vol.Optional(CONF_ACCEL_X):
        cv.nameable(
            sensor.SENSOR_SCHEMA.extend({
                cv.GenerateID():
                cv.declare_variable_id(MPU6050AccelSensor),
            })),
        vol.Optional(CONF_ACCEL_Y):
        cv.nameable(
            sensor.SENSOR_SCHEMA.extend({
                cv.GenerateID():
                cv.declare_variable_id(MPU6050AccelSensor),
            })),
        vol.Optional(CONF_ACCEL_Z):
        cv.nameable(
            sensor.SENSOR_SCHEMA.extend({
                cv.GenerateID():
                cv.declare_variable_id(MPU6050AccelSensor),
            })),
        vol.Optional(CONF_GYRO_X):
Пример #21
0
UARTSwitch = switch.switch_ns.class_('UARTSwitch', switch.Switch, uart.UARTDevice)


def validate_data(value):
    if isinstance(value, text_type):
        return value.encode('utf-8')
    if isinstance(value, str):
        return value
    if isinstance(value, list):
        return cv.Schema([cv.hex_uint8_t])(value)
    raise vol.Invalid("data must either be a string wrapped in quotes or a list of bytes")


PLATFORM_SCHEMA = cv.nameable(switch.SWITCH_PLATFORM_SCHEMA.extend({
    cv.GenerateID(): cv.declare_variable_id(UARTSwitch),
    cv.GenerateID(CONF_UART_ID): cv.use_variable_id(UARTComponent),
    vol.Required(CONF_DATA): validate_data,
    vol.Optional(CONF_INVERTED): cv.invalid("UART switches do not support inverted mode!"),
}))


def to_code(config):
    for uart_ in get_variable(config[CONF_UART_ID]):
        yield
    data = config[CONF_DATA]
    if isinstance(data, str):
        data = [HexInt(ord(x)) for x in data]
    rhs = App.make_uart_switch(uart_, config[CONF_NAME], data)
    var = Pvariable(config[CONF_ID], rhs)
    switch.setup_switch(var, config)

Пример #22
0
CONF_DOUT_PIN = 'dout_pin'

HX711Gain = sensor.sensor_ns.enum('HX711Gain')
GAINS = {
    128: HX711Gain.HX711_GAIN_128,
    32: HX711Gain.HX711_GAIN_32,
    64: HX711Gain.HX711_GAIN_64,
}

PLATFORM_SCHEMA = cv.nameable(
    sensor.SENSOR_PLATFORM_SCHEMA.extend({
        cv.GenerateID():
        cv.declare_variable_id(HX711Sensor),
        vol.Required(CONF_DOUT_PIN):
        pins.gpio_input_pin_schema,
        vol.Required(CONF_CLK_PIN):
        pins.gpio_output_pin_schema,
        vol.Optional(CONF_GAIN):
        cv.one_of(*GAINS, int=True),
        vol.Optional(CONF_UPDATE_INTERVAL):
        cv.update_interval,
    }).extend(cv.COMPONENT_SCHEMA.schema))


def to_code(config):
    for dout_pin in gpio_input_pin_expression(config[CONF_DOUT_PIN]):
        yield
    for sck_pin in gpio_input_pin_expression(config[CONF_CLK_PIN]):
        yield

    rhs = App.make_hx711_sensor(config[CONF_NAME], dout_pin, sck_pin,
Пример #23
0
import voluptuous as vol

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)

    if CONF_LAMBDA in config:
        for template_ in process_lambda(config[CONF_LAMBDA], [],
                                        return_type=optional.template(float_)):
            yield
Пример #24
0
from esphome.const import CONF_HIGH, CONF_LOW, CONF_MAKE_ID, CONF_MEDIUM, CONF_NAME, \
    CONF_OSCILLATION_OUTPUT, CONF_OUTPUT, CONF_SPEED, CONF_SPEED_COMMAND_TOPIC, \
    CONF_SPEED_STATE_TOPIC
from esphome.cpp_generator import add, get_variable, variable
from esphome.cpp_types import App

PLATFORM_SCHEMA = cv.nameable(
    fan.FAN_PLATFORM_SCHEMA.extend({
        cv.GenerateID(CONF_MAKE_ID):
        cv.declare_variable_id(fan.MakeFan),
        vol.Required(CONF_OUTPUT):
        cv.use_variable_id(output.FloatOutput),
        vol.Optional(CONF_SPEED_STATE_TOPIC):
        cv.publish_topic,
        vol.Optional(CONF_SPEED_COMMAND_TOPIC):
        cv.subscribe_topic,
        vol.Optional(CONF_OSCILLATION_OUTPUT):
        cv.use_variable_id(output.BinaryOutput),
        vol.Optional(CONF_SPEED):
        cv.Schema({
            vol.Required(CONF_LOW): cv.percentage,
            vol.Required(CONF_MEDIUM): cv.percentage,
            vol.Required(CONF_HIGH): cv.percentage,
        }),
    }).extend(cv.COMPONENT_SCHEMA.schema))


def to_code(config):
    for output_ in get_variable(config[CONF_OUTPUT]):
        yield
    rhs = App.make_fan(config[CONF_NAME])
Пример #25
0
IPAddressWiFiInfo = text_sensor.text_sensor_ns.class_('IPAddressWiFiInfo',
                                                      text_sensor.TextSensor,
                                                      Component)
SSIDWiFiInfo = text_sensor.text_sensor_ns.class_('SSIDWiFiInfo',
                                                 text_sensor.TextSensor,
                                                 Component)
BSSIDWiFiInfo = text_sensor.text_sensor_ns.class_('BSSIDWiFiInfo',
                                                  text_sensor.TextSensor,
                                                  Component)

PLATFORM_SCHEMA = text_sensor.PLATFORM_SCHEMA.extend({
    vol.Optional(CONF_IP_ADDRESS):
    cv.nameable(
        text_sensor.TEXT_SENSOR_SCHEMA.extend({
            cv.GenerateID():
            cv.declare_variable_id(IPAddressWiFiInfo),
        })),
    vol.Optional(CONF_SSID):
    cv.nameable(
        text_sensor.TEXT_SENSOR_SCHEMA.extend({
            cv.GenerateID():
            cv.declare_variable_id(SSIDWiFiInfo),
        })),
    vol.Optional(CONF_BSSID):
    cv.nameable(
        text_sensor.TEXT_SENSOR_SCHEMA.extend({
            cv.GenerateID():
            cv.declare_variable_id(BSSIDWiFiInfo),
        })),
})
Пример #26
0
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']

MQTTSubscribeTextSensor = text_sensor.text_sensor_ns.class_(
    'MQTTSubscribeTextSensor', text_sensor.TextSensor, Component)

PLATFORM_SCHEMA = cv.nameable(
    text_sensor.TEXT_SENSOR_PLATFORM_SCHEMA.extend({
        cv.GenerateID():
        cv.declare_variable_id(MQTTSubscribeTextSensor),
        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_text_sensor(config[CONF_NAME],
                                              config[CONF_TOPIC])
    sensor_ = Pvariable(config[CONF_ID], rhs)

    if CONF_QOS in config:
        add(sensor_.set_qos(config[CONF_QOS]))

    text_sensor.setup_text_sensor(sensor_, config)
Пример #27
0
from esphome import pins
from esphome.components import binary_sensor
import esphome.config_validation as cv
from esphome.const import CONF_ID, CONF_NAME, CONF_PIN
from esphome.cpp_generator import Pvariable
from esphome.cpp_helpers import gpio_input_pin_expression, setup_component
from esphome.cpp_types import App, Component

GPIOBinarySensorComponent = binary_sensor.binary_sensor_ns.class_(
    'GPIOBinarySensorComponent', binary_sensor.BinarySensor, Component)

PLATFORM_SCHEMA = cv.nameable(
    binary_sensor.BINARY_SENSOR_PLATFORM_SCHEMA.extend({
        cv.GenerateID():
        cv.declare_variable_id(GPIOBinarySensorComponent),
        vol.Required(CONF_PIN):
        pins.gpio_input_pin_schema
    }).extend(cv.COMPONENT_SCHEMA.schema))


def to_code(config):
    pin = None
    for pin in gpio_input_pin_expression(config[CONF_PIN]):
        yield
    rhs = App.make_gpio_binary_sensor(config[CONF_NAME], pin)
    gpio = Pvariable(config[CONF_ID], rhs)
    binary_sensor.setup_binary_sensor(gpio, config)
    setup_component(gpio, config)

Пример #28
0
DEPENDENCIES = ['i2c']

BMP085Component = sensor.sensor_ns.class_('BMP085Component', PollingComponent,
                                          i2c.I2CDevice)
BMP085TemperatureSensor = sensor.sensor_ns.class_(
    'BMP085TemperatureSensor', sensor.EmptyPollingParentSensor)
BMP085PressureSensor = sensor.sensor_ns.class_('BMP085PressureSensor',
                                               sensor.EmptyPollingParentSensor)

PLATFORM_SCHEMA = sensor.PLATFORM_SCHEMA.extend({
    cv.GenerateID():
    cv.declare_variable_id(BMP085Component),
    vol.Required(CONF_TEMPERATURE):
    cv.nameable(
        sensor.SENSOR_SCHEMA.extend({
            cv.GenerateID():
            cv.declare_variable_id(BMP085TemperatureSensor),
        })),
    vol.Required(CONF_PRESSURE):
    cv.nameable(
        sensor.SENSOR_SCHEMA.extend({
            cv.GenerateID():
            cv.declare_variable_id(BMP085PressureSensor),
        })),
    vol.Optional(CONF_ADDRESS):
    cv.i2c_address,
    vol.Optional(CONF_UPDATE_INTERVAL):
    cv.update_interval,
}).extend(cv.COMPONENT_SCHEMA.schema)

Пример #29
0
import voluptuous as vol

from esphome.components import binary_sensor, rdm6300
import esphome.config_validation as cv
from esphome.const import CONF_NAME, CONF_UID
from esphome.cpp_generator import get_variable

DEPENDENCIES = ['rdm6300']

CONF_RDM6300_ID = 'rdm6300_id'

RDM6300BinarySensor = binary_sensor.binary_sensor_ns.class_('RDM6300BinarySensor',
                                                            binary_sensor.BinarySensor)

PLATFORM_SCHEMA = cv.nameable(binary_sensor.BINARY_SENSOR_PLATFORM_SCHEMA.extend({
    cv.GenerateID(): cv.declare_variable_id(RDM6300BinarySensor),
    vol.Required(CONF_UID): cv.uint32_t,
    cv.GenerateID(CONF_RDM6300_ID): cv.use_variable_id(rdm6300.RDM6300Component)
}))


def to_code(config):
    for hub in get_variable(config[CONF_RDM6300_ID]):
        yield
    rhs = hub.make_card(config[CONF_NAME], config[CONF_UID])
    binary_sensor.register_binary_sensor(rhs, config)
Пример #30
0
from esphome.components import binary_sensor
import esphome.config_validation as cv
from esphome.const import CONF_ID, CONF_LAMBDA, CONF_NAME, CONF_STATE
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

TemplateBinarySensor = binary_sensor.binary_sensor_ns.class_(
    'TemplateBinarySensor', binary_sensor.BinarySensor, Component)
BinarySensorPublishAction = binary_sensor.binary_sensor_ns.class_(
    'BinarySensorPublishAction', Action)

PLATFORM_SCHEMA = cv.nameable(
    binary_sensor.BINARY_SENSOR_PLATFORM_SCHEMA.extend({
        cv.GenerateID():
        cv.declare_variable_id(TemplateBinarySensor),
        vol.Optional(CONF_LAMBDA):
        cv.lambda_,
    }).extend(cv.COMPONENT_SCHEMA.schema))


def to_code(config):
    rhs = App.make_template_binary_sensor(config[CONF_NAME])
    var = Pvariable(config[CONF_ID], rhs)
    binary_sensor.setup_binary_sensor(var, config)
    setup_component(var, config)

    if CONF_LAMBDA in config:
        for template_ in process_lambda(config[CONF_LAMBDA], [],
                                        return_type=optional.template(bool_)):
            yield