Esempio n. 1
0
import esphome.const as ehc
from esphome.core import coroutine_with_priority

from . import const as c
from . import cpp_types as t
from .aes_key import create_aes_key
from .md5sum import get_md5sum_hexint
from .peer import peer_to_code, PEER_SCHEMA
from .receive_trigger import validate_receive_trigger, receive_trigger_to_code

COMPONENT_SCHEMA = cv.All(
    cv.COMPONENT_SCHEMA.extend({
        cv.GenerateID():
        cv.declare_id(t.Component),
        cv.Optional(ehc.CONF_CHANNEL):
        cv.All(cv.int_, cv.Range(min=1, max=14)),
        cv.Optional(ehc.CONF_PASSWORD):
        cv.All(cv.string, cv.Length(min=2)),
        cv.Optional(c.CONF_AESKEY):
        create_aes_key,
        cv.Required(c.CONF_PEERS):
        cv.ensure_list(PEER_SCHEMA),
        cv.Optional(c.CONF_ON_RECEIVE):
        validate_receive_trigger,
    }), cv.has_at_most_one_key(ehc.CONF_PASSWORD, c.CONF_AESKEY))


@coroutine_with_priority(1.0)
def wifi_now_component_to_code(config):
    var = cg.new_Pvariable(config[ehc.CONF_ID])
    if ehc.CONF_CHANNEL in config:
Esempio n. 2
0
        cg.add(var.set_code_template(template_))
    else:
        code_ = config[CONF_CODE]
        arr = cg.progmem_array(config[CONF_CODE_STORAGE_ID], code_)
        cg.add(var.set_code_static(arr, len(code_)))
    templ = await cg.templatable(config[CONF_CARRIER_FREQUENCY], args,
                                 cg.uint32)
    cg.add(var.set_carrier_frequency(templ))


# RC5
RC5Data, RC5BinarySensor, RC5Trigger, RC5Action, RC5Dumper = declare_protocol(
    "RC5")
RC5_SCHEMA = cv.Schema({
    cv.Required(CONF_ADDRESS):
    cv.All(cv.hex_int, cv.Range(min=0, max=0x1F)),
    cv.Required(CONF_COMMAND):
    cv.All(cv.hex_int, cv.Range(min=0, max=0x7F)),
})


@register_binary_sensor("rc5", RC5BinarySensor, RC5_SCHEMA)
def rc5_binary_sensor(var, config):
    cg.add(
        var.set_data(
            cg.StructInitializer(
                RC5Data,
                ("address", config[CONF_ADDRESS]),
                ("command", config[CONF_COMMAND]),
            )))
Esempio n. 3
0
    "Color Wipe",
    {
        cv.Optional(CONF_COLORS,
                    default=[{
                        CONF_NUM_LEDS: 1,
                        CONF_RANDOM: True
                    }]):
        cv.ensure_list(
            {
                cv.Optional(CONF_RED, default=1.0): cv.percentage,
                cv.Optional(CONF_GREEN, default=1.0): cv.percentage,
                cv.Optional(CONF_BLUE, default=1.0): cv.percentage,
                cv.Optional(CONF_WHITE, default=1.0): cv.percentage,
                cv.Optional(CONF_RANDOM, default=False): cv.boolean,
                cv.Required(CONF_NUM_LEDS): cv.All(cv.uint32_t,
                                                   cv.Range(min=1)),
            }),
        cv.Optional(CONF_ADD_LED_INTERVAL, default="0.1s"):
        cv.positive_time_period_milliseconds,
        cv.Optional(CONF_REVERSE, default=False):
        cv.boolean,
    },
)
def addressable_color_wipe_effect_to_code(config, effect_id):
    var = cg.new_Pvariable(effect_id, config[CONF_NAME])
    cg.add(var.set_add_led_interval(config[CONF_ADD_LED_INTERVAL]))
    cg.add(var.set_reverse(config[CONF_REVERSE]))
    colors = []
    for color in config.get(CONF_COLORS, []):
        colors.append(
            cg.StructInitializer(
Esempio n. 4
0
remote_receiver_ns = cg.esphome_ns.namespace("remote_receiver")
RemoteReceiverComponent = remote_receiver_ns.class_(
    "RemoteReceiverComponent", remote_base.RemoteReceiverBase, cg.Component
)

MULTI_CONF = True
CONFIG_SCHEMA = remote_base.validate_triggers(
    cv.Schema(
        {
            cv.GenerateID(): cv.declare_id(RemoteReceiverComponent),
            cv.Required(CONF_PIN): cv.All(
                pins.internal_gpio_input_pin_schema, pins.validate_has_interrupt
            ),
            cv.Optional(CONF_DUMP, default=[]): remote_base.validate_dumpers,
            cv.Optional(CONF_TOLERANCE, default=25): cv.All(
                cv.percentage_int, cv.Range(min=0)
            ),
            cv.SplitDefault(
                CONF_BUFFER_SIZE, esp32="10000b", esp8266="1000b"
            ): cv.validate_bytes,
            cv.Optional(
                CONF_FILTER, default="50us"
            ): cv.positive_time_period_microseconds,
            cv.Optional(
                CONF_IDLE, default="10ms"
            ): cv.positive_time_period_microseconds,
            cv.Optional(CONF_MEMORY_BLOCKS, default=3): cv.Range(min=1, max=8),
        }
    ).extend(cv.COMPONENT_SCHEMA)
)
Esempio n. 5
0
INA219Component = ina219_ns.class_("INA219Component", cg.PollingComponent,
                                   i2c.I2CDevice)

CONFIG_SCHEMA = (cv.Schema({
    cv.GenerateID():
    cv.declare_id(INA219Component),
    cv.Optional(CONF_BUS_VOLTAGE):
    sensor.sensor_schema(UNIT_VOLT, ICON_EMPTY, 2, DEVICE_CLASS_VOLTAGE),
    cv.Optional(CONF_SHUNT_VOLTAGE):
    sensor.sensor_schema(UNIT_VOLT, ICON_EMPTY, 2, DEVICE_CLASS_VOLTAGE),
    cv.Optional(CONF_CURRENT):
    sensor.sensor_schema(UNIT_AMPERE, ICON_EMPTY, 3, DEVICE_CLASS_CURRENT),
    cv.Optional(CONF_POWER):
    sensor.sensor_schema(UNIT_WATT, ICON_EMPTY, 2, DEVICE_CLASS_POWER),
    cv.Optional(CONF_SHUNT_RESISTANCE, default=0.1):
    cv.All(cv.resistance, cv.Range(min=0.0, max=32.0)),
    cv.Optional(CONF_MAX_VOLTAGE, default=32.0):
    cv.All(cv.voltage, cv.Range(min=0.0, max=32.0)),
    cv.Optional(CONF_MAX_CURRENT, default=3.2):
    cv.All(cv.current, cv.Range(min=0.0)),
}).extend(cv.polling_component_schema("60s")).extend(
    i2c.i2c_device_schema(0x40)))


def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    yield cg.register_component(var, config)
    yield i2c.register_i2c_device(var, config)

    cg.add(var.set_shunt_resistance_ohm(config[CONF_SHUNT_RESISTANCE]))
    cg.add(var.set_max_current_a(config[CONF_MAX_CURRENT]))
Esempio n. 6
0
        "on_off",
        f"{CONF_TURN_ON_ACTION} and {CONF_TURN_OFF_ACTION} must both be defined",
    ):
    automation.validate_automation(single=True),
    cv.Inclusive(
        CONF_TURN_OFF_ACTION,
        "on_off",
        f"{CONF_TURN_ON_ACTION} and {CONF_TURN_OFF_ACTION} must both be defined",
    ):
    automation.validate_automation(single=True),
    cv.Optional(CONF_STATE_CHANGE_ACTION):
    automation.validate_automation(single=True),
    cv.Required(CONF_PERIOD):
    cv.All(
        cv.positive_time_period_milliseconds,
        cv.Range(min=core.TimePeriod(milliseconds=100)),
    ),
    cv.Optional(CONF_RESTART_CYCLE_ON_STATE_CHANGE, default=False):
    cv.boolean,
}).extend(cv.COMPONENT_SCHEMA)


async def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    await cg.register_component(var, config)
    await output.register_output(var, config)
    if CONF_PIN in config:
        pin = await cg.gpio_pin_expression(config[CONF_PIN])
        cg.add(var.set_pin(pin))
    if CONF_STATE_CHANGE_ACTION in config:
        await automation.build_automation(
Esempio n. 7
0
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome import pins
from esphome.components import display
from esphome.const import CONF_CLK_PIN, CONF_DIO_PIN, CONF_ID, CONF_LAMBDA, CONF_INTENSITY

tm1637_ns = cg.esphome_ns.namespace('tm1637')
TM1637Display = tm1637_ns.class_('TM1637Display', cg.PollingComponent)
TM1637DisplayRef = TM1637Display.operator('ref')

CONFIG_SCHEMA = display.BASIC_DISPLAY_SCHEMA.extend({
    cv.GenerateID(): cv.declare_id(TM1637Display),

    cv.Optional(CONF_INTENSITY, default=7): cv.All(cv.uint8_t, cv.Range(min=0, max=7)),
    cv.Required(CONF_CLK_PIN): pins.internal_gpio_output_pin_schema,
    cv.Required(CONF_DIO_PIN): pins.internal_gpio_output_pin_schema,
}).extend(cv.polling_component_schema('1s'))


def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    yield cg.register_component(var, config)
    yield display.register_display(var, config)

    clk = yield cg.gpio_pin_expression(config[CONF_CLK_PIN])
    cg.add(var.set_clk_pin(clk))
    dio = yield cg.gpio_pin_expression(config[CONF_DIO_PIN])
    cg.add(var.set_dio_pin(dio))

    cg.add(var.set_intensity(config[CONF_INTENSITY]))
Esempio n. 8
0
CONF_CF_PIN = 'cf_pin'
CONFIG_SCHEMA = cv.Schema({
    cv.GenerateID(): cv.declare_id(HLW8012Component),
    cv.Required(CONF_SEL_PIN): pins.gpio_output_pin_schema,
    cv.Required(CONF_CF_PIN): cv.All(pins.internal_gpio_input_pullup_pin_schema,
                                     pins.validate_has_interrupt),
    cv.Required(CONF_CF1_PIN): cv.All(pins.internal_gpio_input_pullup_pin_schema,
                                      pins.validate_has_interrupt),

    cv.Optional(CONF_VOLTAGE): sensor.sensor_schema(UNIT_VOLT, ICON_FLASH, 1),
    cv.Optional(CONF_CURRENT): sensor.sensor_schema(UNIT_AMPERE, ICON_FLASH, 2),
    cv.Optional(CONF_POWER): sensor.sensor_schema(UNIT_WATT, ICON_FLASH, 1),

    cv.Optional(CONF_CURRENT_RESISTOR, default=0.001): cv.resistance,
    cv.Optional(CONF_VOLTAGE_DIVIDER, default=2351): cv.positive_float,
    cv.Optional(CONF_CHANGE_MODE_EVERY, default=8): cv.All(cv.uint32_t, cv.Range(min=1)),
    cv.Optional(CONF_INITIAL_MODE, default=CONF_VOLTAGE): cv.one_of(*INITIAL_MODES, lower=True),
}).extend(cv.polling_component_schema('60s'))


def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    yield cg.register_component(var, config)

    sel = yield cg.gpio_pin_expression(config[CONF_SEL_PIN])
    cg.add(var.set_sel_pin(sel))
    cf = yield cg.gpio_pin_expression(config[CONF_CF_PIN])
    cg.add(var.set_cf_pin(cf))
    cf1 = yield cg.gpio_pin_expression(config[CONF_CF1_PIN])
    cg.add(var.set_cf1_pin(cf1))
Esempio n. 9
0
    cv.Optional(CONF_CURRENT):
    sensor.sensor_schema(
        unit_of_measurement=UNIT_AMPERE,
        accuracy_decimals=2,
        device_class=DEVICE_CLASS_CURRENT,
        state_class=STATE_CLASS_MEASUREMENT,
    ),
    cv.Optional(CONF_POWER):
    sensor.sensor_schema(
        unit_of_measurement=UNIT_WATT,
        accuracy_decimals=2,
        device_class=DEVICE_CLASS_POWER,
        state_class=STATE_CLASS_MEASUREMENT,
    ),
    cv.Optional(CONF_SHUNT_RESISTANCE, default=0.1):
    cv.All(cv.resistance, cv.Range(min=0.0, max=32.0)),
})

CONFIG_SCHEMA = (cv.Schema({
    cv.GenerateID(): cv.declare_id(INA3221Component),
    cv.Optional(CONF_CHANNEL_1): INA3221_CHANNEL_SCHEMA,
    cv.Optional(CONF_CHANNEL_2): INA3221_CHANNEL_SCHEMA,
    cv.Optional(CONF_CHANNEL_3): INA3221_CHANNEL_SCHEMA,
}).extend(cv.polling_component_schema("60s")).extend(
    i2c.i2c_device_schema(0x40)))


async def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    await cg.register_component(var, config)
    await i2c.register_i2c_device(var, config)
    '1.5V': cg.global_ns.TOUCH_HVOLT_ATTEN_1V5,
    '1V': cg.global_ns.TOUCH_HVOLT_ATTEN_1V,
    '0.5V': cg.global_ns.TOUCH_HVOLT_ATTEN_0V5,
    '0V': cg.global_ns.TOUCH_HVOLT_ATTEN_0V,
}

CONFIG_SCHEMA = cv.Schema({
    cv.GenerateID():
    cv.declare_id(ESP32RawTouchComponent),
    cv.Optional(CONF_SETUP_MODE, default=False):
    cv.boolean,
    cv.Optional(CONF_IIR_FILTER, default='0ms'):
    cv.positive_time_period_milliseconds,
    cv.Optional(CONF_SLEEP_DURATION, default='27306us'):
    cv.All(cv.positive_time_period,
           cv.Range(max=TimePeriod(microseconds=436906))),
    cv.Optional(CONF_MEASUREMENT_DURATION, default='8192us'):
    cv.All(cv.positive_time_period,
           cv.Range(max=TimePeriod(microseconds=8192))),
    cv.Optional(CONF_LOW_VOLTAGE_REFERENCE, default='0.5V'):
    validate_voltage(LOW_VOLTAGE_REFERENCE),
    cv.Optional(CONF_HIGH_VOLTAGE_REFERENCE, default='2.7V'):
    validate_voltage(HIGH_VOLTAGE_REFERENCE),
    cv.Optional(CONF_VOLTAGE_ATTENUATION, default='0V'):
    validate_voltage(VOLTAGE_ATTENUATION),
}).extend(cv.COMPONENT_SCHEMA)


def to_code(config):
    touch = cg.new_Pvariable(config[CONF_ID])
    yield cg.register_component(touch, config)
Esempio n. 11
0
    return cv.one_of(*uarts, upper=True)(uart)


CONFIG_SCHEMA = climate.CLIMATE_SCHEMA.extend({
    cv.GenerateID():
    cv.declare_id(MitsubishiHeatPump),
    cv.Optional(CONF_HARDWARE_UART, default="UART0"):
    valid_uart,
    cv.Optional(CONF_BAUD_RATE):
    cv.positive_int,

    # If polling interval is greater than 9 seconds, the HeatPump library
    # reconnects, but doesn't then follow up with our data request.
    cv.Optional(CONF_UPDATE_INTERVAL, default="500ms"):
    cv.All(cv.update_interval, cv.Range(max=cv.TimePeriod(milliseconds=9000))),

    # Optionally override the supported ClimateTraits.
    cv.Optional(CONF_SUPPORTS, default={}):
    cv.Schema({
        cv.Optional(CONF_MODE, default=DEFAULT_CLIMATE_MODES):
        cv.ensure_list(climate.validate_climate_mode),
        cv.Optional(CONF_FAN_MODE, default=DEFAULT_FAN_MODES):
        cv.ensure_list(climate.validate_climate_fan_mode),
        cv.Optional(CONF_SWING_MODE, default=DEFAULT_SWING_MODES):
        cv.ensure_list(climate.validate_climate_swing_mode),
    }),
}).extend(cv.COMPONENT_SCHEMA)


@coroutine
Esempio n. 12
0
        DEVICE_CLASS_EMPTY,
        STATE_CLASS_MEASUREMENT,
    ),
    cv.Optional(CONF_IIR_FILTER, default="OFF"):
    cv.enum(IIR_FILTER_OPTIONS, upper=True),
    cv.Optional(CONF_HEATER):
    cv.Any(
        None,
        cv.All(
            cv.Schema({
                cv.Optional(CONF_TEMPERATURE, default=320):
                cv.int_range(min=200, max=400),
                cv.Optional(CONF_DURATION, default="150ms"):
                cv.All(
                    cv.positive_time_period_milliseconds,
                    cv.Range(max=core.TimePeriod(milliseconds=4032)),
                ),
            }),
            cv.has_at_least_one_key(CONF_TEMPERATURE, CONF_DURATION),
        ),
    ),
}).extend(cv.polling_component_schema("60s")).extend(
    i2c.i2c_device_schema(0x76)))


async def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    await cg.register_component(var, config)
    await i2c.register_i2c_device(var, config)

    if CONF_TEMPERATURE in config:
Esempio n. 13
0
from . import XiaomiRTCGQ02LM

DEPENDENCIES = ["xiaomi_rtcgq02lm"]

CONF_BUTTON = "button"

CONFIG_SCHEMA = cv.Schema({
    cv.GenerateID():
    cv.use_id(XiaomiRTCGQ02LM),
    cv.Optional(CONF_MOTION):
    binary_sensor.binary_sensor_schema(
        device_class=DEVICE_CLASS_MOTION).extend({
            cv.Optional(CONF_TIMEOUT, default="5s"):
            cv.All(
                cv.positive_time_period_milliseconds,
                cv.Range(max=TimePeriod(milliseconds=65535)),
            ),
        }),
    cv.Optional(CONF_LIGHT):
    binary_sensor.binary_sensor_schema(device_class=DEVICE_CLASS_LIGHT),
    cv.Optional(CONF_BUTTON):
    binary_sensor.binary_sensor_schema().extend({
        cv.Optional(CONF_TIMEOUT, default="200ms"):
        cv.All(
            cv.positive_time_period_milliseconds,
            cv.Range(max=TimePeriod(milliseconds=65535)),
        ),
    }),
})

Esempio n. 14
0
DEPENDENCIES = ['i2c']

CONF_CHANNEL_1 = 'channel_1'
CONF_CHANNEL_2 = 'channel_2'
CONF_CHANNEL_3 = 'channel_3'

ina3221_ns = cg.esphome_ns.namespace('ina3221')
INA3221Component = ina3221_ns.class_('INA3221Component', cg.PollingComponent, i2c.I2CDevice)

INA3221_CHANNEL_SCHEMA = cv.Schema({
    cv.Optional(CONF_BUS_VOLTAGE): sensor.sensor_schema(UNIT_VOLT, ICON_FLASH, 2),
    cv.Optional(CONF_SHUNT_VOLTAGE): sensor.sensor_schema(UNIT_VOLT, ICON_FLASH, 2),
    cv.Optional(CONF_CURRENT): sensor.sensor_schema(UNIT_AMPERE, ICON_FLASH, 2),
    cv.Optional(CONF_POWER): sensor.sensor_schema(UNIT_WATT, ICON_FLASH, 2),
    cv.Optional(CONF_SHUNT_RESISTANCE, default=0.1): cv.All(cv.resistance,
                                                            cv.Range(min=0.0, max=32.0)),
})

CONFIG_SCHEMA = cv.Schema({
    cv.GenerateID(): cv.declare_id(INA3221Component),
    cv.Optional(CONF_CHANNEL_1): INA3221_CHANNEL_SCHEMA,
    cv.Optional(CONF_CHANNEL_2): INA3221_CHANNEL_SCHEMA,
    cv.Optional(CONF_CHANNEL_3): INA3221_CHANNEL_SCHEMA,
}).extend(cv.polling_component_schema('60s')).extend(i2c.i2c_device_schema(0x40))


def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    yield cg.register_component(var, config)
    yield i2c.register_i2c_device(var, config)
    cv.Required(CONF_VSYNC_PIN): pins.input_pin,
    cv.Required(CONF_HREF_PIN): pins.input_pin,
    cv.Required(CONF_PIXEL_CLOCK_PIN): pins.input_pin,
    cv.Required(CONF_EXTERNAL_CLOCK): cv.Schema({
        cv.Required(CONF_PIN): pins.output_pin,
        cv.Optional(CONF_FREQUENCY, default='20MHz'): cv.All(cv.frequency, cv.one_of(20e6, 10e6)),
    }),
    cv.Required(CONF_I2C_PINS): cv.Schema({
        cv.Required(CONF_SDA): pins.output_pin,
        cv.Required(CONF_SCL): pins.output_pin,
    }),
    cv.Optional(CONF_RESET_PIN): pins.output_pin,
    cv.Optional(CONF_POWER_DOWN_PIN): pins.output_pin,

    cv.Optional(CONF_MAX_FRAMERATE, default='10 fps'): cv.All(cv.framerate,
                                                              cv.Range(min=0, min_included=False,
                                                                       max=60)),
    cv.Optional(CONF_IDLE_FRAMERATE, default='0.1 fps'): cv.All(cv.framerate,
                                                                cv.Range(min=0, max=1)),
    cv.Optional(CONF_RESOLUTION, default='640X480'): cv.enum(FRAME_SIZES, upper=True),
    cv.Optional(CONF_JPEG_QUALITY, default=10): cv.int_range(min=10, max=63),
    cv.Optional(CONF_CONTRAST, default=0): camera_range_param,
    cv.Optional(CONF_BRIGHTNESS, default=0): camera_range_param,
    cv.Optional(CONF_SATURATION, default=0): camera_range_param,
    cv.Optional(CONF_VERTICAL_FLIP, default=True): cv.boolean,
    cv.Optional(CONF_HORIZONTAL_MIRROR, default=True): cv.boolean,
    cv.Optional(CONF_TEST_PATTERN, default=False): cv.boolean,
}).extend(cv.COMPONENT_SCHEMA)

SETTERS = {
    CONF_DATA_PINS: 'set_data_pins',
    CONF_VSYNC_PIN: 'set_vsync_pin',
Esempio n. 16
0
    CONF_ID,
    CONF_LAMBDA,
    CONF_INTENSITY,
)

CODEOWNERS = ["@glmnet"]

tm1637_ns = cg.esphome_ns.namespace("tm1637")
TM1637Display = tm1637_ns.class_("TM1637Display", cg.PollingComponent)
TM1637DisplayRef = TM1637Display.operator("ref")

CONFIG_SCHEMA = display.BASIC_DISPLAY_SCHEMA.extend(
    {
        cv.GenerateID(): cv.declare_id(TM1637Display),
        cv.Optional(CONF_INTENSITY, default=7): cv.All(
            cv.uint8_t, cv.Range(min=0, max=7)
        ),
        cv.Required(CONF_CLK_PIN): pins.gpio_output_pin_schema,
        cv.Required(CONF_DIO_PIN): pins.gpio_output_pin_schema,
    }
).extend(cv.polling_component_schema("1s"))


def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    yield cg.register_component(var, config)
    yield display.register_display(var, config)

    clk = yield cg.gpio_pin_expression(config[CONF_CLK_PIN])
    cg.add(var.set_clk_pin(clk))
    dio = yield cg.gpio_pin_expression(config[CONF_DIO_PIN])
Esempio n. 17
0
@register_addressable_effect(
    "addressable_color_wipe",
    AddressableColorWipeEffect,
    "Color Wipe",
    {
        cv.Optional(
            CONF_COLORS, default=[{CONF_NUM_LEDS: 1, CONF_RANDOM: True}]
        ): cv.ensure_list(
            {
                cv.Optional(CONF_RED, default=1.0): cv.percentage,
                cv.Optional(CONF_GREEN, default=1.0): cv.percentage,
                cv.Optional(CONF_BLUE, default=1.0): cv.percentage,
                cv.Optional(CONF_WHITE, default=1.0): cv.percentage,
                cv.Optional(CONF_RANDOM, default=False): cv.boolean,
                cv.Required(CONF_NUM_LEDS): cv.All(cv.uint32_t, cv.Range(min=1)),
            }
        ),
        cv.Optional(
            CONF_ADD_LED_INTERVAL, default="0.1s"
        ): cv.positive_time_period_milliseconds,
        cv.Optional(CONF_REVERSE, default=False): cv.boolean,
    },
)
async def addressable_color_wipe_effect_to_code(config, effect_id):
    var = cg.new_Pvariable(effect_id, config[CONF_NAME])
    cg.add(var.set_add_led_interval(config[CONF_ADD_LED_INTERVAL]))
    cg.add(var.set_reverse(config[CONF_REVERSE]))
    colors = []
    for color in config.get(CONF_COLORS, []):
        colors.append(
Esempio n. 18
0
    cv.All(pins.internal_gpio_input_pullup_pin_schema,
           pins.validate_has_interrupt),
    cv.Optional(CONF_VOLTAGE):
    sensor.sensor_schema(UNIT_VOLT, ICON_EMPTY, 1, DEVICE_CLASS_VOLTAGE),
    cv.Optional(CONF_CURRENT):
    sensor.sensor_schema(UNIT_AMPERE, ICON_EMPTY, 2, DEVICE_CLASS_CURRENT),
    cv.Optional(CONF_POWER):
    sensor.sensor_schema(UNIT_WATT, ICON_EMPTY, 1, DEVICE_CLASS_POWER),
    cv.Optional(CONF_ENERGY):
    sensor.sensor_schema(UNIT_WATT_HOURS, ICON_EMPTY, 1, DEVICE_CLASS_ENERGY),
    cv.Optional(CONF_CURRENT_RESISTOR, default=0.001):
    cv.resistance,
    cv.Optional(CONF_VOLTAGE_DIVIDER, default=2351):
    cv.positive_float,
    cv.Optional(CONF_CHANGE_MODE_EVERY, default=8):
    cv.All(cv.uint32_t, cv.Range(min=1)),
    cv.Optional(CONF_INITIAL_MODE, default=CONF_VOLTAGE):
    cv.one_of(*INITIAL_MODES, lower=True),
}).extend(cv.polling_component_schema("60s"))


def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    yield cg.register_component(var, config)

    sel = yield cg.gpio_pin_expression(config[CONF_SEL_PIN])
    cg.add(var.set_sel_pin(sel))
    cf = yield cg.gpio_pin_expression(config[CONF_CF_PIN])
    cg.add(var.set_cf_pin(cf))
    cf1 = yield cg.gpio_pin_expression(config[CONF_CF1_PIN])
    cg.add(var.set_cf1_pin(cf1))
Esempio n. 19
0
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import i2c
from esphome.const import CONF_FREQUENCY, CONF_ID

DEPENDENCIES = ["i2c"]
MULTI_CONF = True

pca9685_ns = cg.esphome_ns.namespace("pca9685")
PCA9685Output = pca9685_ns.class_("PCA9685Output", cg.Component, i2c.I2CDevice)

CONFIG_SCHEMA = (
    cv.Schema(
        {
            cv.GenerateID(): cv.declare_id(PCA9685Output),
            cv.Required(CONF_FREQUENCY): cv.All(
                cv.frequency, cv.Range(min=23.84, max=1525.88)
            ),
        }
    )
    .extend(cv.COMPONENT_SCHEMA)
    .extend(i2c.i2c_device_schema(0x40))
)


async def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID], config[CONF_FREQUENCY])
    await cg.register_component(var, config)
    await i2c.register_i2c_device(var, config)
Esempio n. 20
0
        )
    return value


CONFIG_SCHEMA = cv.All(
    display.FULL_DISPLAY_SCHEMA.extend(
        {
            cv.GenerateID(): cv.declare_id(WaveshareEPaper),
            cv.Required(CONF_DC_PIN): pins.gpio_output_pin_schema,
            cv.Required(CONF_MODEL): cv.one_of(*MODELS, lower=True),
            cv.Optional(CONF_RESET_PIN): pins.gpio_output_pin_schema,
            cv.Optional(CONF_BUSY_PIN): pins.gpio_input_pin_schema,
            cv.Optional(CONF_FULL_UPDATE_EVERY): cv.uint32_t,
            cv.Optional(CONF_RESET_DURATION): cv.All(
                cv.positive_time_period_milliseconds,
                cv.Range(max=core.TimePeriod(milliseconds=500)),
            ),
        }
    )
    .extend(cv.polling_component_schema("1s"))
    .extend(spi.spi_device_schema()),
    validate_full_update_every_only_type_a,
    cv.has_at_most_one_key(CONF_PAGES, CONF_LAMBDA),
)


async def to_code(config):
    model_type, model = MODELS[config[CONF_MODEL]]
    if model_type == "a":
        rhs = WaveshareEPaperTypeA.new(model)
        var = cg.Pvariable(config[CONF_ID], rhs, WaveshareEPaperTypeA)
Esempio n. 21
0
    CONF_ID,
    CONF_LAMBDA,
    CONF_INTENSITY,
)

CODEOWNERS = ["@glmnet"]

tm1637_ns = cg.esphome_ns.namespace("tm1637")
TM1637Display = tm1637_ns.class_("TM1637Display", cg.PollingComponent)
TM1637DisplayRef = TM1637Display.operator("ref")

CONFIG_SCHEMA = display.BASIC_DISPLAY_SCHEMA.extend({
    cv.GenerateID():
    cv.declare_id(TM1637Display),
    cv.Optional(CONF_INTENSITY, default=7):
    cv.All(cv.uint8_t, cv.Range(min=0, max=7)),
    cv.Required(CONF_CLK_PIN):
    pins.gpio_output_pin_schema,
    cv.Required(CONF_DIO_PIN):
    pins.gpio_output_pin_schema,
}).extend(cv.polling_component_schema("1s"))


async def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    await cg.register_component(var, config)
    await display.register_display(var, config)

    clk = await cg.gpio_pin_expression(config[CONF_CLK_PIN])
    cg.add(var.set_clk_pin(clk))
    dio = await cg.gpio_pin_expression(config[CONF_DIO_PIN])
ESP_PLATFORMS = [ESP_PLATFORM_ESP8266]


def valid_pwm_pin(value):
    num = value[CONF_NUMBER]
    cv.one_of(0, 1, 2, 3, 4, 5, 9, 10, 12, 13, 14, 15, 16)(num)
    return value


esp8266_pwm_ns = cg.esphome_ns.namespace('esp8266_pwm')
ESP8266PWM = esp8266_pwm_ns.class_('ESP8266PWM', output.FloatOutput,
                                   cg.Component)
SetFrequencyAction = esp8266_pwm_ns.class_('SetFrequencyAction',
                                           automation.Action)
validate_frequency = cv.All(cv.frequency, cv.Range(min=1.0e-6))

CONFIG_SCHEMA = output.FLOAT_OUTPUT_SCHEMA.extend({
    cv.Required(CONF_ID):
    cv.declare_id(ESP8266PWM),
    cv.Required(CONF_PIN):
    cv.All(pins.internal_gpio_output_pin_schema, valid_pwm_pin),
    cv.Optional(CONF_FREQUENCY, default='1kHz'):
    validate_frequency,
}).extend(cv.COMPONENT_SCHEMA)


def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    yield cg.register_component(var, config)
    yield output.register_output(var, config)
Esempio n. 23
0
max31865_ns = cg.esphome_ns.namespace('max31865')
MAX31865Sensor = max31865_ns.class_('MAX31865Sensor', sensor.Sensor,
                                    cg.PollingComponent, spi.SPIDevice)

MAX31865ConfigFilter = max31865_ns.enum('MAX31865ConfigFilter')
FILTER = {
    '50HZ': MAX31865ConfigFilter.FILTER_50HZ,
    '60HZ': MAX31865ConfigFilter.FILTER_60HZ,
}

CONFIG_SCHEMA = sensor.sensor_schema(UNIT_CELSIUS, ICON_THERMOMETER, 2).extend(
    {
        cv.GenerateID():
        cv.declare_id(MAX31865Sensor),
        cv.Required(CONF_REFERENCE_RESISTANCE):
        cv.All(cv.resistance, cv.Range(min=100, max=10000)),
        cv.Required(CONF_RTD_NOMINAL_RESISTANCE):
        cv.All(cv.resistance, cv.Range(min=100, max=1000)),
        cv.Optional(CONF_MAINS_FILTER, default='60HZ'):
        cv.enum(FILTER, upper=True, space=''),
        cv.Optional(CONF_RTD_WIRES, default=4):
        cv.int_range(min=2, max=4),
    }).extend(cv.polling_component_schema('60s')).extend(
        spi.spi_device_schema())


def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    yield cg.register_component(var, config)
    yield spi.register_spi_device(var, config)
    yield sensor.register_sensor(var, config)
Esempio n. 24
0
     cv.Required(CONF_PIN):
     pins.output_pin,
     cv.Optional(CONF_FREQUENCY, default="20MHz"):
     cv.All(cv.frequency, cv.one_of(20e6, 10e6)),
 }),
 cv.Required(CONF_I2C_PINS):
 cv.Schema({
     cv.Required(CONF_SDA): pins.output_pin,
     cv.Required(CONF_SCL): pins.output_pin,
 }),
 cv.Optional(CONF_RESET_PIN):
 pins.output_pin,
 cv.Optional(CONF_POWER_DOWN_PIN):
 pins.output_pin,
 cv.Optional(CONF_MAX_FRAMERATE, default="10 fps"):
 cv.All(cv.framerate, cv.Range(min=0, min_included=False, max=60)),
 cv.Optional(CONF_IDLE_FRAMERATE, default="0.1 fps"):
 cv.All(cv.framerate, cv.Range(min=0, max=1)),
 cv.Optional(CONF_RESOLUTION, default="640X480"):
 cv.enum(FRAME_SIZES, upper=True),
 cv.Optional(CONF_JPEG_QUALITY, default=10):
 cv.int_range(min=10, max=63),
 cv.Optional(CONF_CONTRAST, default=0):
 camera_range_param,
 cv.Optional(CONF_BRIGHTNESS, default=0):
 camera_range_param,
 cv.Optional(CONF_SATURATION, default=0):
 camera_range_param,
 cv.Optional(CONF_VERTICAL_FLIP, default=True):
 cv.boolean,
 cv.Optional(CONF_HORIZONTAL_MIRROR, default=True):
Esempio n. 25
0
    if cg.is_template(code_):
        template_ = await cg.templatable(code_, args, cg.std_vector.template(cg.int32))
        cg.add(var.set_code_template(template_))
    else:
        code_ = config[CONF_CODE]
        arr = cg.progmem_array(config[CONF_CODE_STORAGE_ID], code_)
        cg.add(var.set_code_static(arr, len(code_)))
    templ = await cg.templatable(config[CONF_CARRIER_FREQUENCY], args, cg.uint32)
    cg.add(var.set_carrier_frequency(templ))


# RC5
RC5Data, RC5BinarySensor, RC5Trigger, RC5Action, RC5Dumper = declare_protocol("RC5")
RC5_SCHEMA = cv.Schema(
    {
        cv.Required(CONF_ADDRESS): cv.All(cv.hex_int, cv.Range(min=0, max=0x1F)),
        cv.Required(CONF_COMMAND): cv.All(cv.hex_int, cv.Range(min=0, max=0x7F)),
    }
)


@register_binary_sensor("rc5", RC5BinarySensor, RC5_SCHEMA)
def rc5_binary_sensor(var, config):
    cg.add(
        var.set_data(
            cg.StructInitializer(
                RC5Data,
                ("address", config[CONF_ADDRESS]),
                ("command", config[CONF_COMMAND]),
            )
        )
Esempio n. 26
0
    pins.internal_gpio_pin_number({CONF_OUTPUT: True}),
)

CONFIG_SCHEMA = cv.Schema({
    cv.GenerateID():
    _bus_declare_type,
    cv.Optional(CONF_SDA, default="SDA"):
    pin_with_input_and_output_support,
    cv.SplitDefault(CONF_SDA_PULLUP_ENABLED, esp32_idf=True):
    cv.All(cv.only_with_esp_idf, cv.boolean),
    cv.Optional(CONF_SCL, default="SCL"):
    pin_with_input_and_output_support,
    cv.SplitDefault(CONF_SCL_PULLUP_ENABLED, esp32_idf=True):
    cv.All(cv.only_with_esp_idf, cv.boolean),
    cv.Optional(CONF_FREQUENCY, default="50kHz"):
    cv.All(cv.frequency, cv.Range(min=0, min_included=False)),
    cv.Optional(CONF_SCAN, default=True):
    cv.boolean,
}).extend(cv.COMPONENT_SCHEMA)


@coroutine_with_priority(1.0)
async def to_code(config):
    cg.add_global(i2c_ns.using)
    var = cg.new_Pvariable(config[CONF_ID])
    await cg.register_component(var, config)

    cg.add(var.set_sda_pin(config[CONF_SDA]))
    if CONF_SDA_PULLUP_ENABLED in config:
        cg.add(var.set_sda_pullup_enabled(config[CONF_SDA_PULLUP_ENABLED]))
    cg.add(var.set_scl_pin(config[CONF_SCL]))
Esempio n. 27
0
    cv.Optional(CONF_CURRENT):
    sensor.sensor_schema(
        unit_of_measurement=UNIT_AMPERE,
        accuracy_decimals=3,
        device_class=DEVICE_CLASS_CURRENT,
        state_class=STATE_CLASS_MEASUREMENT,
    ),
    cv.Optional(CONF_POWER):
    sensor.sensor_schema(
        unit_of_measurement=UNIT_WATT,
        accuracy_decimals=2,
        device_class=DEVICE_CLASS_POWER,
        state_class=STATE_CLASS_MEASUREMENT,
    ),
    cv.Optional(CONF_SHUNT_RESISTANCE, default=0.1):
    cv.All(cv.resistance, cv.Range(min=0.0)),
    cv.Optional(CONF_MAX_CURRENT, default=3.2):
    cv.All(cv.current, cv.Range(min=0.0)),
}).extend(cv.polling_component_schema("60s")).extend(
    i2c.i2c_device_schema(0x40)))


async def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    await cg.register_component(var, config)
    await i2c.register_i2c_device(var, config)

    cg.add(var.set_shunt_resistance_ohm(config[CONF_SHUNT_RESISTANCE]))

    cg.add(var.set_max_current_a(config[CONF_MAX_CURRENT]))
Esempio n. 28
0
    ),
    cv.Optional(CONF_AUTOMATIC_SELF_CALIBRATION, default=True):
    cv.boolean,
    cv.Optional(CONF_ALTITUDE_COMPENSATION):
    cv.All(
        cv.float_with_unit("altitude", "(m|m a.s.l.|MAMSL|MASL)"),
        cv.int_range(min=0, max=0xFFFF, max_included=False),
    ),
    cv.Optional(CONF_AMBIENT_PRESSURE_COMPENSATION, default=0):
    cv.pressure,
    cv.Optional(CONF_TEMPERATURE_OFFSET):
    cv.temperature,
    cv.Optional(CONF_UPDATE_INTERVAL, default="60s"):
    cv.All(
        cv.positive_time_period_seconds,
        cv.Range(min=core.TimePeriod(seconds=1),
                 max=core.TimePeriod(seconds=1800)),
    ),
}).extend(cv.COMPONENT_SCHEMA).extend(i2c.i2c_device_schema(0x61)))


async def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    await cg.register_component(var, config)
    await i2c.register_i2c_device(var, config)

    cg.add(
        var.set_automatic_self_calibration(
            config[CONF_AUTOMATIC_SELF_CALIBRATION]))
    if CONF_ALTITUDE_COMPENSATION in config:
        cg.add(
            var.set_altitude_compensation(config[CONF_ALTITUDE_COMPENSATION]))
Esempio n. 29
0
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome import pins
from esphome.components import remote_base
from esphome.const import CONF_CARRIER_DUTY_PERCENT, CONF_ID, CONF_PIN

AUTO_LOAD = ["remote_base"]
remote_transmitter_ns = cg.esphome_ns.namespace("remote_transmitter")
RemoteTransmitterComponent = remote_transmitter_ns.class_(
    "RemoteTransmitterComponent", remote_base.RemoteTransmitterBase,
    cg.Component)

MULTI_CONF = True
CONFIG_SCHEMA = cv.Schema({
    cv.GenerateID():
    cv.declare_id(RemoteTransmitterComponent),
    cv.Required(CONF_PIN):
    pins.gpio_output_pin_schema,
    cv.Required(CONF_CARRIER_DUTY_PERCENT):
    cv.All(cv.percentage_int, cv.Range(min=1, max=100)),
}).extend(cv.COMPONENT_SCHEMA)


def to_code(config):
    pin = yield cg.gpio_pin_expression(config[CONF_PIN])
    var = cg.new_Pvariable(config[CONF_ID], pin)
    yield cg.register_component(var, config)

    cg.add(var.set_carrier_duty_percent(config[CONF_CARRIER_DUTY_PERCENT]))
Esempio n. 30
0
                             ble_client.BLEClientNode)
PVVXDisplayRef = PVVXDisplay.operator("ref")

CONFIG_SCHEMA = (display.BASIC_DISPLAY_SCHEMA.extend({
    cv.GenerateID():
    cv.declare_id(PVVXDisplay),
    cv.Optional(CONF_TIME_ID):
    cv.use_id(time.RealTimeClock),
    cv.Optional(CONF_AUTO_CLEAR_ENABLED, default=True):
    cv.boolean,
    cv.Optional(CONF_DISCONNECT_DELAY, default="5s"):
    cv.positive_time_period,
    cv.Optional(CONF_VALIDITY_PERIOD, default="5min"):
    cv.All(
        cv.positive_time_period_seconds,
        cv.Range(max=cv.TimePeriod(seconds=65535)),
    ),
}).extend(ble_client.BLE_CLIENT_SCHEMA).extend(
    cv.polling_component_schema("60s")))


async def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    await cg.register_component(var, config)
    await display.register_display(var, config)
    await ble_client.register_ble_node(var, config)
    cg.add(
        var.set_disconnect_delay(
            config[CONF_DISCONNECT_DELAY].total_milliseconds))
    cg.add(var.set_auto_clear(config[CONF_AUTO_CLEAR_ENABLED]))
    cg.add(var.set_validity_period(config[CONF_VALIDITY_PERIOD].total_seconds))