Beispiel #1
0
def i2c_device_schema(default_address):
    """Create a schema for a i2c device.

    :param default_address: The default address of the i2c device, can be None to represent
      a required option.
    :return: The i2c device schema, `extend` this in your config schema.
    """
    schema = {
        cv.GenerateID(CONF_I2C_ID):
        cv.use_id(I2CBus),
        cv.Optional("multiplexer"):
        cv.invalid(
            "This option has been removed, please see "
            "the tca9584a docs for the updated way to use multiplexers"),
    }
    if default_address is None:
        schema[cv.Required(CONF_ADDRESS)] = cv.i2c_address
    else:
        schema[cv.Optional(CONF_ADDRESS,
                           default=default_address)] = cv.i2c_address
    return cv.Schema(schema)
Beispiel #2
0
import esphome.config_validation as cv

CONFIG_SCHEMA = cv.invalid("This platform has been renamed to midea in 2021.9")
import esphome.config_validation as cv

CONFIG_SCHEMA = cv.invalid(
    "This platform has been renamed to ble_presence in 1.13")
Beispiel #4
0
        cv.Optional(CONF_ENABLE_MDNS, default=True):
        cv.boolean,
        cv.Optional(CONF_DOMAIN, default=".local"):
        cv.domain_name,
        cv.Optional(CONF_REBOOT_TIMEOUT, default="15min"):
        cv.positive_time_period_milliseconds,
        cv.SplitDefault(CONF_POWER_SAVE_MODE, esp8266="none", esp32="light"):
        cv.enum(WIFI_POWER_SAVE_MODES, upper=True),
        cv.Optional(CONF_FAST_CONNECT, default=False):
        cv.boolean,
        cv.Optional(CONF_USE_ADDRESS):
        cv.string_strict,
        cv.SplitDefault(CONF_OUTPUT_POWER, esp8266=20.0):
        cv.All(cv.decibel, cv.float_range(min=10.0, max=20.5)),
        cv.Optional("hostname"):
        cv.invalid("The hostname option has been removed in 1.11.0"),
    }),
    validate,
)


def eap_auth(config):
    if config is None:
        return None
    ca_cert = ""
    if CONF_CERTIFICATE_AUTHORITY in config:
        ca_cert = wpa2_eap.read_relative_config_path(
            config[CONF_CERTIFICATE_AUTHORITY])
    client_cert = ""
    if CONF_CERTIFICATE in config:
        client_cert = wpa2_eap.read_relative_config_path(
Beispiel #5
0
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import switch, ble_client
from esphome.const import CONF_ICON, CONF_ID, CONF_INVERTED, ICON_BLUETOOTH
from .. import ble_client_ns

BLEClientSwitch = ble_client_ns.class_("BLEClientSwitch", switch.Switch,
                                       cg.Component, ble_client.BLEClientNode)

CONFIG_SCHEMA = (switch.SWITCH_SCHEMA.extend({
    cv.GenerateID():
    cv.declare_id(BLEClientSwitch),
    cv.Optional(CONF_INVERTED):
    cv.invalid("BLE client switches do not support inverted mode!"),
    cv.Optional(CONF_ICON, default=ICON_BLUETOOTH):
    switch.icon,
}).extend(ble_client.BLE_CLIENT_SCHEMA).extend(cv.COMPONENT_SCHEMA))


async def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    await cg.register_component(var, config)
    await switch.register_switch(var, config)
    await ble_client.register_ble_node(var, config)
Beispiel #6
0
    dumper = ns.class_(f"{name}Dumper", RemoteTransmitterDumper)
    return data, binary_sensor_, trigger, action, dumper


BINARY_SENSOR_REGISTRY = Registry(
    binary_sensor.BINARY_SENSOR_SCHEMA.extend({
        cv.GenerateID(CONF_RECEIVER_ID):
        cv.use_id(RemoteReceiverBase),
    }))
validate_binary_sensor = cv.validate_registry_entry("remote receiver",
                                                    BINARY_SENSOR_REGISTRY)
TRIGGER_REGISTRY = SimpleRegistry()
DUMPER_REGISTRY = Registry({
    cv.Optional(CONF_RECEIVER_ID):
    cv.invalid(
        "This has been removed in ESPHome 1.20.0 and the dumper attaches directly to the parent receiver."
    ),
})


def validate_dumpers(value):
    if isinstance(value, str) and value.lower() == "all":
        return validate_dumpers(list(DUMPER_REGISTRY.keys()))
    return cv.validate_registry("dumper", DUMPER_REGISTRY)(value)


def validate_triggers(base_schema):
    assert isinstance(base_schema, cv.Schema)

    @jschema_extractor("triggers")
    def validator(config):
Beispiel #7
0
        cv.Optional(CONF_MIN_LENGTH, default='50ms'): cv.positive_time_period_milliseconds,
        cv.Optional(CONF_MAX_LENGTH, default='350ms'): cv.positive_time_period_milliseconds,
    }),
    cv.Optional(CONF_ON_MULTI_CLICK): automation.validate_automation({
        cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(MultiClickTrigger),
        cv.Required(CONF_TIMING): cv.All([parse_multi_click_timing_str],
                                         validate_multi_click_timing),
        cv.Optional(CONF_INVALID_COOLDOWN, default='1s'): cv.positive_time_period_milliseconds,
    }),
    cv.Optional(CONF_ON_STATE): automation.validate_automation({
        cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(StateTrigger),
    }),

    cv.Optional(CONF_INVERTED): cv.invalid(
        "The inverted binary_sensor property has been replaced by the "
        "new 'invert' binary  sensor filter. Please see "
        "https://esphome.io/components/binary_sensor/index.html."
    ),
})


@coroutine
def setup_binary_sensor_core_(var, config):
    cg.add(var.set_name(config[CONF_NAME]))
    if CONF_INTERNAL in config:
        cg.add(var.set_internal(CONF_INTERNAL))
    if CONF_DEVICE_CLASS in config:
        cg.add(var.set_device_class(config[CONF_DEVICE_CLASS]))
    if CONF_INVERTED in config:
        cg.add(var.set_inverted(config[CONF_INVERTED]))
    if CONF_FILTERS in config:
Beispiel #8
0
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)


BUILD_FLAGS = '-DUSE_UART_SWITCH'
Beispiel #9
0
    state_hex_schema,
    cv.Optional(CONF_COMMAND, default={}):
    command_hex_schema
})

CONFIG_SCHEMA = fan.FAN_SCHEMA.extend({
    cv.GenerateID(CONF_OUTPUT_ID):
    cv.declare_id(RS485Fan),
    cv.Optional(CONF_SPEED, default={}):
    cv.Schema({
        cv.Optional(CONF_LOW): SPEED_SCHEMA,
        cv.Optional(CONF_MEDIUM): SPEED_SCHEMA,
        cv.Optional(CONF_HIGH): SPEED_SCHEMA
    }),
    cv.Optional(CONF_OUTPUT):
    cv.invalid("Not support output."),
    cv.Optional(CONF_OSCILLATION_OUTPUT):
    cv.invalid("Not support oscillation."),
    cv.Optional(CONF_DIRECTION_OUTPUT):
    cv.invalid("Not support direction.")
}).extend(rs485.RS485_DEVICE_SCHEMA).extend(cv.COMPONENT_SCHEMA)


async def to_code(config):
    var = cg.new_Pvariable(config[CONF_OUTPUT_ID])
    await cg.register_component(var, config)
    await fan.register_fan(var, config)

    speeds = config[CONF_SPEED]
    if CONF_LOW in speeds:
        speed = speeds[CONF_LOW]
Beispiel #10
0
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import switch
from esphome.const import CONF_ID, CONF_INVERTED, CONF_ICON, ICON_RESTART

restart_ns = cg.esphome_ns.namespace("restart")
RestartSwitch = restart_ns.class_("RestartSwitch", switch.Switch, cg.Component)

CONFIG_SCHEMA = switch.SWITCH_SCHEMA.extend({
    cv.GenerateID():
    cv.declare_id(RestartSwitch),
    cv.Optional(CONF_INVERTED):
    cv.invalid("Restart switches do not support inverted mode!"),
    cv.Optional(CONF_ICON, default=ICON_RESTART):
    switch.icon,
}).extend(cv.COMPONENT_SCHEMA)


def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    yield cg.register_component(var, config)
    yield switch.register_switch(var, config)
Beispiel #11
0
            cv.Optional(CONF_EAP): EAP_AUTH_SCHEMA,
            cv.Optional(CONF_AP): WIFI_NETWORK_AP,
            cv.Optional(CONF_DOMAIN, default=".local"): cv.domain_name,
            cv.Optional(
                CONF_REBOOT_TIMEOUT, default="15min"
            ): cv.positive_time_period_milliseconds,
            cv.SplitDefault(
                CONF_POWER_SAVE_MODE, esp8266="none", esp32="light"
            ): cv.enum(WIFI_POWER_SAVE_MODES, upper=True),
            cv.Optional(CONF_FAST_CONNECT, default=False): cv.boolean,
            cv.Optional(CONF_USE_ADDRESS): cv.string_strict,
            cv.SplitDefault(CONF_OUTPUT_POWER, esp8266=20.0): cv.All(
                cv.decibel, cv.float_range(min=10.0, max=20.5)
            ),
            cv.Optional("enable_mdns"): cv.invalid(
                "This option has been removed. Please use the [disabled] option under the "
                "new mdns component instead."
            ),
        }
    ),
    _validate,
)


def eap_auth(config):
    if config is None:
        return None
    ca_cert = ""
    if CONF_CERTIFICATE_AUTHORITY in config:
        ca_cert = wpa2_eap.read_relative_config_path(config[CONF_CERTIFICATE_AUTHORITY])
    client_cert = ""
    if CONF_CERTIFICATE in config:
        vol.Required(CONF_COMMAND): vol.All(cv.hex_int, vol.Range(min=0, max=0x3F)),
    }),
    vol.Optional(CONF_RAW): validate_raw,
    vol.Optional(CONF_RC_SWITCH_RAW): RC_SWITCH_RAW_SCHEMA,
    vol.Optional(CONF_RC_SWITCH_TYPE_A): RC_SWITCH_TYPE_A_SCHEMA,
    vol.Optional(CONF_RC_SWITCH_TYPE_B): RC_SWITCH_TYPE_B_SCHEMA,
    vol.Optional(CONF_RC_SWITCH_TYPE_C): RC_SWITCH_TYPE_C_SCHEMA,
    vol.Optional(CONF_RC_SWITCH_TYPE_D): RC_SWITCH_TYPE_D_SCHEMA,

    vol.Optional(CONF_REPEAT): vol.Any(cv.positive_not_null_int, cv.Schema({
        vol.Required(CONF_TIMES): cv.positive_not_null_int,
        vol.Required(CONF_WAIT_TIME): cv.positive_time_period_microseconds,
    })),
    cv.GenerateID(CONF_REMOTE_TRANSMITTER_ID): cv.use_variable_id(RemoteTransmitterComponent),
    cv.GenerateID(CONF_TRANSMITTER_ID): cv.declare_variable_id(RemoteTransmitter),
    vol.Optional(CONF_INVERTED): cv.invalid("Remote Transmitters do not support inverted mode!"),
}), cv.has_exactly_one_key(*REMOTE_KEYS))


def transmitter_base(full_config):
    name = full_config[CONF_NAME]
    key, config = next((k, v) for k, v in full_config.items() if k in REMOTE_KEYS)

    if key == CONF_JVC:
        return JVCTransmitter.new(name, config[CONF_DATA])
    if key == CONF_LG:
        return LGTransmitter.new(name, config[CONF_DATA], config[CONF_NBITS])
    if key == CONF_NEC:
        return NECTransmitter.new(name, config[CONF_ADDRESS], config[CONF_COMMAND])
    if key == CONF_PANASONIC:
        return PanasonicTransmitter.new(name, config[CONF_ADDRESS], config[CONF_COMMAND])
Beispiel #13
0
        cv.int_range(min=1),
        cv.Optional(CONF_TX_PIN):
        pins.internal_gpio_output_pin_schema,
        cv.Optional(CONF_RX_PIN):
        validate_rx_pin,
        cv.Optional(CONF_RX_BUFFER_SIZE, default=256):
        cv.validate_bytes,
        cv.Optional(CONF_STOP_BITS, default=1):
        cv.one_of(1, 2, int=True),
        cv.Optional(CONF_DATA_BITS, default=8):
        cv.int_range(min=5, max=8),
        cv.Optional(CONF_PARITY, default="NONE"):
        cv.enum(UART_PARITY_OPTIONS, upper=True),
        cv.Optional(CONF_INVERT):
        cv.invalid(
            "This option has been removed. Please instead use invert in the tx/rx pin schemas."
        ),
        cv.Optional(CONF_DEBUG):
        maybe_empty_debug,
    }).extend(cv.COMPONENT_SCHEMA),
    cv.has_at_least_one_key(CONF_TX_PIN, CONF_RX_PIN),
)


async def debug_to_code(config, parent):
    trigger = cg.new_Pvariable(config[CONF_TRIGGER_ID], parent)
    await cg.register_component(trigger, config)
    for action in config[CONF_SEQUENCE]:
        await automation.build_automation(
            trigger,
            [(UARTDirection, "direction"),
Beispiel #14
0
FILTER_KEYS = [
    CONF_INVERT, CONF_DELAYED_ON, CONF_DELAYED_OFF, CONF_LAMBDA, CONF_HEARTBEAT
]

FILTERS_SCHEMA = cv.ensure_list(
    {
        vol.Optional(CONF_INVERT):
        None,
        vol.Optional(CONF_DELAYED_ON):
        cv.positive_time_period_milliseconds,
        vol.Optional(CONF_DELAYED_OFF):
        cv.positive_time_period_milliseconds,
        vol.Optional(CONF_LAMBDA):
        cv.lambda_,
        vol.Optional(CONF_HEARTBEAT):
        cv.invalid("The heartbeat filter has been removed in 1.11.0"),
    }, cv.has_exactly_one_key(*FILTER_KEYS))

MULTI_CLICK_TIMING_SCHEMA = vol.Schema({
    vol.Optional(CONF_STATE):
    cv.boolean,
    vol.Optional(CONF_MIN_LENGTH):
    cv.positive_time_period_milliseconds,
    vol.Optional(CONF_MAX_LENGTH):
    cv.positive_time_period_milliseconds,
})


def parse_multi_click_timing_str(value):
    if not isinstance(value, string_types):
        return value
Beispiel #15
0
SENSOR_SCHEMA = cv.ENTITY_BASE_SCHEMA.extend(cv.MQTT_COMPONENT_SCHEMA).extend({
    cv.OnlyWith(CONF_MQTT_ID, "mqtt"):
    cv.declare_id(mqtt.MQTTSensorComponent),
    cv.GenerateID():
    cv.declare_id(Sensor),
    cv.Optional(CONF_UNIT_OF_MEASUREMENT):
    validate_unit_of_measurement,
    cv.Optional(CONF_ACCURACY_DECIMALS):
    validate_accuracy_decimals,
    cv.Optional(CONF_DEVICE_CLASS):
    validate_device_class,
    cv.Optional(CONF_STATE_CLASS):
    validate_state_class,
    cv.Optional("last_reset_type"):
    cv.invalid(
        "last_reset_type has been removed since 2021.9.0. state_class: total_increasing should be used for total values."
    ),
    cv.Optional(CONF_FORCE_UPDATE, default=False):
    cv.boolean,
    cv.Optional(CONF_EXPIRE_AFTER):
    cv.All(
        cv.requires_component("mqtt"),
        cv.Any(None, cv.positive_time_period_milliseconds),
    ),
    cv.Optional(CONF_FILTERS):
    validate_filters,
    cv.Optional(CONF_ON_VALUE):
    automation.validate_automation({
        cv.GenerateID(CONF_TRIGGER_ID):
        cv.declare_id(SensorStateTrigger),
    }),
Beispiel #16
0
        raise cv.Invalid("Scan duration needs to be at least three times the scan interval to"
                         "cover all BLE channels.")

    return config


CONFIG_SCHEMA = cv.Schema({
    cv.GenerateID(): cv.declare_id(ESP32BLETracker),
    cv.Optional(CONF_SCAN_PARAMETERS, default={}): cv.All(cv.Schema({
        cv.Optional(CONF_DURATION, default='5min'): cv.positive_time_period_seconds,
        cv.Optional(CONF_INTERVAL, default='320ms'): cv.positive_time_period_milliseconds,
        cv.Optional(CONF_WINDOW, default='30ms'): cv.positive_time_period_milliseconds,
        cv.Optional(CONF_ACTIVE, default=True): cv.boolean,
    }), validate_scan_parameters),

    cv.Optional('scan_interval'): cv.invalid("This option has been removed in 1.14 (Reason: "
                                             "it never had an effect)"),
}).extend(cv.COMPONENT_SCHEMA)

ESP_BLE_DEVICE_SCHEMA = cv.Schema({
    cv.GenerateID(CONF_ESP32_BLE_ID): cv.use_id(ESP32BLETracker),
})


def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    yield cg.register_component(var, config)
    params = config[CONF_SCAN_PARAMETERS]
    cg.add(var.set_scan_duration(params[CONF_DURATION]))
    cg.add(var.set_scan_interval(int(params[CONF_INTERVAL].total_milliseconds / 0.625)))
    cg.add(var.set_scan_window(int(params[CONF_WINDOW].total_milliseconds / 0.625)))
    cg.add(var.set_scan_active(params[CONF_ACTIVE]))
Beispiel #17
0
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome import automation
from esphome.components import binary_sensor, rs485
from esphome.const import CONF_ID
from .. import rs485_ns
from ..const import CONF_COMMAND_ON, CONF_COMMAND_OFF

DEPENDENCIES = ['rs485']
RS485BinarySensor = rs485_ns.class_('RS485BinarySensor',
                                    binary_sensor.BinarySensor, cg.Component)

CONFIG_SCHEMA = binary_sensor.BINARY_SENSOR_SCHEMA.extend({
    cv.GenerateID():
    cv.declare_id(RS485BinarySensor),
}).extend(rs485.RS485_DEVICE_SCHEMA).extend({
    cv.Optional(CONF_COMMAND_ON):
    cv.invalid("RS485 Binary Sensor do not support command_on!"),
    cv.Optional(CONF_COMMAND_OFF):
    cv.invalid("RS485 Binary Sensor do not support command_off!")
}).extend(cv.COMPONENT_SCHEMA)


async def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    await cg.register_component(var, config)
    await binary_sensor.register_binary_sensor(var, config)
    await rs485.register_rs485_device(var, config)
Beispiel #18
0
)
from .. import speed_ns

SpeedFan = speed_ns.class_("SpeedFan", cg.Component)

CONFIG_SCHEMA = fan.FAN_SCHEMA.extend({
    cv.GenerateID(CONF_OUTPUT_ID):
    cv.declare_id(SpeedFan),
    cv.Required(CONF_OUTPUT):
    cv.use_id(output.FloatOutput),
    cv.Optional(CONF_OSCILLATION_OUTPUT):
    cv.use_id(output.BinaryOutput),
    cv.Optional(CONF_DIRECTION_OUTPUT):
    cv.use_id(output.BinaryOutput),
    cv.Optional(CONF_SPEED):
    cv.invalid("Configuring individual speeds is deprecated."),
    cv.Optional(CONF_SPEED_COUNT, default=100):
    cv.int_range(min=1),
}).extend(cv.COMPONENT_SCHEMA)


def to_code(config):
    output_ = yield cg.get_variable(config[CONF_OUTPUT])
    state = yield fan.create_fan_state(config)
    var = cg.new_Pvariable(config[CONF_OUTPUT_ID], state, output_,
                           config[CONF_SPEED_COUNT])
    yield cg.register_component(var, config)

    if CONF_OSCILLATION_OUTPUT in config:
        oscillation_output = yield cg.get_variable(
            config[CONF_OSCILLATION_OUTPUT])
Beispiel #19
0
    cv.All(cv.only_on_esp32, pins.internal_gpio_input_pin_schema,
           validate_pin_number),
    cv.Optional(CONF_WAKEUP_PIN_MODE):
    cv.All(cv.only_on_esp32, cv.enum(WAKEUP_PIN_MODES), upper=True),
    cv.Optional(CONF_ESP32_EXT1_WAKEUP):
    cv.All(
        cv.only_on_esp32,
        cv.Schema({
            cv.Required(CONF_PINS):
            cv.ensure_list(pins.shorthand_input_pin, validate_pin_number),
            cv.Required(CONF_MODE):
            cv.enum(EXT1_WAKEUP_MODES, upper=True),
        })),
    cv.Optional(CONF_RUN_CYCLES):
    cv.invalid("The run_cycles option has been removed in 1.11.0 as "
               "it was essentially the same as a run_duration of 0s."
               "Please use run_duration now.")
}).extend(cv.COMPONENT_SCHEMA)


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

    if CONF_SLEEP_DURATION in config:
        cg.add(var.set_sleep_duration(config[CONF_SLEEP_DURATION]))
    if CONF_WAKEUP_PIN in config:
        pin = yield cg.gpio_pin_expression(config[CONF_WAKEUP_PIN])
        cg.add(var.set_wakeup_pin(pin))
    if CONF_WAKEUP_PIN_MODE in config:
        cg.add(var.set_wakeup_pin_mode(config[CONF_WAKEUP_PIN_MODE]))
Beispiel #20
0
    return config


CONFIG_SCHEMA = vol.All(cv.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'): cv.domain_name,
    vol.Optional(CONF_USE_ADDRESS): cv.string_strict,

    vol.Optional('hostname'): cv.invalid("The hostname option has been removed in 1.11.0"),
}), validate)


def to_code(config):
    rhs = App.init_ethernet()
    eth = Pvariable(config[CONF_ID], rhs)

    add(eth.set_phy_addr(config[CONF_PHY_ADDR]))
    add(eth.set_mdc_pin(config[CONF_MDC_PIN]))
    add(eth.set_mdio_pin(config[CONF_MDIO_PIN]))
    add(eth.set_type(ETHERNET_TYPES[config[CONF_TYPE]]))
    add(eth.set_clk_mode(CLK_MODES[config[CONF_CLK_MODE]]))
    add(eth.set_use_address(config[CONF_USE_ADDRESS]))

    if CONF_POWER_PIN in config:
Beispiel #21
0
BINARY_SENSOR_REGISTRY = Registry(
    binary_sensor.BINARY_SENSOR_SCHEMA.extend(
        {
            cv.GenerateID(CONF_RECEIVER_ID): cv.use_id(RemoteReceiverBase),
        }
    )
)
validate_binary_sensor = cv.validate_registry_entry(
    "remote receiver", BINARY_SENSOR_REGISTRY
)
TRIGGER_REGISTRY = SimpleRegistry()
DUMPER_REGISTRY = Registry(
    {
        cv.Optional(CONF_RECEIVER_ID): cv.invalid(
            "This has been removed in ESPHome 1.20.0 and the dumper attaches directly to the parent receiver."
        ),
    }
)


def validate_dumpers(value):
    if isinstance(value, str) and value.lower() == "all":
        return validate_dumpers(list(DUMPER_REGISTRY.keys()))
    return cv.validate_registry("dumper", DUMPER_REGISTRY)(value)


def validate_triggers(base_schema):
    assert isinstance(base_schema, cv.Schema)

    @jschema_extractor("triggers")
Beispiel #22
0
    CONF_OUTPUT_SOURCE_PRIORITY_UTILITY: ("POP00", None),
    CONF_OUTPUT_SOURCE_PRIORITY_SOLAR: ("POP01", None),
    CONF_OUTPUT_SOURCE_PRIORITY_BATTERY: ("POP02", None),
    CONF_INPUT_VOLTAGE_RANGE: ("PGR01", "PGR00"),
    CONF_PV_OK_CONDITION_FOR_PARALLEL: ("PPVOKC1", "PPVOKC0"),
    CONF_PV_POWER_BALANCE: ("PSPB1", "PSPB0"),
}

PipsolarSwitch = pipsolar_ns.class_("PipsolarSwitch", switch.Switch,
                                    cg.Component)

PIPSWITCH_SCHEMA = switch.SWITCH_SCHEMA.extend({
    cv.GenerateID():
    cv.declare_id(PipsolarSwitch),
    cv.Optional(CONF_INVERTED):
    cv.invalid("Pipsolar switches do not support inverted mode!"),
    cv.Optional(CONF_ICON, default=ICON_POWER):
    switch.icon,
}).extend(cv.COMPONENT_SCHEMA)

CONFIG_SCHEMA = PIPSOLAR_COMPONENT_SCHEMA.extend(
    {cv.Optional(type): PIPSWITCH_SCHEMA
     for type in TYPES})


async def to_code(config):
    paren = await cg.get_variable(config[CONF_PIPSOLAR_ID])

    for type, (on, off) in TYPES.items():
        if type in config:
            conf = config[type]
Beispiel #23
0
    automation.validate_automation({
        cv.GenerateID(CONF_TRIGGER_ID):
        cv.declare_id(ShutdownTrigger),
    }),
    cv.Optional(CONF_ON_LOOP):
    automation.validate_automation({
        cv.GenerateID(CONF_TRIGGER_ID):
        cv.declare_id(LoopTrigger),
    }),
    cv.Optional(CONF_INCLUDES, default=[]):
    cv.ensure_list(valid_include),
    cv.Optional(CONF_LIBRARIES, default=[]):
    cv.ensure_list(cv.string_strict),
    cv.Optional('esphome_core_version'):
    cv.invalid("The esphome_core_version option has been "
               "removed in 1.13 - the esphome core source "
               "files are now bundled with ESPHome.")
})

PRELOAD_CONFIG_SCHEMA = cv.Schema(
    {
        cv.Required(CONF_NAME): cv.valid_name,
        cv.Required(CONF_PLATFORM): validate_platform,
    },
    extra=cv.ALLOW_EXTRA)

PRELOAD_CONFIG_SCHEMA2 = PRELOAD_CONFIG_SCHEMA.extend({
    cv.Required(CONF_BOARD):
    validate_board,
    cv.Optional(CONF_BUILD_PATH, default=default_build_path):
    cv.string,
Beispiel #24
0
        unit_of_measurement=UNIT_LUX,
        accuracy_decimals=1,
        device_class=DEVICE_CLASS_ILLUMINANCE,
        state_class=STATE_CLASS_MEASUREMENT,
    )
    .extend(
        {
            cv.GenerateID(): cv.declare_id(BH1750Sensor),
            cv.Optional(CONF_RESOLUTION, default=0.5): cv.enum(
                BH1750_RESOLUTIONS, float=True
            ),
            cv.Optional(CONF_MEASUREMENT_DURATION, default=69): cv.int_range(
                min=31, max=254
            ),
            cv.Optional(CONF_MEASUREMENT_TIME): cv.invalid(
                "The 'measurement_time' option has been replaced with 'measurement_duration' in 1.18.0"
            ),
        }
    )
    .extend(cv.polling_component_schema("60s"))
    .extend(i2c.i2c_device_schema(0x23))
)


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

    cg.add(var.set_resolution(config[CONF_RESOLUTION]))
Beispiel #25
0
        ICON_ARROW_EXPAND_VERTICAL,
        2,
        DEVICE_CLASS_EMPTY,
        STATE_CLASS_MEASUREMENT,
    )
    .extend(
        {
            cv.GenerateID(): cv.declare_id(UltrasonicSensorComponent),
            cv.Required(CONF_TRIGGER_PIN): pins.gpio_output_pin_schema,
            cv.Required(CONF_ECHO_PIN): pins.internal_gpio_input_pin_schema,
            cv.Optional(CONF_TIMEOUT, default="2m"): cv.distance,
            cv.Optional(
                CONF_PULSE_TIME, default="10us"
            ): cv.positive_time_period_microseconds,
            cv.Optional("timeout_meter"): cv.invalid(
                "The timeout_meter option has been renamed " "to 'timeout' in 1.12."
            ),
            cv.Optional("timeout_time"): cv.invalid(
                "The timeout_time option has been removed. Please "
                "use 'timeout' in 1.12."
            ),
        }
    )
    .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 sensor.register_sensor(var, config)
Beispiel #26
0
        cv.Optional(CONF_MAC_ADDRESS):
        cv.mac_address,
        cv.Required(CONF_SERVICE_UUID):
        bt_uuid,
    }),
    cv.Optional(CONF_ON_BLE_MANUFACTURER_DATA_ADVERTISE):
    automation.validate_automation({
        cv.GenerateID(CONF_TRIGGER_ID):
        cv.declare_id(BLEManufacturerDataAdvertiseTrigger),
        cv.Optional(CONF_MAC_ADDRESS):
        cv.mac_address,
        cv.Required(CONF_MANUFACTURER_ID):
        bt_uuid,
    }),
    cv.Optional('scan_interval'):
    cv.invalid("This option has been removed in 1.14 (Reason: "
               "it never had an effect)"),
}).extend(cv.COMPONENT_SCHEMA)

ESP_BLE_DEVICE_SCHEMA = cv.Schema({
    cv.GenerateID(CONF_ESP32_BLE_ID):
    cv.use_id(ESP32BLETracker),
})


def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    yield cg.register_component(var, config)
    params = config[CONF_SCAN_PARAMETERS]
    cg.add(var.set_scan_duration(params[CONF_DURATION]))
    cg.add(
        var.set_scan_interval(
Beispiel #27
0
    vol.Optional(CONF_ON_SHUTDOWN):
    automation.validate_automation({
        cv.GenerateID(CONF_TRIGGER_ID):
        cv.declare_variable_id(ShutdownTrigger),
    }),
    vol.Optional(CONF_ON_LOOP):
    automation.validate_automation({
        cv.GenerateID(CONF_TRIGGER_ID):
        cv.declare_variable_id(LoopTrigger),
    }),
    vol.Optional(CONF_INCLUDES):
    cv.ensure_list(cv.file_),
    vol.Optional(CONF_LIBRARIES):
    cv.ensure_list(cv.string_strict),
    vol.Optional('esphomelib_version'):
    cv.invalid("The esphomelib_version has been renamed to "
               "esphome_core_version in 1.11.0"),
})


def preload_core_config(config):
    if 'esphomeyaml' in config:
        _LOGGER.warning(
            "The esphomeyaml section has been renamed to esphome in 1.11.0. "
            "Please replace 'esphomeyaml:' in your configuration with 'esphome:'."
        )
        config[CONF_ESPHOME] = config.pop('esphomeyaml')
    if CONF_ESPHOME not in config:
        raise EsphomeError(u"No esphome section in config")
    core_conf = config[CONF_ESPHOME]
    if CONF_PLATFORM not in core_conf:
        raise EsphomeError("esphome.platform not specified.")
Beispiel #28
0
DEPENDENCIES = ["i2c"]

tca9548a_ns = cg.esphome_ns.namespace("tca9548a")
TCA9548AComponent = tca9548a_ns.class_("TCA9548AComponent", cg.Component,
                                       i2c.I2CDevice)
TCA9548AChannel = tca9548a_ns.class_("TCA9548AChannel", i2c.I2CBus)

MULTI_CONF = True

CONF_BUS_ID = "bus_id"
CONFIG_SCHEMA = (cv.Schema({
    cv.GenerateID():
    cv.declare_id(TCA9548AComponent),
    cv.Optional(CONF_SCAN):
    cv.invalid("This option has been removed"),
    cv.Optional(CONF_CHANNELS, default=[]):
    cv.ensure_list({
        cv.Required(CONF_BUS_ID): cv.declare_id(TCA9548AChannel),
        cv.Required(CONF_CHANNEL): cv.int_range(min=0, max=7),
    }),
}).extend(i2c.i2c_device_schema(0x70)).extend(cv.COMPONENT_SCHEMA))


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)

    for conf in config[CONF_CHANNELS]:
        chan = cg.new_Pvariable(conf[CONF_BUS_ID])
Beispiel #29
0
I2CDevice = pins.I2CDevice

CONFIG_SCHEMA = cv.Schema({
    cv.GenerateID():
    cv.declare_variable_id(I2CComponent),
    vol.Optional(CONF_SDA, default='SDA'):
    pins.input_pin,
    vol.Optional(CONF_SCL, default='SCL'):
    pins.input_pin,
    vol.Optional(CONF_FREQUENCY):
    vol.All(cv.frequency, vol.Range(min=0, min_included=False)),
    vol.Optional(CONF_SCAN, default=True):
    cv.boolean,
    vol.Optional(CONF_RECEIVE_TIMEOUT):
    cv.invalid("The receive_timeout option has been removed "
               "because timeouts are already handled by the "
               "low-level i2c interface.")
}).extend(cv.COMPONENT_SCHEMA.schema)


def to_code(config):
    rhs = App.init_i2c(config[CONF_SDA], config[CONF_SCL],
                       config.get(CONF_SCAN))
    i2c = Pvariable(config[CONF_ID], rhs)
    if CONF_FREQUENCY in config:
        add(i2c.set_frequency(config[CONF_FREQUENCY]))

    setup_component(i2c, config)


BUILD_FLAGS = '-DUSE_I2C'
from esphome.components import switch, uart
from esphome.const import CONF_DATA, CONF_ID, CONF_INVERTED
from esphome.core import HexInt
from .. import uart_ns, validate_raw_data

DEPENDENCIES = ['uart']

UARTSwitch = uart_ns.class_('UARTSwitch', switch.Switch, uart.UARTDevice,
                            cg.Component)

CONFIG_SCHEMA = switch.SWITCH_SCHEMA.extend({
    cv.GenerateID():
    cv.declare_id(UARTSwitch),
    cv.Required(CONF_DATA):
    validate_raw_data,
    cv.Optional(CONF_INVERTED):
    cv.invalid("UART switches do not support inverted mode!"),
}).extend(uart.UART_DEVICE_SCHEMA).extend(cv.COMPONENT_SCHEMA)


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

    data = config[CONF_DATA]
    if isinstance(data, bytes):
        data = [HexInt(x) for x in data]
    cg.add(var.set_data(data))