Beispiel #1
0
import voluptuous as vol

import esphomeyaml.config_validation as cv
from esphomeyaml.components import sensor
from esphomeyaml.components.esp32_ble_tracker import CONF_ESP32_BLE_ID, ESP32BLETracker, \
    make_address_array
from esphomeyaml.const import CONF_MAC_ADDRESS, CONF_NAME
from esphomeyaml.helpers import get_variable, esphomelib_ns

DEPENDENCIES = ['esp32_ble_tracker']

ESP32BLERSSISensor = esphomelib_ns.class_('ESP32BLERSSISensor', sensor.Sensor)

PLATFORM_SCHEMA = cv.nameable(
    sensor.SENSOR_PLATFORM_SCHEMA.extend({
        cv.GenerateID():
        cv.declare_variable_id(ESP32BLERSSISensor),
        vol.Required(CONF_MAC_ADDRESS):
        cv.mac_address,
        cv.GenerateID(CONF_ESP32_BLE_ID):
        cv.use_variable_id(ESP32BLETracker)
    }))


def to_code(config):
    for hub in get_variable(config[CONF_ESP32_BLE_ID]):
        yield
    rhs = hub.make_rssi_sensor(config[CONF_NAME],
                               make_address_array(config[CONF_MAC_ADDRESS]))
    sensor.register_sensor(rhs, config)
Beispiel #2
0
import voluptuous as vol

from esphomeyaml import automation
from esphomeyaml.automation import ACTION_REGISTRY, maybe_simple_id
import esphomeyaml.config_validation as cv
from esphomeyaml.const import CONF_ID
from esphomeyaml.helpers import NoArg, Pvariable, TemplateArguments, esphomelib_ns, get_variable, \
    Trigger, Action

Script = esphomelib_ns.class_('Script', Trigger.template(NoArg))
ScriptExecuteAction = esphomelib_ns.class_('ScriptExecuteAction', Action)

CONFIG_SCHEMA = automation.validate_automation({
    vol.Required(CONF_ID):
    cv.declare_variable_id(Script),
})


def to_code(config):
    for conf in config:
        trigger = Pvariable(conf[CONF_ID], Script.new())
        automation.build_automation(trigger, NoArg, conf)


CONF_SCRIPT_EXECUTE = 'script.execute'
SCRIPT_EXECUTE_ACTION_SCHEMA = maybe_simple_id({
    vol.Required(CONF_ID):
    cv.use_variable_id(Script),
})

Beispiel #3
0
import voluptuous as vol

import esphomeyaml.config_validation as cv
from esphomeyaml import pins
from esphomeyaml.const import CONF_CLK_PIN, CONF_ID, CONF_MISO_PIN, CONF_MOSI_PIN
from esphomeyaml.helpers import App, Pvariable, esphomelib_ns, gpio_input_pin_expression, \
    gpio_output_pin_expression, add, setup_component, Component

SPIComponent = esphomelib_ns.class_('SPIComponent', Component)
SPIDevice = esphomelib_ns.class_('SPIDevice')

SPI_SCHEMA = vol.All(
    vol.Schema({
        cv.GenerateID(): cv.declare_variable_id(SPIComponent),
        vol.Required(CONF_CLK_PIN): pins.gpio_output_pin_schema,
        vol.Optional(CONF_MISO_PIN): pins.gpio_input_pin_schema,
        vol.Optional(CONF_MOSI_PIN): pins.gpio_output_pin_schema,
    }), cv.has_at_least_one_key(CONF_MISO_PIN, CONF_MOSI_PIN))

CONFIG_SCHEMA = vol.All(cv.ensure_list, [SPI_SCHEMA])


def to_code(config):
    for conf in config:
        for clk in gpio_output_pin_expression(conf[CONF_CLK_PIN]):
            yield
        rhs = App.init_spi(clk)
        spi = Pvariable(conf[CONF_ID], rhs)
        if CONF_MISO_PIN in conf:
            for miso in gpio_input_pin_expression(conf[CONF_MISO_PIN]):
                yield
Beispiel #4
0
import voluptuous as vol

import esphomeyaml.config_validation as cv
from esphomeyaml import pins
from esphomeyaml.const import CONF_BAUD_RATE, CONF_ID, CONF_RX_PIN, CONF_TX_PIN
from esphomeyaml.helpers import App, Pvariable, esphomelib_ns, setup_component, Component

UARTComponent = esphomelib_ns.class_('UARTComponent', Component)
UARTDevice = esphomelib_ns.class_('UARTDevice')

UART_SCHEMA = vol.All(
    vol.Schema({
        cv.GenerateID(): cv.declare_variable_id(UARTComponent),
        vol.Optional(CONF_TX_PIN): pins.output_pin,
        vol.Optional(CONF_RX_PIN): pins.input_pin,
        vol.Required(CONF_BAUD_RATE): cv.positive_int,
    }).extend(cv.COMPONENT_SCHEMA.schema),
    cv.has_at_least_one_key(CONF_TX_PIN, CONF_RX_PIN))

CONFIG_SCHEMA = vol.All(cv.ensure_list, [UART_SCHEMA])


def to_code(config):
    for conf in config:
        tx = conf.get(CONF_TX_PIN, -1)
        rx = conf.get(CONF_RX_PIN, -1)
        rhs = App.init_uart(tx, rx, conf[CONF_BAUD_RATE])
        var = Pvariable(conf[CONF_ID], rhs)

        setup_component(var, conf)
Beispiel #5
0
import voluptuous as vol

import esphomeyaml.config_validation as cv
from esphomeyaml import pins
from esphomeyaml.const import CONF_FREQUENCY, CONF_SCL, CONF_SDA, CONF_SCAN, CONF_ID, \
    CONF_RECEIVE_TIMEOUT
from esphomeyaml.helpers import App, add, Pvariable, esphomelib_ns, setup_component, Component

I2CComponent = esphomelib_ns.class_('I2CComponent', Component)
I2CDevice = pins.I2CDevice

CONFIG_SCHEMA = vol.Schema({
    cv.GenerateID():
    cv.declare_variable_id(I2CComponent),
    vol.Required(CONF_SDA, default='SDA'):
    pins.input_output_pin,
    vol.Required(CONF_SCL, default='SCL'):
    pins.input_output_pin,
    vol.Optional(CONF_FREQUENCY):
    vol.All(cv.frequency, vol.Range(min=0, min_included=False)),
    vol.Optional(CONF_SCAN):
    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],
Beispiel #6
0
import voluptuous as vol

from esphomeyaml import config_validation as cv
from esphomeyaml.const import CONF_ID, CONF_SCAN_INTERVAL, CONF_TYPE, CONF_UUID, ESP_PLATFORM_ESP32
from esphomeyaml.helpers import App, ArrayInitializer, Component, Pvariable, RawExpression, add, \
    esphomelib_ns, setup_component

ESP_PLATFORMS = [ESP_PLATFORM_ESP32]

ESP32BLEBeacon = esphomelib_ns.class_('ESP32BLEBeacon', Component)

CONF_MAJOR = 'major'
CONF_MINOR = 'minor'

CONFIG_SCHEMA = vol.Schema({
    cv.GenerateID(): cv.declare_variable_id(ESP32BLEBeacon),
    vol.Required(CONF_TYPE): vol.All(vol.Upper, cv.one_of('IBEACON')),
    vol.Required(CONF_UUID): cv.uuid,
    vol.Optional(CONF_MAJOR): cv.uint16_t,
    vol.Optional(CONF_MINOR): cv.uint16_t,
    vol.Optional(CONF_SCAN_INTERVAL): cv.positive_time_period_milliseconds,
}).extend(cv.COMPONENT_SCHEMA.schema)


def to_code(config):
    uuid = config[CONF_UUID].hex
    uuid_arr = [RawExpression('0x{}'.format(uuid[i:i + 2])) for i in range(0, len(uuid), 2)]
    rhs = App.make_esp32_ble_beacon(ArrayInitializer(*uuid_arr, multiline=False))
    ble = Pvariable(config[CONF_ID], rhs)
    if CONF_MAJOR in config:
        add(ble.set_major(config[CONF_MAJOR]))
import voluptuous as vol

from esphomeyaml.components import binary_sensor
from esphomeyaml.components.esp32_ble_tracker import CONF_ESP32_BLE_ID, ESP32BLETracker, \
    make_address_array
import esphomeyaml.config_validation as cv
from esphomeyaml.const import CONF_MAC_ADDRESS, CONF_NAME
from esphomeyaml.helpers import esphomelib_ns, get_variable

DEPENDENCIES = ['esp32_ble_tracker']
ESP32BLEPresenceDevice = esphomelib_ns.class_('ESP32BLEPresenceDevice',
                                              binary_sensor.BinarySensor)

PLATFORM_SCHEMA = cv.nameable(
    binary_sensor.BINARY_SENSOR_PLATFORM_SCHEMA.extend({
        cv.GenerateID():
        cv.declare_variable_id(ESP32BLEPresenceDevice),
        vol.Required(CONF_MAC_ADDRESS):
        cv.mac_address,
        cv.GenerateID(CONF_ESP32_BLE_ID):
        cv.use_variable_id(ESP32BLETracker)
    }))


def to_code(config):
    hub = None
    for hub in get_variable(config[CONF_ESP32_BLE_ID]):
        yield
    rhs = hub.make_presence_sensor(
        config[CONF_NAME], make_address_array(config[CONF_MAC_ADDRESS]))
    binary_sensor.register_binary_sensor(rhs, config)
Beispiel #8
0
                u"Cannot have two actions in one item. Key '{}' overrides '{}'! "
                u"Did you forget to indent the action?"
                u"".format(key, key2))
        validator = ACTION_REGISTRY[key][0]
        value[i] = {
            CONF_ACTION_ID:
            cv.declare_variable_id(Action)(item[CONF_ACTION_ID]),
            key: validator(item[key])
        }
    return value


ACTION_REGISTRY = ServiceRegistry()

# pylint: disable=invalid-name
DelayAction = esphomelib_ns.class_('DelayAction', Action, Component)
LambdaAction = esphomelib_ns.class_('LambdaAction', Action)
IfAction = esphomelib_ns.class_('IfAction', Action)
UpdateComponentAction = esphomelib_ns.class_('UpdateComponentAction', Action)
Automation = esphomelib_ns.class_('Automation')

Condition = esphomelib_ns.class_('Condition')
AndCondition = esphomelib_ns.class_('AndCondition', Condition)
OrCondition = esphomelib_ns.class_('OrCondition', Condition)
RangeCondition = esphomelib_ns.class_('RangeCondition', Condition)
LambdaCondition = esphomelib_ns.class_('LambdaCondition', Condition)

CONDITIONS_SCHEMA = vol.All(cv.ensure_list, [
    cv.templatable({
        cv.GenerateID(CONF_CONDITION_ID):
        cv.declare_variable_id(Condition),
Beispiel #9
0
    vol.Optional(CONF_MANUAL_IP): STA_MANUAL_IP_SCHEMA,
})


def validate(config):
    if CONF_PASSWORD in config and CONF_SSID not in config:
        raise vol.Invalid("Cannot have WiFi password without SSID!")
    if CONF_SSID not in config and CONF_AP not in config:
        raise vol.Invalid("Please specify at least an SSID or an Access Point "
                          "to create.")
    return config


IPAddress = global_ns.class_('IPAddress')
ManualIP = esphomelib_ns.struct('ManualIP')
WiFiComponent = esphomelib_ns.class_('WiFiComponent', Component)
WiFiAp = esphomelib_ns.struct('WiFiAp')

WiFiPowerSaveMode = esphomelib_ns.enum('WiFiPowerSaveMode')
WIFI_POWER_SAVE_MODES = {
    'NONE': WiFiPowerSaveMode.WIFI_POWER_SAVE_NONE,
    'LIGHT': WiFiPowerSaveMode.WIFI_POWER_SAVE_LIGHT,
    'HIGH': WiFiPowerSaveMode.WIFI_POWER_SAVE_HIGH,
}

CONFIG_SCHEMA = vol.All(vol.Schema({
    cv.GenerateID(): cv.declare_variable_id(WiFiComponent),
    vol.Optional(CONF_SSID): cv.ssid,
    vol.Optional(CONF_PASSWORD): validate_password,
    vol.Optional(CONF_MANUAL_IP): STA_MANUAL_IP_SCHEMA,
    vol.Optional(CONF_AP): WIFI_NETWORK_AP,
import voluptuous as vol

from esphomeyaml import config_validation as cv
from esphomeyaml.components import sensor
from esphomeyaml.const import CONF_ID, CONF_SCAN_INTERVAL, ESP_PLATFORM_ESP32
from esphomeyaml.core import HexInt
from esphomeyaml.helpers import App, Pvariable, add, esphomelib_ns, ArrayInitializer, \
    setup_component, Component

ESP_PLATFORMS = [ESP_PLATFORM_ESP32]

CONF_ESP32_BLE_ID = 'esp32_ble_id'
ESP32BLETracker = esphomelib_ns.class_('ESP32BLETracker', Component)
XiaomiSensor = esphomelib_ns.class_('XiaomiSensor', sensor.Sensor)
XiaomiDevice = esphomelib_ns.class_('XiaomiDevice')
XIAOMI_SENSOR_SCHEMA = sensor.SENSOR_SCHEMA.extend({
    cv.GenerateID(): cv.declare_variable_id(XiaomiSensor)
})

CONFIG_SCHEMA = vol.Schema({
    cv.GenerateID(): cv.declare_variable_id(ESP32BLETracker),
    vol.Optional(CONF_SCAN_INTERVAL): cv.positive_time_period_milliseconds,
}).extend(cv.COMPONENT_SCHEMA.schema)


def make_address_array(address):
    addr = [HexInt(i) for i in address.parts]
    return ArrayInitializer(*addr, multiline=False)


def to_code(config):
Beispiel #11
0
import logging

import voluptuous as vol

from esphomeyaml import core
import esphomeyaml.config_validation as cv
from esphomeyaml.const import CONF_ID, CONF_OTA, CONF_PASSWORD, CONF_PORT, CONF_SAFE_MODE, \
    ESP_PLATFORM_ESP32, ESP_PLATFORM_ESP8266
from esphomeyaml.core import ESPHomeYAMLError
from esphomeyaml.helpers import App, Pvariable, add, esphomelib_ns, Component

_LOGGER = logging.getLogger(__name__)

OTAComponent = esphomelib_ns.class_('OTAComponent', Component)

CONFIG_SCHEMA = vol.Schema({
    cv.GenerateID():
    cv.declare_variable_id(OTAComponent),
    vol.Optional(CONF_SAFE_MODE, default=True):
    cv.boolean,
    vol.Optional(CONF_PORT):
    cv.port,
    vol.Optional(CONF_PASSWORD):
    cv.string,
})


def to_code(config):
    rhs = App.init_ota()
    ota = Pvariable(config[CONF_ID], rhs)
    if CONF_PASSWORD in config:
Beispiel #12
0
# pylint: disable=invalid-name
is_log_level = vol.All(vol.Upper, cv.one_of(*LOG_LEVELS))


def validate_local_no_higher_than_global(value):
    global_level = value.get(CONF_LEVEL, 'DEBUG')
    for tag, level in value.get(CONF_LOGS, {}).iteritems():
        if LOG_LEVEL_SEVERITY.index(level) > LOG_LEVEL_SEVERITY.index(
                global_level):
            raise ESPHomeYAMLError(
                u"The local log level {} for {} must be less severe than the "
                u"global log level {}.".format(level, tag, global_level))
    return value


LogComponent = esphomelib_ns.class_('LogComponent', Component)

CONFIG_SCHEMA = vol.All(
    vol.Schema({
        cv.GenerateID(): cv.declare_variable_id(LogComponent),
        vol.Optional(CONF_BAUD_RATE, default=115200): cv.positive_int,
        vol.Optional(CONF_TX_BUFFER_SIZE): cv.validate_bytes,
        vol.Optional(CONF_LEVEL): is_log_level,
        vol.Optional(CONF_LOGS): vol.Schema({
            cv.string: is_log_level,
        })
    }), validate_local_no_higher_than_global)


def to_code(config):
    rhs = App.init_log(config.get(CONF_BAUD_RATE))
Beispiel #13
0
import voluptuous as vol

import esphomeyaml.config_validation as cv
from esphomeyaml import pins
from esphomeyaml.const import CONF_ENABLE_TIME, CONF_ID, CONF_KEEP_ON_TIME, CONF_PIN
from esphomeyaml.helpers import App, Pvariable, add, esphomelib_ns, gpio_output_pin_expression, \
    setup_component, Component

PowerSupplyComponent = esphomelib_ns.class_('PowerSupplyComponent', Component)

POWER_SUPPLY_SCHEMA = vol.Schema({
    vol.Required(CONF_ID):
    cv.declare_variable_id(PowerSupplyComponent),
    vol.Required(CONF_PIN):
    pins.gpio_output_pin_schema,
    vol.Optional(CONF_ENABLE_TIME):
    cv.positive_time_period_milliseconds,
    vol.Optional(CONF_KEEP_ON_TIME):
    cv.positive_time_period_milliseconds,
}).extend(cv.COMPONENT_SCHEMA.schema)

CONFIG_SCHEMA = vol.All(cv.ensure_list, [POWER_SUPPLY_SCHEMA])


def to_code(config):
    for conf in config:
        for pin in gpio_output_pin_expression(conf[CONF_PIN]):
            yield

        rhs = App.make_power_supply(pin)
        psu = Pvariable(conf[CONF_ID], rhs)
Beispiel #14
0
from esphomeyaml.const import CONF_ID, CONF_NUMBER, CONF_RUN_CYCLES, CONF_RUN_DURATION, \
    CONF_SLEEP_DURATION, CONF_WAKEUP_PIN, CONF_MODE, CONF_PINS
from esphomeyaml.helpers import Action, App, Component, Pvariable, TemplateArguments, add, \
    esphomelib_ns, get_variable, gpio_input_pin_expression, setup_component, global_ns, \
    StructInitializer


def validate_pin_number(value):
    valid_pins = [0, 2, 4, 12, 13, 14, 15, 25, 26, 27, 32, 39]
    if value[CONF_NUMBER] not in valid_pins:
        raise vol.Invalid(u"Only pins {} support wakeup"
                          u"".format(', '.join(str(x) for x in valid_pins)))
    return value


DeepSleepComponent = esphomelib_ns.class_('DeepSleepComponent', Component)
EnterDeepSleepAction = esphomelib_ns.class_('EnterDeepSleepAction', Action)
PreventDeepSleepAction = esphomelib_ns.class_('PreventDeepSleepAction', Action)

WakeupPinMode = esphomelib_ns.enum('WakeupPinMode')
WAKEUP_PIN_MODES = {
    'IGNORE': WakeupPinMode.WAKEUP_PIN_MODE_IGNORE,
    'KEEP_AWAKE': WakeupPinMode.WAKEUP_PIN_MODE_KEEP_AWAKE,
    'INVERT_WAKEUP': WakeupPinMode.WAKEUP_PIN_MODE_INVERT_WAKEUP,
}

esp_sleep_ext1_wakeup_mode_t = global_ns.enum('esp_sleep_ext1_wakeup_mode_t')
Ext1Wakeup = esphomelib_ns.struct('Ext1Wakeup')
EXT1_WAKEUP_MODES = {
    'ALL_LOW': esp_sleep_ext1_wakeup_mode_t.ESP_EXT1_WAKEUP_ALL_LOW,
    'ANY_HIGH': esp_sleep_ext1_wakeup_mode_t.ESP_EXT1_WAKEUP_ANY_HIGH,
Beispiel #15
0
import voluptuous as vol

from esphomeyaml import config_validation as cv
from esphomeyaml.const import CONF_ID, CONF_INITIAL_VALUE, CONF_RESTORE_VALUE, CONF_TYPE
from esphomeyaml.helpers import App, Component, Pvariable, RawExpression, TemplateArguments, add, \
    esphomelib_ns, setup_component

GlobalVariableComponent = esphomelib_ns.class_('GlobalVariableComponent',
                                               Component)

GLOBAL_VAR_SCHEMA = vol.Schema({
    vol.Required(CONF_ID):
    cv.declare_variable_id(GlobalVariableComponent),
    vol.Required(CONF_TYPE):
    cv.string_strict,
    vol.Optional(CONF_INITIAL_VALUE):
    cv.string_strict,
    vol.Optional(CONF_RESTORE_VALUE):
    cv.boolean,
}).extend(cv.COMPONENT_SCHEMA.schema)

CONFIG_SCHEMA = vol.All(cv.ensure_list, [GLOBAL_VAR_SCHEMA])


def to_code(config):
    for conf in config:
        type_ = RawExpression(conf[CONF_TYPE])
        template_args = TemplateArguments(type_)
        res_type = GlobalVariableComponent.template(template_args)
        initial_value = None
        if CONF_INITIAL_VALUE in conf:
Beispiel #16
0
import voluptuous as vol

from esphomeyaml import core
import esphomeyaml.config_validation as cv
from esphomeyaml.const import CONF_CSS_URL, CONF_ID, CONF_JS_URL, CONF_PORT, ESP_PLATFORM_ESP32
from esphomeyaml.helpers import App, Component, Pvariable, StoringController, add, esphomelib_ns, \
    setup_component

WebServer = esphomelib_ns.class_('WebServer', Component, StoringController)

CONFIG_SCHEMA = vol.Schema({
    cv.GenerateID(): cv.declare_variable_id(WebServer),
    vol.Optional(CONF_PORT): cv.port,
    vol.Optional(CONF_CSS_URL): cv.string,
    vol.Optional(CONF_JS_URL): cv.string,
}).extend(cv.COMPONENT_SCHEMA.schema)


def to_code(config):
    rhs = App.init_web_server(config.get(CONF_PORT))
    web_server = Pvariable(config[CONF_ID], rhs)
    if CONF_CSS_URL in config:
        add(web_server.set_css_url(config[CONF_CSS_URL]))
    if CONF_JS_URL in config:
        add(web_server.set_js_url(config[CONF_JS_URL]))

    setup_component(web_server, config)


BUILD_FLAGS = '-DUSE_WEB_SERVER'
Beispiel #17
0
import voluptuous as vol

from esphomeyaml import config_validation as cv, pins
from esphomeyaml.const import CONF_ID, CONF_PIN
from esphomeyaml.helpers import App, Pvariable, esphomelib_ns, gpio_output_pin_expression, \
    setup_component, Component

StatusLEDComponent = esphomelib_ns.class_('StatusLEDComponent', Component)

CONFIG_SCHEMA = vol.Schema({
    cv.GenerateID():
    cv.declare_variable_id(StatusLEDComponent),
    vol.Optional(CONF_PIN):
    pins.gpio_output_pin_schema,
}).extend(cv.COMPONENT_SCHEMA.schema)


def to_code(config):
    for pin in gpio_output_pin_expression(config[CONF_PIN]):
        yield
    rhs = App.make_status_led(pin)
    var = Pvariable(config[CONF_ID], rhs)

    setup_component(var, config)


BUILD_FLAGS = '-DUSE_STATUS_LED'