示例#1
0
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),
    }),
})

TEXT_SENSOR_PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(TEXT_SENSOR_SCHEMA.schema)
示例#2
0
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)
    return '{}:{}:{}'.format(offset_hour, offset_minute, offset_second)
示例#3
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),
})

示例#4
0
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.struct('MQTTMessage')
MQTTClientComponent = mqtt_ns.class_('MQTTClientComponent', Component)
MQTTPublishAction = mqtt_ns.class_('MQTTPublishAction', Action)
MQTTPublishJsonAction = mqtt_ns.class_('MQTTPublishJsonAction', Action)
MQTTMessageTrigger = mqtt_ns.class_('MQTTMessageTrigger',
                                    Trigger.template(std_string))
MQTTJsonMessageTrigger = mqtt_ns.class_('MQTTJsonMessageTrigger',
                                        Trigger.template(JsonObjectConstRef))
MQTTComponent = mqtt_ns.class_('MQTTComponent', Component)


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


def validate_fingerprint(value):
示例#5
0
import voluptuous as vol

import esphomeyaml.config_validation as cv
from esphomeyaml import pins, automation
from esphomeyaml.components import binary_sensor, spi
from esphomeyaml.components.spi import SPIComponent
from esphomeyaml.const import CONF_CS_PIN, CONF_ID, CONF_SPI_ID, CONF_UPDATE_INTERVAL, \
    CONF_ON_TAG, CONF_TRIGGER_ID
from esphomeyaml.helpers import App, Pvariable, get_variable, gpio_output_pin_expression, \
    std_string, setup_component, PollingComponent, Trigger

DEPENDENCIES = ['spi']

PN532Component = binary_sensor.binary_sensor_ns.class_('PN532Component', PollingComponent,
                                                       spi.SPIDevice)
PN532Trigger = binary_sensor.binary_sensor_ns.class_('PN532Trigger', Trigger.template(std_string))

CONFIG_SCHEMA = vol.All(cv.ensure_list, [vol.Schema({
    cv.GenerateID(): cv.declare_variable_id(PN532Component),
    cv.GenerateID(CONF_SPI_ID): cv.use_variable_id(SPIComponent),
    vol.Required(CONF_CS_PIN): pins.gpio_output_pin_schema,
    vol.Optional(CONF_UPDATE_INTERVAL): cv.update_interval,
    vol.Optional(CONF_ON_TAG): automation.validate_automation({
        cv.GenerateID(CONF_TRIGGER_ID): cv.declare_variable_id(PN532Trigger),
    }),
}).extend(cv.COMPONENT_SCHEMA.schema)])


def to_code(config):
    for conf in config:
        for spi_ in get_variable(conf[CONF_SPI_ID]):
示例#6
0
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')
BinarySensor = binary_sensor_ns.class_('BinarySensor', Nameable)
MQTTBinarySensorComponent = binary_sensor_ns.class_(
    'MQTTBinarySensorComponent', mqtt.MQTTComponent)

# Triggers
PressTrigger = binary_sensor_ns.class_('PressTrigger', Trigger.template(NoArg))
ReleaseTrigger = binary_sensor_ns.class_('ReleaseTrigger',
                                         Trigger.template(NoArg))
ClickTrigger = binary_sensor_ns.class_('ClickTrigger', Trigger.template(NoArg))
DoubleClickTrigger = binary_sensor_ns.class_('DoubleClickTrigger',
                                             Trigger.template(NoArg))
MultiClickTrigger = binary_sensor_ns.class_('MultiClickTrigger',
                                            Trigger.template(NoArg), Component)
MultiClickTriggerEvent = binary_sensor_ns.struct('MultiClickTriggerEvent')

# Filters
Filter = binary_sensor_ns.class_('Filter')
DelayedOnFilter = binary_sensor_ns.class_('DelayedOnFilter', Filter, Component)
DelayedOffFilter = binary_sensor_ns.class_('DelayedOffFilter', Filter,
                                           Component)
HeartbeatFilter = binary_sensor_ns.class_('HeartbeatFilter', Filter, Component)
示例#7
0
# Base
sensor_ns = esphomelib_ns.namespace('sensor')
Sensor = sensor_ns.class_('Sensor', Nameable)
MQTTSensorComponent = sensor_ns.class_('MQTTSensorComponent',
                                       mqtt.MQTTComponent)

PollingSensorComponent = sensor_ns.class_('PollingSensorComponent',
                                          PollingComponent, Sensor)
EmptySensor = sensor_ns.class_('EmptySensor', Sensor)
EmptyPollingParentSensor = sensor_ns.class_('EmptyPollingParentSensor',
                                            EmptySensor)

# Triggers
SensorStateTrigger = sensor_ns.class_('SensorStateTrigger',
                                      Trigger.template(float_))
SensorRawStateTrigger = sensor_ns.class_('SensorRawStateTrigger',
                                         Trigger.template(float_))
ValueRangeTrigger = sensor_ns.class_('ValueRangeTrigger',
                                     Trigger.template(float_))

# Filters
Filter = sensor_ns.class_('Filter')
SlidingWindowMovingAverageFilter = sensor_ns.class_(
    'SlidingWindowMovingAverageFilter', Filter)
ExponentialMovingAverageFilter = sensor_ns.class_(
    'ExponentialMovingAverageFilter', Filter)
LambdaFilter = sensor_ns.class_('LambdaFilter', Filter)
OffsetFilter = sensor_ns.class_('OffsetFilter', Filter)
MultiplyFilter = sensor_ns.class_('MultiplyFilter', Filter)
FilterOutValueFilter = sensor_ns.class_('FilterOutValueFilter', Filter)