Пример #1
0
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import display, uart
from esphome.const import CONF_ID, CONF_LAMBDA, CONF_BRIGHTNESS
from . import nextion_ns

DEPENDENCIES = ["uart"]
AUTO_LOAD = ["binary_sensor"]

Nextion = nextion_ns.class_("Nextion", cg.PollingComponent, uart.UARTDevice)
NextionRef = Nextion.operator("ref")

CONFIG_SCHEMA = (display.BASIC_DISPLAY_SCHEMA.extend({
    cv.GenerateID():
    cv.declare_id(Nextion),
    cv.Optional(CONF_BRIGHTNESS, default=1.0):
    cv.percentage,
}).extend(cv.polling_component_schema("5s")).extend(uart.UART_DEVICE_SCHEMA))


async def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    await cg.register_component(var, config)
    await uart.register_uart_device(var, config)

    if CONF_BRIGHTNESS in config:
        cg.add(var.set_brightness(config[CONF_BRIGHTNESS]))
    if CONF_LAMBDA in config:
        lambda_ = await cg.process_lambda(config[CONF_LAMBDA],
                                          [(NextionRef, "it")],
                                          return_type=cg.void)
Пример #2
0
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import i2c, sensor
from esphome.const import CONF_ID, DEVICE_CLASS_TEMPERATURE, ICON_EMPTY, UNIT_CELSIUS

DEPENDENCIES = ["i2c"]

sts3x_ns = cg.esphome_ns.namespace("sts3x")

STS3XComponent = sts3x_ns.class_("STS3XComponent", sensor.Sensor,
                                 cg.PollingComponent, i2c.I2CDevice)

CONFIG_SCHEMA = (sensor.sensor_schema(
    UNIT_CELSIUS, ICON_EMPTY, 1, DEVICE_CLASS_TEMPERATURE).extend({
        cv.GenerateID():
        cv.declare_id(STS3XComponent),
    }).extend(cv.polling_component_schema("60s")).extend(
        i2c.i2c_device_schema(0x4A)))


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)
Пример #3
0
            raise cv.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 cv.Invalid(
                "If you give clock_pin, you must also specify data_pin")
        return config
    raise cv.Invalid(
        "Must specify at least one of 'pin' or 'clock_pin'+'data_pin'")


CONFIG_SCHEMA = cv.All(
    light.ADDRESSABLE_LIGHT_SCHEMA.extend({
        cv.GenerateID(CONF_OUTPUT_ID):
        cv.declare_id(NeoPixelBusLightOutputBase),
        cv.Optional(CONF_TYPE, default="GRB"):
        validate_type,
        cv.Optional(CONF_VARIANT, default="800KBPS"):
        validate_variant,
        cv.Optional(CONF_METHOD, default=None):
        validate_method,
        cv.Optional(CONF_INVERT, default="no"):
        cv.boolean,
        cv.Optional(CONF_PIN):
        pins.output_pin,
        cv.Optional(CONF_CLOCK_PIN):
        pins.output_pin,
        cv.Optional(CONF_DATA_PIN):
        pins.output_pin,
        cv.Required(CONF_NUM_LEDS):
Пример #4
0
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import sensor
from esphome.const import ICON_ROTATE_RIGHT, CONF_ID, UNIT_DEGREES, CONF_ROTATION

polehealth_ns = cg.esphome_ns.namespace('polehealth')
PoleHealthSensor = polehealth_ns.class_('PoleHealthSensor', cg.Component, sensor.Sensor)

rotation_schema = sensor.sensor_schema(UNIT_DEGREES, ICON_ROTATE_RIGHT, 1)

CONF_ACCEL_X = "in_accel_x"
CONF_ACCEL_Y = "in_accel_y"
CONF_ACCEL_Z = "in_accel_z"

CONFIG_SCHEMA = sensor.sensor_schema(UNIT_DEGREES, ICON_ROTATE_RIGHT, 1).extend({
    cv.GenerateID(): cv.declare_id(PoleHealthSensor),
    cv.Required(CONF_ACCEL_X): cv.use_id(sensor.Sensor),
    cv.Required(CONF_ACCEL_Y): cv.use_id(sensor.Sensor),
    cv.Required(CONF_ACCEL_Z): cv.use_id(sensor.Sensor),
    cv.Optional(CONF_ROTATION): rotation_schema,
}).extend(cv.COMPONENT_SCHEMA)


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

    sens_x = yield cg.get_variable(config[CONF_ACCEL_X])
    cg.add(var.set_accel_x(sens_x))
    sens_y = yield cg.get_variable(config[CONF_ACCEL_Y])
Пример #5
0
    if (
        config.get(CONF_VERIFY_SSL)
        and not isinstance(url_, Lambda)
        and url_.lower().startswith("https:")
    ):
        raise cv.Invalid(
            "Currently ESPHome doesn't support SSL verification. "
            "Set 'verify_ssl: false' to make insecure HTTPS requests."
        )
    return config


CONFIG_SCHEMA = cv.All(
    cv.Schema(
        {
            cv.GenerateID(): cv.declare_id(HttpRequestComponent),
            cv.Optional(CONF_USERAGENT, "ESPHome"): cv.string,
            cv.Optional(
                CONF_TIMEOUT, default="5s"
            ): cv.positive_time_period_milliseconds,
            cv.SplitDefault(CONF_ESP8266_DISABLE_SSL_SUPPORT, esp8266=False): cv.All(
                cv.only_on_esp8266, cv.boolean
            ),
        }
    ).extend(cv.COMPONENT_SCHEMA),
    cv.require_framework_version(
        esp8266_arduino=cv.Version(2, 5, 1),
        esp32_arduino=cv.Version(0, 0, 0),
    ),
)
Пример #6
0
    UNIT_EMPTY,
    UNIT_CELSIUS,
    UNIT_PERCENT,
    UNIT_VOLT,
)

DEPENDENCIES = ["uart"]

smt100_ns = cg.esphome_ns.namespace("smt100")
SMT100 = smt100_ns.class_("SMT100Component", cg.PollingComponent, uart.UARTDevice)


CONFIG_SCHEMA = (
    cv.Schema(
        {
            cv.GenerateID(): cv.declare_id(SMT100),
            cv.Optional(CONF_COUNTS): sensor.sensor_schema(
                unit_of_measurement=UNIT_EMPTY,
                accuracy_decimals=0,
                state_class=STATE_CLASS_MEASUREMENT,
            ),
            cv.Optional(CONF_DIELECTRIC_CONSTANT): sensor.sensor_schema(
                unit_of_measurement=UNIT_EMPTY,
                accuracy_decimals=2,
                state_class=STATE_CLASS_MEASUREMENT,
            ),
            cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema(
                unit_of_measurement=UNIT_CELSIUS,
                accuracy_decimals=2,
                device_class=DEVICE_CLASS_TEMPERATURE,
                state_class=STATE_CLASS_MEASUREMENT,
Пример #7
0
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import light, output
from esphome.const import CONF_OUTPUT_ID, CONF_PIN_A, CONF_PIN_B

hbridge_ns = cg.esphome_ns.namespace("hbridge")
HBridgeLightOutput = hbridge_ns.class_("HBridgeLightOutput",
                                       cg.PollingComponent, light.LightOutput)

CONFIG_SCHEMA = light.RGB_LIGHT_SCHEMA.extend({
    cv.GenerateID(CONF_OUTPUT_ID):
    cv.declare_id(HBridgeLightOutput),
    cv.Required(CONF_PIN_A):
    cv.use_id(output.FloatOutput),
    cv.Required(CONF_PIN_B):
    cv.use_id(output.FloatOutput),
})


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

    hside = yield cg.get_variable(config[CONF_PIN_A])
    cg.add(var.set_pina_pin(hside))
    lside = yield cg.get_variable(config[CONF_PIN_B])
    cg.add(var.set_pinb_pin(lside))
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome import pins
from esphome.components import sensor
from esphome.const import CONF_ECHO_PIN, CONF_ID, CONF_TRIGGER_PIN, \
    CONF_TIMEOUT, UNIT_METER, ICON_ARROW_EXPAND_VERTICAL

CONF_PULSE_TIME = 'pulse_time'

ultrasonic_ns = cg.esphome_ns.namespace('ultrasonic')
UltrasonicSensorComponent = ultrasonic_ns.class_('UltrasonicSensorComponent',
                                                 sensor.Sensor, cg.PollingComponent)

CONFIG_SCHEMA = sensor.sensor_schema(UNIT_METER, ICON_ARROW_EXPAND_VERTICAL, 2).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'))


def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    yield cg.register_component(var, config)
Пример #9
0
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import i2c
from esphome.components import light
from esphome.const import CONF_OUTPUT_ID

DEPENDENCIES = ['i2c']

lp5024_ns = cg.esphome_ns.namespace('lp5024')
LP5024LightOutputBase = lp5024_ns.class_('LP5024LightOutputBase',
                                         light.AddressableLight)

CONFIG_SCHEMA = cv.All(
    light.ADDRESSABLE_LIGHT_SCHEMA.extend({
        cv.GenerateID(CONF_OUTPUT_ID):
        cv.declare_id(LP5024LightOutputBase),
    }).extend(cv.COMPONENT_SCHEMA).extend(i2c.i2c_device_schema(0x50)))


def to_code(config):
    var = cg.new_Pvariable(config[CONF_OUTPUT_ID])
    yield cg.register_component(var, config)
    yield i2c.register_i2c_device(var, config)
    yield light.register_light(var, config)
Пример #10
0
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome import pins
from esphome.const import CONF_FREQUENCY, CONF_ID, CONF_SCAN, CONF_SCL, CONF_SDA, CONF_ADDRESS, \
    CONF_I2C_ID
from esphome.core import coroutine, coroutine_with_priority

i2c_ns = cg.esphome_ns.namespace('i2c')
I2CComponent = i2c_ns.class_('I2CComponent', cg.Component)
I2CDevice = i2c_ns.class_('I2CDevice')

MULTI_CONF = True
CONFIG_SCHEMA = cv.Schema({
    cv.GenerateID():
    cv.declare_id(I2CComponent),
    cv.Optional(CONF_SDA, default='SDA'):
    pins.input_pin,
    cv.Optional(CONF_SCL, default='SCL'):
    pins.input_pin,
    cv.Optional(CONF_FREQUENCY, default='50kHz'):
    cv.All(cv.frequency, cv.Range(min=0, min_included=False)),
    cv.Optional(CONF_SCAN, default=True):
    cv.boolean,
}).extend(cv.COMPONENT_SCHEMA)


@coroutine_with_priority(1.0)
def to_code(config):
    cg.add_global(i2c_ns.using)
    var = cg.new_Pvariable(config[CONF_ID])
    yield cg.register_component(var, config)
Пример #11
0
import esphome.config_validation as cv
from esphome.components import sensor
from esphome.const import (
    CONF_ID,
    DEVICE_CLASS_SIGNAL_STRENGTH,
    ENTITY_CATEGORY_DIAGNOSTIC,
    STATE_CLASS_MEASUREMENT,
    UNIT_DECIBEL_MILLIWATT,
)

DEPENDENCIES = ["wifi"]
wifi_signal_ns = cg.esphome_ns.namespace("wifi_signal")
WiFiSignalSensor = wifi_signal_ns.class_("WiFiSignalSensor", sensor.Sensor,
                                         cg.PollingComponent)

CONFIG_SCHEMA = (sensor.sensor_schema(
    unit_of_measurement=UNIT_DECIBEL_MILLIWATT,
    accuracy_decimals=0,
    device_class=DEVICE_CLASS_SIGNAL_STRENGTH,
    state_class=STATE_CLASS_MEASUREMENT,
    entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
).extend({
    cv.GenerateID(): cv.declare_id(WiFiSignalSensor),
}).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)
Пример #12
0
    UNIT_CELSIUS,
    ICON_PERCENT,
    ICON_THERMOMETER,
    DEVICE_CLASS_BATTERY,
    DEVICE_CLASS_TEMPERATURE,
)

AUTO_LOAD = ['sensor']

CONF_CURRENT_TEMP = "current_temp"
CONF_STATE_CLASS = "measurement"

WavinAhc9000Climate = wavinAhc9000_ns.class_('WavinAhc9000Climate', climate.Climate, cg.Component)
 
CONFIG_SCHEMA = climate.CLIMATE_SCHEMA.extend({
    cv.GenerateID(): cv.declare_id(WavinAhc9000Climate),
    cv.GenerateID(CONF_WAVINAHC9000_ID): cv.use_id(WavinAhc9000),
    cv.Required(CONF_CHANNEL): cv.int_range(min=1, max=16),
    cv.Optional(CONF_BATTERY_LEVEL): sensor.sensor_schema(UNIT_PERCENT, ICON_PERCENT, 0, DEVICE_CLASS_BATTERY),
    cv.Optional(CONF_CURRENT_TEMP): sensor.sensor_schema(UNIT_CELSIUS, ICON_THERMOMETER, 1, DEVICE_CLASS_TEMPERATURE, CONF_STATE_CLASS),
}).extend(cv.COMPONENT_SCHEMA)
 
def to_code(config):
    wavin = yield cg.get_variable(config[CONF_WAVINAHC9000_ID])
    var = cg.new_Pvariable(config[CONF_ID], wavin)
    yield cg.register_component(var, config)
    yield climate.register_climate(var, config)
 
    cg.add(var.set_channel(config[CONF_CHANNEL] - 1))
    if CONF_BATTERY_LEVEL in config:
        sens = yield sensor.new_sensor(config[CONF_BATTERY_LEVEL])
Пример #13
0
    UNIT_PERCENT,
    UNIT_EMPTY,
)

DEPENDENCIES = ["i2c"]

# locally defined constant

lc709203f_ns = cg.esphome_ns.namespace("lc709203f")

LC709203FComponent = lc709203f_ns.class_("LC709203FComponent",
                                         cg.PollingComponent, i2c.I2CDevice)

CONFIG_SCHEMA = (cv.Schema({
    cv.GenerateID():
    cv.declare_id(LC709203FComponent),
    cv.Optional(CONF_BATTERY_VOLTAGE):
    sensor.sensor_schema(UNIT_VOLT, ICON_EMPTY, 2).extend({}),
    cv.Optional(CONF_BATTERY_LEVEL):
    sensor.sensor_schema(UNIT_PERCENT, ICON_EMPTY, 1).extend({}),
    cv.Optional("cell_charge"):
    sensor.sensor_schema(UNIT_PERCENT, ICON_EMPTY, 0).extend({}),
}).extend(cv.polling_component_schema("60s")).extend(
    i2c.i2c_device_schema(0x77)))


def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    yield cg.register_component(var, config)
    yield i2c.register_i2c_device(var, config)
Пример #14
0
}

color_channel_schema = sensor.sensor_schema(
    UNIT_PERCENT, ICON_LIGHTBULB, 1, DEVICE_CLASS_EMPTY
)
color_temperature_schema = sensor.sensor_schema(
    UNIT_KELVIN, ICON_THERMOMETER, 1, DEVICE_CLASS_EMPTY
)
illuminance_schema = sensor.sensor_schema(
    UNIT_LUX, ICON_EMPTY, 1, DEVICE_CLASS_ILLUMINANCE
)

CONFIG_SCHEMA = (
    cv.Schema(
        {
            cv.GenerateID(): cv.declare_id(TCS34725Component),
            cv.Optional(CONF_RED_CHANNEL): color_channel_schema,
            cv.Optional(CONF_GREEN_CHANNEL): color_channel_schema,
            cv.Optional(CONF_BLUE_CHANNEL): color_channel_schema,
            cv.Optional(CONF_CLEAR_CHANNEL): color_channel_schema,
            cv.Optional(CONF_ILLUMINANCE): illuminance_schema,
            cv.Optional(CONF_COLOR_TEMPERATURE): color_temperature_schema,
            cv.Optional(CONF_INTEGRATION_TIME, default="2.4ms"): cv.enum(
                TCS34725_INTEGRATION_TIMES, lower=True
            ),
            cv.Optional(CONF_GAIN, default="1X"): cv.enum(TCS34725_GAINS, upper=True),
        }
    )
    .extend(cv.polling_component_schema("60s"))
    .extend(i2c.i2c_device_schema(0x29))
)
Пример #15
0
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome import pins
from esphome.components import spi, ssd1306_base
from esphome.const import CONF_DC_PIN, CONF_ID, CONF_LAMBDA, CONF_PAGES

AUTO_LOAD = ["ssd1306_base"]
DEPENDENCIES = ["spi"]

ssd1306_spi = cg.esphome_ns.namespace("ssd1306_spi")
SPISSD1306 = ssd1306_spi.class_("SPISSD1306", ssd1306_base.SSD1306, spi.SPIDevice)

CONFIG_SCHEMA = cv.All(
    ssd1306_base.SSD1306_SCHEMA.extend(
        {
            cv.GenerateID(): cv.declare_id(SPISSD1306),
            cv.Required(CONF_DC_PIN): pins.gpio_output_pin_schema,
        }
    )
    .extend(cv.COMPONENT_SCHEMA)
    .extend(spi.spi_device_schema()),
    cv.has_at_most_one_key(CONF_PAGES, CONF_LAMBDA),
)


async def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    await ssd1306_base.setup_ssd1036(var, config)
    await spi.register_spi_device(var, config)

    dc = await cg.gpio_pin_expression(config[CONF_DC_PIN])
Пример #16
0
CODEOWNERS = ["@esphome/core"]
IS_PLATFORM_COMPONENT = True

LightRestoreMode = light_ns.enum("LightRestoreMode")
RESTORE_MODES = {
    "RESTORE_DEFAULT_OFF": LightRestoreMode.LIGHT_RESTORE_DEFAULT_OFF,
    "RESTORE_DEFAULT_ON": LightRestoreMode.LIGHT_RESTORE_DEFAULT_ON,
    "ALWAYS_OFF": LightRestoreMode.LIGHT_ALWAYS_OFF,
    "ALWAYS_ON": LightRestoreMode.LIGHT_ALWAYS_ON,
    "RESTORE_INVERTED_DEFAULT_OFF": LightRestoreMode.LIGHT_RESTORE_INVERTED_DEFAULT_OFF,
    "RESTORE_INVERTED_DEFAULT_ON": LightRestoreMode.LIGHT_RESTORE_INVERTED_DEFAULT_ON,
}

LIGHT_SCHEMA = cv.NAMEABLE_SCHEMA.extend(cv.MQTT_COMMAND_COMPONENT_SCHEMA).extend(
    {
        cv.GenerateID(): cv.declare_id(LightState),
        cv.OnlyWith(CONF_MQTT_ID, "mqtt"): cv.declare_id(mqtt.MQTTJSONLightComponent),
        cv.Optional(CONF_RESTORE_MODE, default="restore_default_off"): cv.enum(
            RESTORE_MODES, upper=True, space="_"
        ),
        cv.Optional(CONF_ON_TURN_ON): auto.validate_automation(
            {
                cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(LightTurnOnTrigger),
            }
        ),
        cv.Optional(CONF_ON_TURN_OFF): auto.validate_automation(
            {
                cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(LightTurnOffTrigger),
            }
        ),
    }
Пример #17
0
    CONF_POSITION_ACTION
from .. import template_ns

TemplateCover = template_ns.class_('TemplateCover', cover.Cover, cg.Component)

TemplateCoverRestoreMode = template_ns.enum('TemplateCoverRestoreMode')
RESTORE_MODES = {
    'NO_RESTORE': TemplateCoverRestoreMode.COVER_NO_RESTORE,
    'RESTORE': TemplateCoverRestoreMode.COVER_RESTORE,
    'RESTORE_AND_CALL': TemplateCoverRestoreMode.COVER_RESTORE_AND_CALL,
}

CONF_HAS_POSITION = 'has_position'

CONFIG_SCHEMA = cover.COVER_SCHEMA.extend({
    cv.GenerateID(): cv.declare_id(TemplateCover),
    cv.Optional(CONF_LAMBDA): cv.returning_lambda,
    cv.Optional(CONF_OPTIMISTIC, default=False): cv.boolean,
    cv.Optional(CONF_ASSUMED_STATE, default=False): cv.boolean,
    cv.Optional(CONF_HAS_POSITION, default=False): cv.boolean,
    cv.Optional(CONF_OPEN_ACTION): automation.validate_automation(single=True),
    cv.Optional(CONF_CLOSE_ACTION): automation.validate_automation(single=True),
    cv.Optional(CONF_STOP_ACTION): automation.validate_automation(single=True),
    cv.Optional(CONF_TILT_ACTION): automation.validate_automation(single=True),
    cv.Optional(CONF_TILT_LAMBDA): cv.returning_lambda,
    cv.Optional(CONF_POSITION_ACTION): automation.validate_automation(single=True),
    cv.Optional(CONF_RESTORE_MODE, default='RESTORE'): cv.enum(RESTORE_MODES, upper=True),
}).extend(cv.COMPONENT_SCHEMA)


def to_code(config):
Пример #18
0
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import switch
from esphome.const import CONF_ID, CONF_LAMBDA, CONF_SWITCHES
from .. import custom_ns

CustomSwitchConstructor = custom_ns.class_("CustomSwitchConstructor")

CONFIG_SCHEMA = cv.Schema({
    cv.GenerateID():
    cv.declare_id(CustomSwitchConstructor),
    cv.Required(CONF_LAMBDA):
    cv.returning_lambda,
    cv.Required(CONF_SWITCHES):
    cv.ensure_list(
        switch.SWITCH_SCHEMA.extend({
            cv.GenerateID():
            cv.declare_id(switch.Switch),
        })),
})


async def to_code(config):
    template_ = await cg.process_lambda(config[CONF_LAMBDA], [],
                                        return_type=cg.std_vector.template(
                                            switch.SwitchPtr))

    rhs = CustomSwitchConstructor(template_)
    var = cg.variable(config[CONF_ID], rhs)
    for i, conf in enumerate(config[CONF_SWITCHES]):
        switch_ = cg.Pvariable(conf[CONF_ID], var.get_switch(i))
Пример #19
0
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import binary_sensor
from esphome.const import CONF_ID, CONF_DEVICE_CLASS, DEVICE_CLASS_CONNECTIVITY

status_ns = cg.esphome_ns.namespace("status")
StatusBinarySensor = status_ns.class_("StatusBinarySensor",
                                      binary_sensor.BinarySensor, cg.Component)

CONFIG_SCHEMA = binary_sensor.BINARY_SENSOR_SCHEMA.extend({
    cv.GenerateID():
    cv.declare_id(StatusBinarySensor),
    cv.Optional(CONF_DEVICE_CLASS, default=DEVICE_CLASS_CONNECTIVITY):
    binary_sensor.device_class,
}).extend(cv.COMPONENT_SCHEMA)


def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    yield cg.register_component(var, config)
    yield binary_sensor.register_binary_sensor(var, config)
Пример #20
0
from esphome.const import CONF_ID, CONF_SENSOR

AUTO_LOAD = ['sensor']

yashima_ns = cg.esphome_ns.namespace('yashima')
YashimaClimate = yashima_ns.class_('YashimaClimate', climate.Climate,
                                   cg.Component)

CONF_TRANSMITTER_ID = 'transmitter_id'
CONF_SUPPORTS_HEAT = 'supports_heat'
CONF_SUPPORTS_COOL = 'supports_cool'

CONFIG_SCHEMA = cv.All(
    climate.CLIMATE_SCHEMA.extend({
        cv.GenerateID():
        cv.declare_id(YashimaClimate),
        cv.GenerateID(CONF_TRANSMITTER_ID):
        cv.use_id(remote_transmitter.RemoteTransmitterComponent),
        cv.Optional(CONF_SUPPORTS_COOL, default=True):
        cv.boolean,
        cv.Optional(CONF_SUPPORTS_HEAT, default=True):
        cv.boolean,
        cv.Optional(CONF_SENSOR):
        cv.use_id(sensor.Sensor),
    }).extend(cv.COMPONENT_SCHEMA))


def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    yield cg.register_component(var, config)
    yield climate.register_climate(var, config)
Пример #21
0

def validate_full_update_every_only_type_a(value):
    if CONF_FULL_UPDATE_EVERY not in value:
        return value
    if MODELS[value[CONF_MODEL]][0] == "b":
        raise cv.Invalid(
            "The 'full_update_every' option is only available for models "
            "'1.54in', '1.54inV2', '2.13in', '2.90in', and '2.90inV2'.")
    return value


CONFIG_SCHEMA = cv.All(
    display.FULL_DISPLAY_SCHEMA.extend({
        cv.GenerateID():
        cv.declare_id(WaveshareEPaper),
        cv.Required(CONF_DC_PIN):
        pins.gpio_output_pin_schema,
        cv.Required(CONF_MODEL):
        cv.one_of(*MODELS, lower=True),
        cv.Optional(CONF_RESET_PIN):
        pins.gpio_output_pin_schema,
        cv.Optional(CONF_BUSY_PIN):
        pins.gpio_input_pin_schema,
        cv.Optional(CONF_FULL_UPDATE_EVERY):
        cv.uint32_t,
    }).extend(cv.polling_component_schema("1s")).extend(
        spi.spi_device_schema()),
    validate_full_update_every_only_type_a,
    cv.has_at_most_one_key(CONF_PAGES, CONF_LAMBDA),
)
Пример #22
0
CONF_DOUT_PIN = "dout_pin"

HX711Gain = hx711_ns.enum("HX711Gain")
GAINS = {
    128: HX711Gain.HX711_GAIN_128,
    32: HX711Gain.HX711_GAIN_32,
    64: HX711Gain.HX711_GAIN_64,
}

CONFIG_SCHEMA = (sensor.sensor_schema(
    icon=ICON_SCALE,
    accuracy_decimals=0,
    state_class=STATE_CLASS_MEASUREMENT,
).extend({
    cv.GenerateID(): cv.declare_id(HX711Sensor),
    cv.Required(CONF_DOUT_PIN): pins.gpio_input_pin_schema,
    cv.Required(CONF_CLK_PIN): pins.gpio_output_pin_schema,
    cv.Optional(CONF_GAIN, default=128): cv.enum(GAINS, int=True),
}).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)

    dout_pin = await cg.gpio_pin_expression(config[CONF_DOUT_PIN])
    cg.add(var.set_dout_pin(dout_pin))
    sck_pin = await cg.gpio_pin_expression(config[CONF_CLK_PIN])
    cg.add(var.set_sck_pin(sck_pin))
Пример #23
0
        if update_interval.total_minutes > 30:
            raise cv.Invalid("Maximum update interval is 30min")
    elif value.get(CONF_RX_ONLY) and CONF_UPDATE_INTERVAL in value:
        # update_interval does not affect anything in rx-only mode, let's warn user about
        # that
        raise cv.Invalid(
            "update_interval has no effect in rx_only mode. Please remove it.",
            path=["update_interval"],
        )
    return value


CONFIG_SCHEMA = cv.All(
    cv.Schema(
        {
            cv.GenerateID(): cv.declare_id(SDS011Component),
            cv.Optional(CONF_PM_2_5): sensor.sensor_schema(
                unit_of_measurement=UNIT_MICROGRAMS_PER_CUBIC_METER,
                icon=ICON_CHEMICAL_WEAPON,
                accuracy_decimals=1,
                device_class=DEVICE_CLASS_PM25,
                state_class=STATE_CLASS_MEASUREMENT,
            ),
            cv.Optional(CONF_PM_10_0): sensor.sensor_schema(
                unit_of_measurement=UNIT_MICROGRAMS_PER_CUBIC_METER,
                icon=ICON_CHEMICAL_WEAPON,
                accuracy_decimals=1,
                device_class=DEVICE_CLASS_PM10,
                state_class=STATE_CLASS_MEASUREMENT,
            ),
            cv.Optional(CONF_RX_ONLY, default=False): cv.boolean,
Пример #24
0
    UNIT_CELSIUS,
    UNIT_PERCENT,
    UNIT_VOLT,
)

CODEOWNERS = ["@ahpohl"]

DEPENDENCIES = ["esp32_ble_tracker"]

atc_mithermometer_ns = cg.esphome_ns.namespace("atc_mithermometer")
ATCMiThermometer = atc_mithermometer_ns.class_(
    "ATCMiThermometer", esp32_ble_tracker.ESPBTDeviceListener, cg.Component)

CONFIG_SCHEMA = (cv.Schema({
    cv.GenerateID():
    cv.declare_id(ATCMiThermometer),
    cv.Required(CONF_MAC_ADDRESS):
    cv.mac_address,
    cv.Optional(CONF_TEMPERATURE):
    sensor.sensor_schema(
        unit_of_measurement=UNIT_CELSIUS,
        accuracy_decimals=1,
        device_class=DEVICE_CLASS_TEMPERATURE,
        state_class=STATE_CLASS_MEASUREMENT,
    ),
    cv.Optional(CONF_HUMIDITY):
    sensor.sensor_schema(
        unit_of_measurement=UNIT_PERCENT,
        accuracy_decimals=0,
        device_class=DEVICE_CLASS_HUMIDITY,
        state_class=STATE_CLASS_MEASUREMENT,
Пример #25
0
BLESensor = ble_client_ns.class_(
    "BLESensor", sensor.Sensor, cg.PollingComponent, ble_client.BLEClientNode
)
BLESensorNotifyTrigger = ble_client_ns.class_(
    "BLESensorNotifyTrigger", automation.Trigger.template(cg.float_)
)

CONFIG_SCHEMA = cv.All(
    sensor.sensor_schema(
        accuracy_decimals=0,
        state_class=STATE_CLASS_NONE,
    )
    .extend(
        {
            cv.GenerateID(): cv.declare_id(BLESensor),
            cv.Required(CONF_SERVICE_UUID): esp32_ble_tracker.bt_uuid,
            cv.Required(CONF_CHARACTERISTIC_UUID): esp32_ble_tracker.bt_uuid,
            cv.Optional(CONF_DESCRIPTOR_UUID): esp32_ble_tracker.bt_uuid,
            cv.Optional(CONF_LAMBDA): cv.returning_lambda,
            cv.Optional(CONF_NOTIFY, default=False): cv.boolean,
            cv.Optional(CONF_ON_NOTIFY): automation.validate_automation(
                {
                    cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(
                        BLESensorNotifyTrigger
                    ),
                }
            ),
        }
    )
    .extend(cv.polling_component_schema("60s"))
Пример #26
0
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import sensor, modbus
from esphome.const import CONF_CURRENT, CONF_ID, CONF_POWER, CONF_VOLTAGE, \
    CONF_FREQUENCY, UNIT_VOLT, ICON_FLASH, UNIT_AMPERE, UNIT_WATT, UNIT_EMPTY, \
    ICON_POWER, CONF_POWER_FACTOR, ICON_CURRENT_AC, UNIT_HERTZ, \
    CONF_ENERGY, UNIT_WATT_HOURS, ICON_COUNTER

AUTO_LOAD = ['modbus']

nilanac_ns = cg.esphome_ns.namespace('nilan')
NILAN = nilanac_ns.class_('NILAN', cg.PollingComponent, modbus.ModbusDevice)

CONFIG_SCHEMA = cv.Schema({
    cv.GenerateID():
    cv.declare_id(NILAN),
    cv.Optional(CONF_VOLTAGE):
    sensor.sensor_schema(UNIT_VOLT, ICON_FLASH, 1),
    cv.Optional(CONF_CURRENT):
    sensor.sensor_schema(UNIT_AMPERE, ICON_CURRENT_AC, 3),
    cv.Optional(CONF_POWER):
    sensor.sensor_schema(UNIT_WATT, ICON_POWER, 1),
    cv.Optional(CONF_ENERGY):
    sensor.sensor_schema(UNIT_WATT_HOURS, ICON_COUNTER, 0),
    cv.Optional(CONF_FREQUENCY):
    sensor.sensor_schema(UNIT_HERTZ, ICON_CURRENT_AC, 1),
    cv.Optional(CONF_POWER_FACTOR):
    sensor.sensor_schema(UNIT_EMPTY, ICON_FLASH, 2),
}).extend(cv.polling_component_schema('60s')).extend(
    modbus.modbus_device_schema(0x30))
Пример #27
0
from esphome.const import CONF_ICON, CONF_ID, CONF_STATUS
from . import DalyBmsComponent, CONF_BMS_DALY_ID

ICON_CAR_BATTERY = "mdi:car-battery"

TYPES = [
    CONF_STATUS,
]

CONFIG_SCHEMA = cv.All(
    cv.Schema(
        {
            cv.GenerateID(CONF_BMS_DALY_ID): cv.use_id(DalyBmsComponent),
            cv.Optional(CONF_STATUS): text_sensor.TEXT_SENSOR_SCHEMA.extend(
                {
                    cv.GenerateID(): cv.declare_id(text_sensor.TextSensor),
                    cv.Optional(CONF_ICON, default=ICON_CAR_BATTERY): cv.icon,
                }
            ),
        }
    ).extend(cv.COMPONENT_SCHEMA)
)


async def setup_conf(config, key, hub):
    if key in config:
        conf = config[key]
        sens = cg.new_Pvariable(conf[CONF_ID])
        await text_sensor.register_text_sensor(sens, conf)
        cg.add(getattr(hub, f"set_{key}_text_sensor")(sens))
Пример #28
0
    UNIT_PERCENT,
    CONF_BINDKEY,
)

DEPENDENCIES = ["esp32_ble_tracker"]
AUTO_LOAD = ["xiaomi_ble"]

xiaomi_cgd1_ns = cg.esphome_ns.namespace("xiaomi_cgd1")
XiaomiCGD1 = xiaomi_cgd1_ns.class_(
    "XiaomiCGD1", esp32_ble_tracker.ESPBTDeviceListener, cg.Component
)

CONFIG_SCHEMA = (
    cv.Schema(
        {
            cv.GenerateID(): cv.declare_id(XiaomiCGD1),
            cv.Required(CONF_BINDKEY): cv.bind_key,
            cv.Required(CONF_MAC_ADDRESS): cv.mac_address,
            cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema(
                UNIT_CELSIUS, ICON_EMPTY, 1, DEVICE_CLASS_TEMPERATURE
            ),
            cv.Optional(CONF_HUMIDITY): sensor.sensor_schema(
                UNIT_PERCENT, ICON_EMPTY, 1, DEVICE_CLASS_HUMIDITY
            ),
            cv.Optional(CONF_BATTERY_LEVEL): sensor.sensor_schema(
                UNIT_PERCENT, ICON_EMPTY, 0, DEVICE_CLASS_BATTERY
            ),
        }
    )
    .extend(esp32_ble_tracker.ESP_BLE_DEVICE_SCHEMA)
    .extend(cv.COMPONENT_SCHEMA)
Пример #29
0
    CONF_CLOSE_DURATION,
    CONF_CLOSE_ENDSTOP,
    CONF_ID,
    CONF_OPEN_ACTION,
    CONF_OPEN_DURATION,
    CONF_OPEN_ENDSTOP,
    CONF_STOP_ACTION,
    CONF_MAX_DURATION,
)

endstop_ns = cg.esphome_ns.namespace("endstop")
EndstopCover = endstop_ns.class_("EndstopCover", cover.Cover, cg.Component)

CONFIG_SCHEMA = cover.COVER_SCHEMA.extend({
    cv.GenerateID():
    cv.declare_id(EndstopCover),
    cv.Required(CONF_STOP_ACTION):
    automation.validate_automation(single=True),
    cv.Required(CONF_OPEN_ENDSTOP):
    cv.use_id(binary_sensor.BinarySensor),
    cv.Required(CONF_OPEN_ACTION):
    automation.validate_automation(single=True),
    cv.Required(CONF_OPEN_DURATION):
    cv.positive_time_period_milliseconds,
    cv.Required(CONF_CLOSE_ACTION):
    automation.validate_automation(single=True),
    cv.Required(CONF_CLOSE_ENDSTOP):
    cv.use_id(binary_sensor.BinarySensor),
    cv.Required(CONF_CLOSE_DURATION):
    cv.positive_time_period_milliseconds,
    cv.Optional(CONF_MAX_DURATION):
Пример #30
0
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import button
from esphome.const import (
    CONF_ID,
    DEVICE_CLASS_RESTART,
    ENTITY_CATEGORY_CONFIG,
)

restart_ns = cg.esphome_ns.namespace("restart")
RestartButton = restart_ns.class_("RestartButton", button.Button, cg.Component)

CONFIG_SCHEMA = (button.button_schema(
    device_class=DEVICE_CLASS_RESTART,
    entity_category=ENTITY_CATEGORY_CONFIG).extend({
        cv.GenerateID():
        cv.declare_id(RestartButton)
    }).extend(cv.COMPONENT_SCHEMA))


async def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    await cg.register_component(var, config)
    await button.register_button(var, config)