Пример #1
0
    vol.Optional(CONF_INVERTED):
    cv.boolean,
})

BINARY_OUTPUT_PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
    BINARY_OUTPUT_SCHEMA.schema)

FLOAT_OUTPUT_SCHEMA = BINARY_OUTPUT_SCHEMA.extend({
    vol.Optional(CONF_MAX_POWER):
    cv.percentage,
})

FLOAT_OUTPUT_PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
    FLOAT_OUTPUT_SCHEMA.schema)

output_ns = esphomelib_ns.namespace('output')


def setup_output_platform_(obj, config, skip_power_supply=False):
    if CONF_INVERTED in config:
        add(obj.set_inverted(config[CONF_INVERTED]))
    if not skip_power_supply and CONF_POWER_SUPPLY in config:
        power_supply = None
        for power_supply in get_variable(config[CONF_POWER_SUPPLY]):
            yield
        add(obj.set_power_supply(power_supply))
    if CONF_MAX_POWER in config:
        add(obj.set_max_power(config[CONF_MAX_POWER]))


def setup_output_platform(obj, config, skip_power_supply=False):
Пример #2
0
    vol.All(cv.ensure_list, [automation.AUTOMATION_SCHEMA]),
    vol.Optional(CONF_ON_RAW_VALUE):
    vol.All(cv.ensure_list, [automation.AUTOMATION_SCHEMA]),
    vol.Optional(CONF_ON_VALUE_RANGE):
    vol.All(cv.ensure_list, [
        vol.All(
            automation.AUTOMATION_SCHEMA.extend(
                {
                    vol.Optional(CONF_ABOVE): vol.Coerce(float),
                    vol.Optional(CONF_BELOW): vol.Coerce(float),
                }), cv.has_at_least_one_key(CONF_ABOVE, CONF_BELOW))
    ]),
})

# pylint: disable=invalid-name
sensor_ns = esphomelib_ns.namespace('sensor')
Sensor = sensor_ns.Sensor
MQTTSensorComponent = sensor_ns.MQTTSensorComponent
OffsetFilter = sensor_ns.OffsetFilter
MultiplyFilter = sensor_ns.MultiplyFilter
FilterOutValueFilter = sensor_ns.FilterOutValueFilter
FilterOutNANFilter = sensor_ns.FilterOutNANFilter
SlidingWindowMovingAverageFilter = sensor_ns.SlidingWindowMovingAverageFilter
ExponentialMovingAverageFilter = sensor_ns.ExponentialMovingAverageFilter
LambdaFilter = sensor_ns.LambdaFilter
ThrottleFilter = sensor_ns.ThrottleFilter
DeltaFilter = sensor_ns.DeltaFilter
OrFilter = sensor_ns.OrFilter
HeartbeatFilter = sensor_ns.HeartbeatFilter
DebounceFilter = sensor_ns.DebounceFilter
UniqueFilter = sensor_ns.UniqueFilter
Пример #3
0
from esphomeyaml.helpers import Application, Pvariable, add, esphomelib_ns, setup_mqtt_component

PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({})

FAN_SCHEMA = cv.MQTT_COMMAND_COMPONENT_SCHEMA.extend({
    cv.GenerateID('fan'):
    cv.register_variable_id,
    cv.GenerateID('mqtt_fan', CONF_MQTT_ID):
    cv.register_variable_id,
    vol.Optional(CONF_OSCILLATION_STATE_TOPIC):
    cv.publish_topic,
    vol.Optional(CONF_OSCILLATION_COMMAND_TOPIC):
    cv.subscribe_topic,
})

fan_ns = esphomelib_ns.namespace('fan')
FanState = fan_ns.FanState
MQTTFanComponent = fan_ns.MQTTFanComponent
MakeFan = Application.MakeFan
TurnOnAction = fan_ns.TurnOnAction
TurnOffAction = fan_ns.TurnOffAction
ToggleAction = fan_ns.ToggleAction
FanSpeed = fan_ns.FanSpeed
FAN_SPEED_OFF = fan_ns.FAN_SPEED_OFF
FAN_SPEED_LOW = fan_ns.FAN_SPEED_LOW
FAN_SPEED_MEDIUM = fan_ns.FAN_SPEED_MEDIUM
FAN_SPEED_HIGH = fan_ns.FAN_SPEED_HIGH

FAN_SPEEDS = {
    'OFF': FAN_SPEED_OFF,
    'LOW': FAN_SPEED_LOW,
Пример #4
0
import voluptuous as vol

from esphomeyaml.automation import ACTION_REGISTRY
import esphomeyaml.config_validation as cv
from esphomeyaml.const import CONF_ACCELERATION, CONF_DECELERATION, CONF_ID, CONF_MAX_SPEED, \
    CONF_POSITION, CONF_TARGET
from esphomeyaml.helpers import Pvariable, TemplateArguments, add, add_job, esphomelib_ns, \
    get_variable, int32, templatable, Action

PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({

})

# pylint: disable=invalid-name
stepper_ns = esphomelib_ns.namespace('stepper')
Stepper = stepper_ns.class_('Stepper')

SetTargetAction = stepper_ns.class_('SetTargetAction', Action)
ReportPositionAction = stepper_ns.class_('ReportPositionAction', Action)


def validate_acceleration(value):
    value = cv.string(value)
    for suffix in ('steps/s^2', 'steps/s*s', 'steps/s/s', 'steps/ss', 'steps/(s*s)'):
        if value.endswith(suffix):
            value = value[:-len(suffix)]

    if value == 'inf':
        return 1e6

    try:
Пример #5
0
import voluptuous as vol

from esphomeyaml.automation import maybe_simple_id, ACTION_REGISTRY
from esphomeyaml.components import mqtt
import esphomeyaml.config_validation as cv
from esphomeyaml.const import CONF_ICON, CONF_ID, CONF_INVERTED, CONF_MQTT_ID, CONF_INTERNAL, \
    CONF_OPTIMISTIC
from esphomeyaml.helpers import App, Pvariable, add, esphomelib_ns, setup_mqtt_component, \
    TemplateArguments, get_variable, Nameable, Action

PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({})

switch_ns = esphomelib_ns.namespace('switch_')
Switch = switch_ns.class_('Switch', Nameable)
MQTTSwitchComponent = switch_ns.class_('MQTTSwitchComponent',
                                       mqtt.MQTTComponent)

ToggleAction = switch_ns.class_('ToggleAction', Action)
TurnOffAction = switch_ns.class_('TurnOffAction', Action)
TurnOnAction = switch_ns.class_('TurnOnAction', Action)

SWITCH_SCHEMA = cv.MQTT_COMMAND_COMPONENT_SCHEMA.extend({
    cv.GenerateID(CONF_MQTT_ID):
    cv.declare_variable_id(MQTTSwitchComponent),
    vol.Optional(CONF_ICON):
    cv.icon,
    vol.Optional(CONF_INVERTED):
    cv.boolean,
})

SWITCH_PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(SWITCH_SCHEMA.schema)
Пример #6
0
import math

import voluptuous as vol

import esphomeyaml.config_validation as cv
from esphomeyaml import automation
from esphomeyaml.const import CONF_CRON, CONF_DAYS_OF_MONTH, CONF_DAYS_OF_WEEK, CONF_HOURS, \
    CONF_MINUTES, CONF_MONTHS, CONF_ON_TIME, CONF_SECONDS, CONF_TIMEZONE, CONF_TRIGGER_ID
from esphomeyaml.helpers import App, NoArg, Pvariable, add, add_job, esphomelib_ns, \
    ArrayInitializer, Component, Trigger

_LOGGER = logging.getLogger(__name__)

PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({})

time_ns = esphomelib_ns.namespace('time')
RealTimeClockComponent = time_ns.class_('RealTimeClockComponent', Component)
CronTrigger = time_ns.class_('CronTrigger', Trigger.template(NoArg), Component)
EsphomelibTime = time_ns.struct('EsphomelibTime')


def _tz_timedelta(td):
    offset_hour = int(td.total_seconds() / (60 * 60))
    offset_minute = int(abs(td.total_seconds() / 60)) % 60
    offset_second = int(abs(td.total_seconds())) % 60
    if offset_hour == 0 and offset_minute == 0 and offset_second == 0:
        return '0'
    elif offset_minute == 0 and offset_second == 0:
        return '{}'.format(offset_hour)
    elif offset_second == 0:
        return '{}:{}'.format(offset_hour, offset_minute)
Пример #7
0
import esphomeyaml.config_validation as cv
from esphomeyaml.const import CONF_ALPHA, CONF_BLUE, CONF_BRIGHTNESS, CONF_COLORS, \
    CONF_DEFAULT_TRANSITION_LENGTH, CONF_DURATION, CONF_EFFECTS, CONF_EFFECT_ID, \
    CONF_GAMMA_CORRECT, CONF_GREEN, CONF_ID, CONF_INTERNAL, CONF_LAMBDA, CONF_MQTT_ID, CONF_NAME, \
    CONF_NUM_LEDS, CONF_RANDOM, CONF_RED, CONF_SPEED, CONF_STATE, CONF_TRANSITION_LENGTH, \
    CONF_UPDATE_INTERVAL, CONF_WHITE, CONF_WIDTH, CONF_FLASH_LENGTH, CONF_COLOR_TEMPERATURE, \
    CONF_EFFECT
from esphomeyaml.helpers import Application, ArrayInitializer, Pvariable, RawExpression, \
    StructInitializer, add, add_job, esphomelib_ns, process_lambda, setup_mqtt_component, \
    get_variable, TemplateArguments, templatable, uint32, float_, std_string

PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({

})

light_ns = esphomelib_ns.namespace('light')
LightState = light_ns.LightState
LightColorValues = light_ns.LightColorValues
MQTTJSONLightComponent = light_ns.MQTTJSONLightComponent
ToggleAction = light_ns.ToggleAction
TurnOffAction = light_ns.TurnOffAction
TurnOnAction = light_ns.TurnOnAction
MakeLight = Application.MakeLight
RandomLightEffect = light_ns.RandomLightEffect
LambdaLightEffect = light_ns.LambdaLightEffect
StrobeLightEffect = light_ns.StrobeLightEffect
StrobeLightEffectColor = light_ns.StrobeLightEffectColor
FlickerLightEffect = light_ns.FlickerLightEffect
FastLEDLambdaLightEffect = light_ns.FastLEDLambdaLightEffect
FastLEDRainbowLightEffect = light_ns.FastLEDRainbowLightEffect
FastLEDColorWipeEffect = light_ns.FastLEDColorWipeEffect
Пример #8
0
import voluptuous as vol

import esphomeyaml.config_validation as cv
from esphomeyaml import pins
from esphomeyaml.const import CONF_BUFFER_SIZE, CONF_DUMP, CONF_FILTER, CONF_ID, CONF_IDLE, \
    CONF_PIN, CONF_TOLERANCE
from esphomeyaml.helpers import App, Pvariable, add, esphomelib_ns, gpio_input_pin_expression

remote_ns = esphomelib_ns.namespace('remote')

RemoteReceiverComponent = remote_ns.RemoteReceiverComponent

DUMPERS = {
    'lg': remote_ns.LGDumper,
    'nec': remote_ns.NECDumper,
    'panasonic': remote_ns.PanasonicDumper,
    'raw': remote_ns.RawDumper,
    'sony': remote_ns.SonyDumper,
    'rc_switch': remote_ns.RCSwitchDumper,
}


def validate_dumpers_all(value):
    if not isinstance(value, (str, unicode)):
        raise vol.Invalid("Not valid dumpers")
    if value.upper() == "ALL":
        return list(sorted(list(DUMPERS)))
    raise vol.Invalid("Not valid dumpers")


CONFIG_SCHEMA = vol.All(cv.ensure_list, [
Пример #9
0
import voluptuous as vol

from esphomeyaml import automation
from esphomeyaml.components import mqtt
import esphomeyaml.config_validation as cv
from esphomeyaml.const import CONF_ICON, CONF_ID, CONF_INTERNAL, CONF_MQTT_ID, CONF_ON_VALUE, \
    CONF_TRIGGER_ID
from esphomeyaml.helpers import App, Pvariable, add, add_job, esphomelib_ns, setup_mqtt_component, \
    std_string, Nameable, Trigger

PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({})

# pylint: disable=invalid-name
text_sensor_ns = esphomelib_ns.namespace('text_sensor')
TextSensor = text_sensor_ns.class_('TextSensor', Nameable)
MQTTTextSensor = text_sensor_ns.class_('MQTTTextSensor', mqtt.MQTTComponent)

TextSensorStateTrigger = text_sensor_ns.class_('TextSensorStateTrigger',
                                               Trigger.template(std_string))

TEXT_SENSOR_SCHEMA = cv.MQTT_COMPONENT_SCHEMA.extend({
    cv.GenerateID(CONF_MQTT_ID):
    cv.declare_variable_id(MQTTTextSensor),
    vol.Optional(CONF_ICON):
    cv.icon,
    vol.Optional(CONF_ON_VALUE):
    automation.validate_automation({
        cv.GenerateID(CONF_TRIGGER_ID):
        cv.declare_variable_id(TextSensorStateTrigger),
    }),
})
Пример #10
0
    vol.Optional(CONF_QOS, default=0):
    cv.mqtt_qos,
    vol.Optional(CONF_RETAIN, default=True):
    cv.boolean,
})

MQTT_MESSAGE_TEMPLATE_SCHEMA = vol.Any(None, MQTT_MESSAGE_BASE,
                                       validate_message_just_topic)

MQTT_MESSAGE_SCHEMA = vol.Any(
    None,
    MQTT_MESSAGE_BASE.extend({
        vol.Required(CONF_PAYLOAD): cv.mqtt_payload,
    }))

mqtt_ns = esphomelib_ns.namespace('mqtt')
MQTTMessage = mqtt_ns.MQTTMessage
MQTTClientComponent = mqtt_ns.MQTTClientComponent
MQTTPublishAction = mqtt_ns.MQTTPublishAction
MQTTMessageTrigger = mqtt_ns.MQTTMessageTrigger


def validate_broker(value):
    value = cv.string_strict(value)
    if u':' in value:
        raise vol.Invalid(u"Please specify the port using the port: option")
    if not value:
        raise vol.Invalid(u"Broker cannot be empty")
    return value

Пример #11
0
    CONF_MAX_LENGTH, CONF_MIN_LENGTH, CONF_MQTT_ID, CONF_ON_CLICK, CONF_ON_DOUBLE_CLICK, \
    CONF_ON_PRESS, CONF_ON_RELEASE, CONF_TRIGGER_ID, CONF_FILTERS, CONF_INVERT, CONF_DELAYED_ON, \
    CONF_DELAYED_OFF, CONF_LAMBDA, CONF_HEARTBEAT
from esphomeyaml.helpers import App, NoArg, Pvariable, add, add_job, esphomelib_ns, \
    setup_mqtt_component, bool_, process_lambda, ArrayInitializer

DEVICE_CLASSES = [
    '', 'battery', 'cold', 'connectivity', 'door', 'garage_door', 'gas',
    'heat', 'light', 'lock', 'moisture', 'motion', 'moving', 'occupancy',
    'opening', 'plug', 'power', 'presence', 'problem', 'safety', 'smoke',
    'sound', 'vibration', 'window'
]

PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({})

binary_sensor_ns = esphomelib_ns.namespace('binary_sensor')
PressTrigger = binary_sensor_ns.PressTrigger
ReleaseTrigger = binary_sensor_ns.ReleaseTrigger
ClickTrigger = binary_sensor_ns.ClickTrigger
DoubleClickTrigger = binary_sensor_ns.DoubleClickTrigger
BinarySensor = binary_sensor_ns.BinarySensor
InvertFilter = binary_sensor_ns.InvertFilter
LambdaFilter = binary_sensor_ns.LambdaFilter
DelayedOnFilter = binary_sensor_ns.DelayedOnFilter
DelayedOffFilter = binary_sensor_ns.DelayedOffFilter
HeartbeatFilter = binary_sensor_ns.HeartbeatFilter
MQTTBinarySensorComponent = binary_sensor_ns.MQTTBinarySensorComponent

FILTER_KEYS = [
    CONF_INVERT, CONF_DELAYED_ON, CONF_DELAYED_OFF, CONF_LAMBDA, CONF_HEARTBEAT
]
Пример #12
0
# coding=utf-8
import voluptuous as vol

import esphomeyaml.config_validation as cv
from esphomeyaml.const import CONF_LAMBDA, CONF_ROTATION, CONF_UPDATE_INTERVAL
from esphomeyaml.helpers import add, add_job, esphomelib_ns

PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({})

display_ns = esphomelib_ns.namespace('display')
DisplayBuffer = display_ns.class_('DisplayBuffer')
DisplayBufferRef = DisplayBuffer.operator('ref')

DISPLAY_ROTATIONS = {
    0: display_ns.DISPLAY_ROTATION_0_DEGREES,
    90: display_ns.DISPLAY_ROTATION_90_DEGREES,
    180: display_ns.DISPLAY_ROTATION_180_DEGREES,
    270: display_ns.DISPLAY_ROTATION_270_DEGREES,
}


def validate_rotation(value):
    value = cv.string(value)
    if value.endswith(u"°"):
        value = value[:-1]
    try:
        value = int(value)
    except ValueError:
        raise vol.Invalid(u"Expected integer for rotation")
    return cv.one_of(*DISPLAY_ROTATIONS)(value)
Пример #13
0
import esphomeyaml.config_validation as cv
from esphomeyaml.const import CONF_ID, CONF_MQTT_ID
from esphomeyaml.helpers import Pvariable, esphomelib_ns, setup_mqtt_component

PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({

})

COVER_SCHEMA = cv.MQTT_COMMAND_COMPONENT_SCHEMA.extend({
    cv.GenerateID('cover'): cv.register_variable_id,
    cv.GenerateID('mqtt_cover', CONF_MQTT_ID): cv.register_variable_id,
})

cover_ns = esphomelib_ns.namespace('cover')
Cover = cover_ns.Cover
MQTTCoverComponent = cover_ns.MQTTCoverComponent
CoverState = cover_ns.CoverState
COVER_OPEN = cover_ns.COVER_OPEN
COVER_CLOSED = cover_ns.COVER_CLOSED
OpenAction = cover_ns.OpenAction
CloseAction = cover_ns.CloseAction
StopAction = cover_ns.StopAction


def setup_cover_core_(cover_var, mqtt_var, config):
    setup_mqtt_component(mqtt_var, config)


def setup_cover(cover_obj, mqtt_obj, config):
    cover_var = Pvariable(Cover, config[CONF_ID], cover_obj, has_side_effects=False)
    mqtt_var = Pvariable(MQTTCoverComponent, config[CONF_MQTT_ID], mqtt_obj,
Пример #14
0
import esphomeyaml.config_validation as cv
from esphomeyaml.const import CONF_ADDRESS, CONF_ID, CONF_PCF8575
from esphomeyaml.helpers import App, Pvariable, esphomelib_ns

DEPENDENCIES = ['i2c']

PCF8574_SCHEMA = vol.Schema({
    vol.Required(CONF_ID):
    cv.register_variable_id,
    vol.Optional(CONF_ADDRESS, default=0x21):
    cv.i2c_address,
    vol.Optional(CONF_PCF8575, default=False):
    cv.boolean,
})

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

io_ns = esphomelib_ns.namespace('io')
PCF8574Component = io_ns.PCF8574Component


def to_code(config):
    for conf in config:
        rhs = App.make_pcf8574_component(conf[CONF_ADDRESS],
                                         conf[CONF_PCF8575])
        Pvariable(PCF8574Component, conf[CONF_ID], rhs)


BUILD_FLAGS = '-DUSE_PCF8574'