Example #1
0
import voluptuous as vol

from esphome import pins
from esphome.components import sensor
import esphome.config_validation as cv
from esphome.const import CONF_CLK_PIN, CONF_GAIN, CONF_ID, CONF_NAME, CONF_UPDATE_INTERVAL
from esphome.cpp_generator import Pvariable, add
from esphome.cpp_helpers import gpio_input_pin_expression, setup_component
from esphome.cpp_types import App, Application

MakeHX711Sensor = Application.struct('MakeHX711Sensor')
HX711Sensor = sensor.sensor_ns.class_('HX711Sensor',
                                      sensor.PollingSensorComponent)

CONF_DOUT_PIN = 'dout_pin'

HX711Gain = sensor.sensor_ns.enum('HX711Gain')
GAINS = {
    128: HX711Gain.HX711_GAIN_128,
    32: HX711Gain.HX711_GAIN_32,
    64: HX711Gain.HX711_GAIN_64,
}

PLATFORM_SCHEMA = cv.nameable(
    sensor.SENSOR_PLATFORM_SCHEMA.extend({
        cv.GenerateID():
        cv.declare_variable_id(HX711Sensor),
        vol.Required(CONF_DOUT_PIN):
        pins.gpio_input_pin_schema,
        vol.Required(CONF_CLK_PIN):
        pins.gpio_output_pin_schema,
Example #2
0
    'RGB',
    'RBG',
    'GRB',
    'GBR',
    'BRG',
    'BGR',
]


def validate(value):
    if value[CONF_CHIPSET] == 'NEOPIXEL' and CONF_RGB_ORDER in value:
        raise vol.Invalid("NEOPIXEL doesn't support RGB order")
    return value


MakeFastLEDLight = Application.struct('MakeFastLEDLight')

PLATFORM_SCHEMA = cv.nameable(
    light.LIGHT_PLATFORM_SCHEMA.extend({
        cv.GenerateID():
        cv.declare_variable_id(light.AddressableLightState),
        cv.GenerateID(CONF_MAKE_ID):
        cv.declare_variable_id(MakeFastLEDLight),
        vol.Required(CONF_CHIPSET):
        cv.one_of(*TYPES, upper=True),
        vol.Required(CONF_PIN):
        pins.output_pin,
        vol.Required(CONF_NUM_LEDS):
        cv.positive_not_null_int,
        vol.Optional(CONF_MAX_REFRESH_RATE):
        cv.positive_time_period_microseconds,
Example #3
0
from esphome.components.mqtt import setup_mqtt_component
import esphome.config_validation as cv
from esphome.const import CONF_ID, CONF_INTERNAL, CONF_MQTT_ID, CONF_OSCILLATING, \
    CONF_OSCILLATION_COMMAND_TOPIC, CONF_OSCILLATION_STATE_TOPIC, CONF_SPEED, \
    CONF_SPEED_COMMAND_TOPIC, CONF_SPEED_STATE_TOPIC
from esphome.core import CORE
from esphome.cpp_generator import Pvariable, add, get_variable, templatable
from esphome.cpp_types import Action, Application, Component, Nameable, bool_, esphome_ns
from esphome.py_compat import string_types

PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({})

fan_ns = esphome_ns.namespace('fan')
FanState = fan_ns.class_('FanState', Nameable, Component)
MQTTFanComponent = fan_ns.class_('MQTTFanComponent', mqtt.MQTTComponent)
MakeFan = Application.struct('MakeFan')

# Actions
TurnOnAction = fan_ns.class_('TurnOnAction', Action)
TurnOffAction = fan_ns.class_('TurnOffAction', Action)
ToggleAction = fan_ns.class_('ToggleAction', Action)

FanSpeed = fan_ns.enum('FanSpeed')
FAN_SPEED_OFF = FanSpeed.FAN_SPEED_OFF
FAN_SPEED_LOW = FanSpeed.FAN_SPEED_LOW
FAN_SPEED_MEDIUM = FanSpeed.FAN_SPEED_MEDIUM
FAN_SPEED_HIGH = FanSpeed.FAN_SPEED_HIGH

FAN_SCHEMA = cv.MQTT_COMMAND_COMPONENT_SCHEMA.extend({
    cv.GenerateID():
    cv.declare_variable_id(FanState),
Example #4
0
import voluptuous as vol

from esphome.components import sensor
import esphome.config_validation as cv
from esphome.const import CONF_ID, CONF_NAME, CONF_UPDATE_INTERVAL, ESP_PLATFORM_ESP32
from esphome.cpp_generator import Pvariable
from esphome.cpp_helpers import setup_component
from esphome.cpp_types import App, Application

ESP_PLATFORMS = [ESP_PLATFORM_ESP32]

MakeESP32HallSensor = Application.struct('MakeESP32HallSensor')
ESP32HallSensor = sensor.sensor_ns.class_('ESP32HallSensor', sensor.PollingSensorComponent)

PLATFORM_SCHEMA = cv.nameable(sensor.SENSOR_PLATFORM_SCHEMA.extend({
    cv.GenerateID(): cv.declare_variable_id(ESP32HallSensor),
    vol.Optional(CONF_UPDATE_INTERVAL): cv.update_interval,
}).extend(cv.COMPONENT_SCHEMA.schema))


def to_code(config):
    rhs = App.make_esp32_hall_sensor(config[CONF_NAME], config.get(CONF_UPDATE_INTERVAL))
    hall = Pvariable(config[CONF_ID], rhs)
    sensor.setup_sensor(hall, config)
    setup_component(hall, config)


BUILD_FLAGS = '-DUSE_ESP32_HALL_SENSOR'
Example #5
0
import voluptuous as vol

from esphome.components import i2c, sensor
import esphome.config_validation as cv
from esphome.const import CONF_HUMIDITY, CONF_ID, CONF_NAME, CONF_TEMPERATURE, \
    CONF_UPDATE_INTERVAL
from esphome.cpp_generator import Pvariable
from esphome.cpp_helpers import setup_component
from esphome.cpp_types import App, Application, PollingComponent

DEPENDENCIES = ['i2c']

MakeHTU21DSensor = Application.struct('MakeHTU21DSensor')
HTU21DComponent = sensor.sensor_ns.class_('HTU21DComponent', PollingComponent, i2c.I2CDevice)
HTU21DTemperatureSensor = sensor.sensor_ns.class_('HTU21DTemperatureSensor',
                                                  sensor.EmptyPollingParentSensor)
HTU21DHumiditySensor = sensor.sensor_ns.class_('HTU21DHumiditySensor',
                                               sensor.EmptyPollingParentSensor)

PLATFORM_SCHEMA = sensor.PLATFORM_SCHEMA.extend({
    cv.GenerateID(): cv.declare_variable_id(HTU21DComponent),
    vol.Required(CONF_TEMPERATURE): cv.nameable(sensor.SENSOR_SCHEMA.extend({
        cv.GenerateID(): cv.declare_variable_id(HTU21DTemperatureSensor),
    })),
    vol.Required(CONF_HUMIDITY): cv.nameable(sensor.SENSOR_SCHEMA.extend({
        cv.GenerateID(): cv.declare_variable_id(HTU21DHumiditySensor),
    })),
    vol.Optional(CONF_UPDATE_INTERVAL): cv.update_interval,
}).extend(cv.COMPONENT_SCHEMA.schema)

Example #6
0
import voluptuous as vol

from esphome.components import light
from esphome.components.light import AddressableLight
import esphome.config_validation as cv
from esphome.const import CONF_DEFAULT_TRANSITION_LENGTH, CONF_EFFECTS, CONF_FROM, CONF_ID, \
    CONF_MAKE_ID, CONF_NAME, CONF_SEGMENTS, CONF_TO
from esphome.cpp_generator import get_variable, variable
from esphome.cpp_types import App, Application

AddressableSegment = light.light_ns.class_('AddressableSegment')
PartitionLightOutput = light.light_ns.class_('PartitionLightOutput',
                                             AddressableLight)
MakePartitionLight = Application.struct('MakePartitionLight')


def validate_from_to(value):
    if value[CONF_FROM] > value[CONF_TO]:
        raise vol.Invalid(u"From ({}) must not be larger than to ({})"
                          u"".format(value[CONF_FROM], value[CONF_TO]))
    return value


PLATFORM_SCHEMA = cv.nameable(
    light.LIGHT_PLATFORM_SCHEMA.extend({
        cv.GenerateID():
        cv.declare_variable_id(light.AddressableLightState),
        cv.GenerateID(CONF_MAKE_ID):
        cv.declare_variable_id(MakePartitionLight),
        vol.Required(CONF_SEGMENTS):
        vol.All(
Example #7
0
def validate(config):
    if CONF_PIN in config:
        if CONF_CLOCK_PIN in config or CONF_DATA_PIN in config:
            raise vol.Invalid(
                "Cannot specify both 'pin' and 'clock_pin'+'data_pin'")
        return config
    if CONF_CLOCK_PIN in config:
        if CONF_DATA_PIN not in config:
            raise vol.Invalid(
                "If you give clock_pin, you must also specify data_pin")
        return config
    raise vol.Invalid(
        "Must specify at least one of 'pin' or 'clock_pin'+'data_pin'")


MakeNeoPixelBusLight = Application.struct('MakeNeoPixelBusLight')

PLATFORM_SCHEMA = cv.nameable(
    light.LIGHT_PLATFORM_SCHEMA.extend({
        cv.GenerateID():
        cv.declare_variable_id(light.AddressableLightState),
        cv.GenerateID(CONF_MAKE_ID):
        cv.declare_variable_id(MakeNeoPixelBusLight),
        vol.Optional(CONF_TYPE, default='GRB'):
        validate_type,
        vol.Optional(CONF_VARIANT, default='800KBPS'):
        validate_variant,
        vol.Optional(CONF_METHOD, default=None):
        validate_method,
        vol.Optional(CONF_PIN):
        pins.output_pin,