Esempio n. 1
0
from . import cpp_types as t


def maybe_simple_value_or_default(*validators, **kwargs):
    key = kwargs.pop('key', ehc.CONF_VALUE)
    validator = cv.All(*validators)

    def validate(value):
        if isinstance(value, dict):
            return validator(value)
        return validator({key: value})

    return validate


@automation.register_action(c.ACTION_ABORT, t.TerminalAction, cv.All({}))
@coroutine
def abort_action_to_code(config, action_id, template_arg, args):
    text = "sendaction->stop(); return true;"
    lambda_ = yield cg.process_lambda(Lambda(text), args, return_type=cg.bool_)
    yield cg.new_Pvariable(action_id, template_arg, lambda_)


@automation.register_action(c.ACTION_RETRY_SEND, t.TerminalAction,
                            maybe_simple_value_or_default(
                                cv.Schema({
                                    cv.Optional(c.CONF_MAX_RETRIES, default=2):
                                    cv.int_,
                                }),
                                key=c.CONF_MAX_RETRIES))
@coroutine
Esempio n. 2
0
 cv.declare_id(Sensor),
 cv.Optional(CONF_UNIT_OF_MEASUREMENT):
 unit_of_measurement,
 cv.Optional(CONF_ICON):
 icon,
 cv.Optional(CONF_ACCURACY_DECIMALS):
 accuracy_decimals,
 cv.Optional(CONF_DEVICE_CLASS):
 device_class,
 cv.Optional(CONF_STATE_CLASS):
 validate_state_class,
 cv.Optional(CONF_FORCE_UPDATE, default=False):
 cv.boolean,
 cv.Optional(CONF_EXPIRE_AFTER):
 cv.All(
     cv.requires_component("mqtt"),
     cv.Any(None, cv.positive_time_period_milliseconds),
 ),
 cv.Optional(CONF_FILTERS):
 validate_filters,
 cv.Optional(CONF_ON_VALUE):
 automation.validate_automation({
     cv.GenerateID(CONF_TRIGGER_ID):
     cv.declare_id(SensorStateTrigger),
 }),
 cv.Optional(CONF_ON_RAW_VALUE):
 automation.validate_automation({
     cv.GenerateID(CONF_TRIGGER_ID):
     cv.declare_id(SensorRawStateTrigger),
 }),
 cv.Optional(CONF_ON_VALUE_RANGE):
 automation.validate_automation(
Esempio n. 3
0
        )

    return config


CONFIG_SCHEMA = cv.All(
    sensor.sensor_schema(accuracy_decimals=2, ).extend({
        cv.GenerateID():
        cv.declare_id(NextionSensor),
        cv.Optional(CONF_PRECISION, default=0):
        cv.int_range(min=0, max=8),
        cv.Optional(CONF_WAVE_CHANNEL_ID):
        CheckWaveID,
        cv.Optional(CONF_COMPONENT_ID):
        cv.uint8_t,
        cv.Optional(CONF_WAVE_MAX_LENGTH, default=255):
        cv.int_range(min=1, max=1024),
        cv.Optional(CONF_WAVE_MAX_VALUE, default=100):
        cv.int_range(min=1, max=1024),
        cv.Optional(CONF_WAVEFORM_SEND_LAST_VALUE, default=True):
        cv.boolean,
    }).extend(CONFIG_SENSOR_COMPONENT_SCHEMA).extend(
        cv.polling_component_schema("never")),
    cv.has_exactly_one_key(CONF_COMPONENT_ID, CONF_COMPONENT_NAME,
                           CONF_VARIABLE_NAME),
    _validate,
)


async def to_code(config):

    hub = await cg.get_variable(config[CONF_NEXTION_ID])
Esempio n. 4
0
MAX31865Sensor = max31865_ns.class_("MAX31865Sensor", sensor.Sensor,
                                    cg.PollingComponent, spi.SPIDevice)

MAX31865ConfigFilter = max31865_ns.enum("MAX31865ConfigFilter")
FILTER = {
    "50HZ": MAX31865ConfigFilter.FILTER_50HZ,
    "60HZ": MAX31865ConfigFilter.FILTER_60HZ,
}

CONFIG_SCHEMA = (sensor.sensor_schema(
    UNIT_CELSIUS, ICON_EMPTY, 2, DEVICE_CLASS_TEMPERATURE,
    STATE_CLASS_MEASUREMENT).extend({
        cv.GenerateID():
        cv.declare_id(MAX31865Sensor),
        cv.Required(CONF_REFERENCE_RESISTANCE):
        cv.All(cv.resistance, cv.Range(min=100, max=10000)),
        cv.Required(CONF_RTD_NOMINAL_RESISTANCE):
        cv.All(cv.resistance, cv.Range(min=100, max=1000)),
        cv.Optional(CONF_MAINS_FILTER, default="60HZ"):
        cv.enum(FILTER, upper=True, space=""),
        cv.Optional(CONF_RTD_WIRES, default=4):
        cv.int_range(min=2, max=4),
    }).extend(cv.polling_component_schema("60s")).extend(
        spi.spi_device_schema()))


async def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    await cg.register_component(var, config)
    await spi.register_spi_device(var, config)
    await sensor.register_sensor(var, config)
Esempio n. 5
0
        # Copy over all fields to subfolder:
        trace = {}
        for f in fields:
            if f in config:
                trace[f] = config.pop(f)
        config[subfolder] = cv.ensure_list(subschema)(trace)
    return config


def _relocate_trace(config):
    return _relocate_fields_to_subfolder(config, CONF_TRACES,
                                         GRAPH_TRACE_SCHEMA)


CONFIG_SCHEMA = cv.All(
    GRAPH_SCHEMA,
    _relocate_trace,
)


async def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    cg.add(var.set_duration(config[CONF_DURATION]))
    cg.add(var.set_width(config[CONF_WIDTH]))
    cg.add(var.set_height(config[CONF_HEIGHT]))
    await cg.register_component(var, config)

    # Graph options
    if CONF_X_GRID in config:
        cg.add(var.set_grid_x(config[CONF_X_GRID]))
    if CONF_Y_GRID in config:
        cg.add(var.set_grid_y(config[CONF_Y_GRID]))
Esempio n. 6
0
                           CONF_RESET_PIN, CONF_CS_PIN, CONF_CONTRAST)

DEPENDENCIES = ['spi']

pcd8544_ns = cg.esphome_ns.namespace('pcd8544')
PCD8544 = pcd8544_ns.class_('PCD8544', cg.PollingComponent,
                            display.DisplayBuffer, spi.SPIDevice)

CONFIG_SCHEMA = cv.All(
    display.FULL_DISPLAY_SCHEMA.extend({
        cv.GenerateID():
        cv.declare_id(PCD8544),
        cv.Required(CONF_DC_PIN):
        pins.gpio_output_pin_schema,
        cv.Required(CONF_RESET_PIN):
        pins.gpio_output_pin_schema,
        cv.Required(CONF_CS_PIN):
        pins.gpio_output_pin_schema,  # CE
        cv.Optional(CONF_CONTRAST, default=0x7f):
        cv.int_,
    }).extend(cv.polling_component_schema('1s')).extend(
        spi.spi_device_schema()),
    cv.has_at_most_one_key(CONF_PAGES, CONF_LAMBDA))


def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])

    yield cg.register_component(var, config)
    yield display.register_display(var, config)
    yield spi.register_spi_device(var, config)
Esempio n. 7
0
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome import pins
from esphome.components import spi, st7735_base
from esphome.const import CONF_DC_PIN, CONF_ID, CONF_LAMBDA, CONF_PAGES

AUTO_LOAD = ['st7735_base']
DEPENDENCIES = ['spi']

st7735_spi = cg.esphome_ns.namespace('st7735_spi')
SPIST7735 = st7735_spi.class_('SPIST7735', st7735_base.ST7735, spi.SPIDevice)

CONFIG_SCHEMA = cv.All(
    st7735_base.ST7735_SCHEMA.extend({
        cv.GenerateID():
        cv.declare_id(SPIST7735),
        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))


def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    yield st7735_base.setup_st7735(var, config)
    yield spi.register_spi_device(var, config)

    dc = yield cg.gpio_pin_expression(config[CONF_DC_PIN])
    cg.add(var.set_dc_pin(dc))
Esempio n. 8
0
CONF_SPEED_DATAPOINT = "speed_datapoint"
CONF_OSCILLATION_DATAPOINT = "oscillation_datapoint"
CONF_DIRECTION_DATAPOINT = "direction_datapoint"

TuyaFan = tuya_ns.class_("TuyaFan", cg.Component)

CONFIG_SCHEMA = cv.All(
    fan.FAN_SCHEMA.extend({
        cv.GenerateID(CONF_OUTPUT_ID):
        cv.declare_id(TuyaFan),
        cv.GenerateID(CONF_TUYA_ID):
        cv.use_id(Tuya),
        cv.Optional(CONF_OSCILLATION_DATAPOINT):
        cv.uint8_t,
        cv.Optional(CONF_SPEED_DATAPOINT):
        cv.uint8_t,
        cv.Optional(CONF_SWITCH_DATAPOINT):
        cv.uint8_t,
        cv.Optional(CONF_DIRECTION_DATAPOINT):
        cv.uint8_t,
        cv.Optional(CONF_SPEED_COUNT, default=3):
        cv.int_range(min=1, max=256),
    }).extend(cv.COMPONENT_SCHEMA),
    cv.has_at_least_one_key(CONF_SPEED_DATAPOINT, CONF_SWITCH_DATAPOINT),
)


def to_code(config):
    parent = yield cg.get_variable(config[CONF_TUYA_ID])
    state = yield fan.create_fan_state(config)
Esempio n. 9
0
        device_class=DEVICE_CLASS_TEMPERATURE,
        state_class=STATE_CLASS_MEASUREMENT,
    ),
    cv.Optional(CONF_HUMIDITY):
    sensor.sensor_schema(
        unit_of_measurement=UNIT_PERCENT,
        icon=ICON_WATER_PERCENT,
        accuracy_decimals=2,
        device_class=DEVICE_CLASS_HUMIDITY,
        state_class=STATE_CLASS_MEASUREMENT,
    ),
    cv.Optional(CONF_AUTOMATIC_SELF_CALIBRATION, default=True):
    cv.boolean,
    cv.Optional(CONF_ALTITUDE_COMPENSATION, default="0m"):
    cv.All(
        cv.float_with_unit("altitude", "(m|m a.s.l.|MAMSL|MASL)"),
        cv.int_range(min=0, max=0xFFFF, max_included=False),
    ),
    cv.Optional(CONF_AMBIENT_PRESSURE_COMPENSATION):
    cv.pressure,
    cv.Optional(CONF_TEMPERATURE_OFFSET, default="4°C"):
    cv.temperature,
    cv.Optional(CONF_AMBIENT_PRESSURE_COMPENSATION_SOURCE):
    cv.use_id(sensor.Sensor),
}).extend(cv.polling_component_schema("60s")).extend(
    i2c.i2c_device_schema(0x62)))

SENSOR_MAP = {
    CONF_CO2: "set_co2_sensor",
    CONF_TEMPERATURE: "set_temperature_sensor",
    CONF_HUMIDITY: "set_humidity_sensor",
}
Esempio n. 10
0

CONF_DRIVE_STRENGTH = "drive_strength"
ESP32_PIN_SCHEMA = cv.All(
    {
        cv.GenerateID():
        _choose_pin_declaration,
        cv.Required(CONF_NUMBER):
        validate_gpio_pin,
        cv.Optional(CONF_MODE, default={}):
        cv.Schema({
            cv.Optional(CONF_INPUT, default=False): cv.boolean,
            cv.Optional(CONF_OUTPUT, default=False): cv.boolean,
            cv.Optional(CONF_OPEN_DRAIN, default=False): cv.boolean,
            cv.Optional(CONF_PULLUP, default=False): cv.boolean,
            cv.Optional(CONF_PULLDOWN, default=False): cv.boolean,
        }),
        cv.Optional(CONF_INVERTED, default=False):
        cv.boolean,
        cv.SplitDefault(CONF_DRIVE_STRENGTH, esp32_idf="20mA"):
        cv.All(
            cv.only_with_esp_idf,
            cv.float_with_unit("current", "mA", optional_unit=True),
            cv.enum(DRIVE_STRENGTHS),
        ),
    },
    validate_supports,
)


@pins.PIN_SCHEMA_REGISTRY.register("esp32", ESP32_PIN_SCHEMA)
Esempio n. 11
0
}

entry = {
    cv.Required(CONF_BINARY_SENSOR): cv.use_id(binary_sensor.BinarySensor),
    cv.Required(CONF_VALUE): cv.float_,
}

CONFIG_SCHEMA = cv.typed_schema(
    {
        CONF_GROUP:
        sensor.sensor_schema(UNIT_EMPTY, ICON_CHECK_CIRCLE_OUTLINE, 0,
                             DEVICE_CLASS_EMPTY).extend({
                                 cv.GenerateID():
                                 cv.declare_id(BinarySensorMap),
                                 cv.Required(CONF_CHANNELS):
                                 cv.All(cv.ensure_list(entry),
                                        cv.Length(min=1)),
                             }),
    },
    lower=True,
)


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

    constant = SENSOR_MAP_TYPES[config[CONF_TYPE]]
    cg.add(var.set_sensor_type(constant))

    for ch in config[CONF_CHANNELS]:
Esempio n. 12
0
                             cv.Optional(CONF_OVERSAMPLING, default="16X"):
                             cv.enum(OVERSAMPLING_OPTIONS, upper=True),
                         }),
    cv.Optional(CONF_GAS_RESISTANCE):
    sensor.sensor_schema(UNIT_OHM, ICON_GAS_CYLINDER, 1, DEVICE_CLASS_EMPTY),
    cv.Optional(CONF_IIR_FILTER, default="OFF"):
    cv.enum(IIR_FILTER_OPTIONS, upper=True),
    cv.Optional(CONF_HEATER):
    cv.Any(
        None,
        cv.All(
            cv.Schema({
                cv.Optional(CONF_TEMPERATURE, default=320):
                cv.int_range(min=200, max=400),
                cv.Optional(CONF_DURATION, default="150ms"):
                cv.All(
                    cv.positive_time_period_milliseconds,
                    cv.Range(max=core.TimePeriod(milliseconds=4032)),
                ),
            }),
            cv.has_at_least_one_key(CONF_TEMPERATURE, CONF_DURATION),
        ),
    ),
}).extend(cv.polling_component_schema("60s")).extend(
    i2c.i2c_device_schema(0x76)))


def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    yield cg.register_component(var, config)
    yield i2c.register_i2c_device(var, config)
Esempio n. 13
0
        config[CONF_USE_ADDRESS] = use_address

    return config


CONF_OUTPUT_POWER = 'output_power'
CONFIG_SCHEMA = cv.All(cv.Schema({
    cv.GenerateID(): cv.declare_id(WiFiComponent),
    cv.Optional(CONF_NETWORKS): cv.ensure_list(WIFI_NETWORK_STA),

    cv.Optional(CONF_SSID): cv.ssid,
    cv.Optional(CONF_PASSWORD): validate_password,
    cv.Optional(CONF_MANUAL_IP): STA_MANUAL_IP_SCHEMA,

    cv.Optional(CONF_AP): WIFI_NETWORK_AP,
    cv.Optional(CONF_DOMAIN, default='.local'): cv.domain_name,
    cv.Optional(CONF_REBOOT_TIMEOUT, default='15min'): cv.positive_time_period_milliseconds,
    cv.SplitDefault(CONF_POWER_SAVE_MODE, esp8266='none', esp32='light'):
        cv.enum(WIFI_POWER_SAVE_MODES, upper=True),
    cv.Optional(CONF_FAST_CONNECT, default=False): cv.boolean,
    cv.Optional(CONF_USE_ADDRESS): cv.string_strict,
    cv.SplitDefault(CONF_OUTPUT_POWER, esp8266=20.0): cv.All(
        cv.decibel, cv.float_range(min=10.0, max=20.5)),

    cv.Optional('hostname'): cv.invalid("The hostname option has been removed in 1.11.0"),
}), validate)


def safe_ip(ip):
    if ip is None:
        return IPAddress(0, 0, 0, 0)
    return IPAddress(*ip.args)
Esempio n. 14
0
                "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_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):
        cv.positive_not_null_int,
    }).extend(cv.COMPONENT_SCHEMA), validate, validate_method_pin)


def to_code(config):
    has_white = 'W' in config[CONF_TYPE]
    template = cg.TemplateArguments(
        getattr(cg.global_ns, format_method(config)))
Esempio n. 15
0
        raise cv.Invalid("Include has invalid file extension {} - valid extensions are {}"
                         "".format(ext, ', '.join(VALID_INCLUDE_EXTS)))
    return value


CONFIG_SCHEMA = cv.Schema({
    cv.Required(CONF_NAME): cv.valid_name,
    cv.Required(CONF_PLATFORM): cv.one_of('ESP8266', 'ESP32', upper=True),
    cv.Required(CONF_BOARD): validate_board,
    cv.Optional(CONF_COMMENT): cv.string,
    cv.Optional(CONF_ARDUINO_VERSION, default='recommended'): validate_arduino_version,
    cv.Optional(CONF_BUILD_PATH, default=default_build_path): cv.string,
    cv.Optional(CONF_PLATFORMIO_OPTIONS, default={}): cv.Schema({
        cv.string_strict: cv.Any([cv.string], cv.string),
    }),
    cv.SplitDefault(CONF_ESP8266_RESTORE_FROM_FLASH, esp8266=False): cv.All(cv.only_on_esp8266,
                                                                            cv.boolean),

    cv.SplitDefault(CONF_BOARD_FLASH_MODE, esp8266='dout'): cv.one_of(*BUILD_FLASH_MODES,
                                                                      lower=True),
    cv.Optional(CONF_ON_BOOT): automation.validate_automation({
        cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(StartupTrigger),
        cv.Optional(CONF_PRIORITY, default=600.0): cv.float_,
    }),
    cv.Optional(CONF_ON_SHUTDOWN): automation.validate_automation({
        cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(ShutdownTrigger),
    }),
    cv.Optional(CONF_ON_LOOP): automation.validate_automation({
        cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(LoopTrigger),
    }),
    cv.Optional(CONF_INCLUDES, default=[]): cv.ensure_list(valid_include),
    cv.Optional(CONF_LIBRARIES, default=[]): cv.ensure_list(cv.string_strict),
Esempio n. 16
0
StateTrigger = climate_ns.class_("StateTrigger", automation.Trigger.template())

CLIMATE_SCHEMA = cv.ENTITY_BASE_SCHEMA.extend(
    cv.MQTT_COMMAND_COMPONENT_SCHEMA).extend({
        cv.GenerateID():
        cv.declare_id(Climate),
        cv.OnlyWith(CONF_MQTT_ID, "mqtt"):
        cv.declare_id(mqtt.MQTTClimateComponent),
        cv.Optional(CONF_VISUAL, default={}):
        cv.Schema({
            cv.Optional(CONF_MIN_TEMPERATURE): cv.temperature,
            cv.Optional(CONF_MAX_TEMPERATURE): cv.temperature,
            cv.Optional(CONF_TEMPERATURE_STEP): cv.temperature,
        }),
        cv.Optional(CONF_ACTION_STATE_TOPIC):
        cv.All(cv.requires_component("mqtt"), cv.publish_topic),
        cv.Optional(CONF_AWAY_COMMAND_TOPIC):
        cv.All(cv.requires_component("mqtt"), cv.publish_topic),
        cv.Optional(CONF_AWAY_STATE_TOPIC):
        cv.All(cv.requires_component("mqtt"), cv.publish_topic),
        cv.Optional(CONF_CURRENT_TEMPERATURE_STATE_TOPIC):
        cv.All(cv.requires_component("mqtt"), cv.publish_topic),
        cv.Optional(CONF_FAN_MODE_COMMAND_TOPIC):
        cv.All(cv.requires_component("mqtt"), cv.publish_topic),
        cv.Optional(CONF_FAN_MODE_STATE_TOPIC):
        cv.All(cv.requires_component("mqtt"), cv.publish_topic),
        cv.Optional(CONF_MODE_COMMAND_TOPIC):
        cv.All(cv.requires_component("mqtt"), cv.publish_topic),
        cv.Optional(CONF_MODE_STATE_TOPIC):
        cv.All(cv.requires_component("mqtt"), cv.publish_topic),
        cv.Optional(CONF_SWING_MODE_COMMAND_TOPIC):
Esempio n. 17
0
    CONF_VALUE_TYPE,
    CONF_WRITE_LAMBDA,
)

DEPENDENCIES = ["modbus_controller"]
CODEOWNERS = ["@martgras"]

ModbusOutput = modbus_controller_ns.class_("ModbusOutput", cg.Component,
                                           output.FloatOutput, SensorItem)

CONFIG_SCHEMA = cv.All(
    output.FLOAT_OUTPUT_SCHEMA.extend(ModbusItemBaseSchema).extend({
        cv.GenerateID():
        cv.declare_id(ModbusOutput),
        cv.Optional(CONF_WRITE_LAMBDA):
        cv.returning_lambda,
        cv.Optional(CONF_MULTIPLY, default=1.0):
        cv.float_,
    }),
    validate_modbus_register,
)


async def to_code(config):
    byte_offset, reg_count = modbus_calc_properties(config)
    var = cg.new_Pvariable(
        config[CONF_ID],
        config[CONF_ADDRESS],
        byte_offset,
        config[CONF_VALUE_TYPE],
        reg_count,
Esempio n. 18
0
CODEOWNERS = ["@justfalter"]

addressable_light_ns = cg.esphome_ns.namespace("addressable_light")
AddressableLightDisplay = addressable_light_ns.class_(
    "AddressableLightDisplay", display.DisplayBuffer, cg.PollingComponent)

CONFIG_SCHEMA = cv.All(
    display.FULL_DISPLAY_SCHEMA.extend({
        cv.GenerateID():
        cv.declare_id(AddressableLightDisplay),
        cv.Required(CONF_ADDRESSABLE_LIGHT_ID):
        cv.use_id(light.AddressableLightState),
        cv.Required(CONF_WIDTH):
        cv.positive_int,
        cv.Required(CONF_HEIGHT):
        cv.positive_int,
        cv.Optional(CONF_UPDATE_INTERVAL, default="16ms"):
        cv.positive_time_period_milliseconds,
        cv.Optional(CONF_PIXEL_MAPPER):
        cv.returning_lambda,
    }),
    cv.has_at_most_one_key(CONF_PAGES, CONF_LAMBDA),
)


async def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    wrapped_light = await cg.get_variable(config[CONF_ADDRESSABLE_LIGHT_ID])
    cg.add(var.set_width(config[CONF_WIDTH]))
    cg.add(var.set_height(config[CONF_HEIGHT]))
Esempio n. 19
0
        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),
)


async def to_code(config):
    model_type, model = MODELS[config[CONF_MODEL]]
    if model_type == "a":
        rhs = WaveshareEPaperTypeA.new(model)
Esempio n. 20
0
        value[CONF_ID])
    return value


CONFIG_SCHEMA = automation.validate_automation(
    {
        # Don't declare id as cv.declare_id yet, because the ID type
        # dpeends on the mode. Will be checked later with assign_declare_id
        cv.Required(CONF_ID):
        cv.string_strict,
        cv.Optional(CONF_MODE, default=CONF_SINGLE):
        cv.one_of(*SCRIPT_MODES, lower=True),
        cv.Optional(CONF_MAX_RUNS):
        cv.positive_int,
    },
    extra_validators=cv.All(check_max_runs, assign_declare_id),
)


def to_code(config):
    # Register all variables first, so that scripts can use other scripts
    triggers = []
    for conf in config:
        trigger = cg.new_Pvariable(conf[CONF_ID])
        # Add a human-readable name to the script
        cg.add(trigger.set_name(conf[CONF_ID].id))

        if CONF_MAX_RUNS in conf:
            cg.add(trigger.set_max_runs(conf[CONF_MAX_RUNS]))

        if conf[CONF_MODE] == CONF_QUEUED:
TM1651_BRIGHTNESS_OPTIONS = {
    1: TM1651Display.TM1651_BRIGHTNESS_LOW,
    2: TM1651Display.TM1651_BRIGHTNESS_MEDIUM,
    3: TM1651Display.TM1651_BRIGHTNESS_HIGH
}

CONFIG_SCHEMA = cv.Schema({
    cv.GenerateID():
    cv.declare_id(TM1651Display),
    cv.Required(CONF_CLK_PIN):
    pins.internal_gpio_output_pin_schema,
    cv.Required(CONF_DIO_PIN):
    pins.internal_gpio_output_pin_schema,
})

validate_level_percent = cv.All(cv.int_range(min=0, max=100))
validate_level = cv.All(cv.int_range(min=0, max=7))
validate_brightness = cv.enum(TM1651_BRIGHTNESS_OPTIONS, int=True)


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

    clk_pin = yield cg.gpio_pin_expression(config[CONF_CLK_PIN])
    cg.add(var.set_clk_pin(clk_pin))
    dio_pin = yield cg.gpio_pin_expression(config[CONF_DIO_PIN])
    cg.add(var.set_dio_pin(dio_pin))

    # https://platformio.org/lib/show/6865/TM1651
    cg.add_library('6865', '1.0.1')
Esempio n. 22
0
    "U_QWORD": 4,
    "U_QWORDU_R": 4,
    "S_QWORD": 4,
    "U_QWORD_R": 4,
    "FP32": 2,
    "FP32_R": 2,
}

MULTI_CONF = True

_LOGGER = logging.getLogger(__name__)

CONFIG_SCHEMA = cv.All(
    cv.Schema({
        cv.GenerateID():
        cv.declare_id(ModbusController),
        cv.Optional(CONF_COMMAND_THROTTLE, default="0ms"):
        cv.positive_time_period_milliseconds,
    }).extend(cv.polling_component_schema("60s")).extend(
        modbus.modbus_device_schema(0x01)))

ModbusItemBaseSchema = cv.Schema(
    {
        cv.GenerateID(CONF_MODBUS_CONTROLLER_ID):
        cv.use_id(ModbusController),
        cv.Optional(CONF_ADDRESS):
        cv.positive_int,
        cv.Optional(CONF_CUSTOM_COMMAND):
        cv.ensure_list(cv.hex_uint8_t),
        cv.Exclusive(
            CONF_OFFSET,
            "offset",
Esempio n. 23
0
    ),
    cv.Optional(CONF_METHOD, default="right"):
    cv.enum(TOTAL_DAILY_ENERGY_METHODS, lower=True),
}).extend(cv.COMPONENT_SCHEMA))

FINAL_VALIDATE_SCHEMA = cv.All(
    cv.Schema(
        {
            cv.Required(CONF_ID): cv.use_id(TotalDailyEnergy),
            cv.Optional(CONF_ICON): cv.icon,
            cv.Optional(CONF_UNIT_OF_MEASUREMENT):
            sensor.validate_unit_of_measurement,
            cv.Optional(CONF_ACCURACY_DECIMALS):
            sensor.validate_accuracy_decimals,
            cv.Required(CONF_POWER_ID): cv.use_id(sensor.Sensor),
        },
        extra=cv.ALLOW_EXTRA,
    ),
    inherit_property_from(CONF_ICON, CONF_POWER_ID),
    inherit_property_from(CONF_UNIT_OF_MEASUREMENT,
                          CONF_POWER_ID,
                          transform=inherit_unit_of_measurement),
    inherit_property_from(CONF_ACCURACY_DECIMALS,
                          CONF_POWER_ID,
                          transform=inherit_accuracy_decimals),
)


async def to_code(config):
    var = await sensor.new_sensor(config)
    await cg.register_component(var, config)
Esempio n. 24
0
 cv.All(
     cv.ensure_list(
         cv.Schema({
             cv.Optional(CONF_STATE, default=True):
             cv.boolean,
             cv.Optional(CONF_BRIGHTNESS, default=1.0):
             cv.percentage,
             cv.Optional(CONF_COLOR_BRIGHTNESS, default=1.0):
             cv.percentage,
             cv.Optional(CONF_RED, default=1.0):
             cv.percentage,
             cv.Optional(CONF_GREEN, default=1.0):
             cv.percentage,
             cv.Optional(CONF_BLUE, default=1.0):
             cv.percentage,
             cv.Optional(CONF_WHITE, default=1.0):
             cv.percentage,
             cv.Required(CONF_DURATION):
             cv.positive_time_period_milliseconds,
         }),
         cv.has_at_least_one_key(
             CONF_STATE,
             CONF_BRIGHTNESS,
             CONF_COLOR_BRIGHTNESS,
             CONF_RED,
             CONF_GREEN,
             CONF_BLUE,
             CONF_WHITE,
         ),
     ),
     cv.Length(min=2),
 ),
Esempio n. 25
0
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import i2c, pn532
from esphome.const import CONF_ID

AUTO_LOAD = ["pn532"]
CODEOWNERS = ["@OttoWinter", "@jesserockz"]
DEPENDENCIES = ["i2c"]

pn532_i2c_ns = cg.esphome_ns.namespace("pn532_i2c")
PN532I2C = pn532_i2c_ns.class_("PN532I2C", pn532.PN532, i2c.I2CDevice)

CONFIG_SCHEMA = cv.All(
    pn532.PN532_SCHEMA.extend({
        cv.GenerateID(): cv.declare_id(PN532I2C),
    }).extend(i2c.i2c_device_schema(0x24)))


async def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    await pn532.setup_pn532(var, config)
    await i2c.register_i2c_device(var, config)
Esempio n. 26
0
CONF_OUTDOOR_TEMPERATURE = "outdoor_temperature"
CONF_POWER_USAGE = "power_usage"
CONF_HUMIDITY_SETPOINT = "humidity_setpoint"
midea_ac_ns = cg.esphome_ns.namespace("midea_ac")
MideaAC = midea_ac_ns.class_("MideaAC", climate.Climate, cg.Component)

CONFIG_SCHEMA = cv.All(
    climate.CLIMATE_SCHEMA.extend(
        {
            cv.GenerateID(): cv.declare_id(MideaAC),
            cv.GenerateID(CONF_MIDEA_DONGLE_ID): cv.use_id(MideaDongle),
            cv.Optional(CONF_BEEPER, default=False): cv.boolean,
            cv.Optional(CONF_SWING_HORIZONTAL, default=False): cv.boolean,
            cv.Optional(CONF_SWING_BOTH, default=False): cv.boolean,
            cv.Optional(CONF_OUTDOOR_TEMPERATURE): sensor.sensor_schema(
                UNIT_CELSIUS, ICON_THERMOMETER, 0, DEVICE_CLASS_TEMPERATURE
            ),
            cv.Optional(CONF_POWER_USAGE): sensor.sensor_schema(
                UNIT_WATT, ICON_POWER, 0, DEVICE_CLASS_POWER
            ),
            cv.Optional(CONF_HUMIDITY_SETPOINT): sensor.sensor_schema(
                UNIT_PERCENT, ICON_WATER_PERCENT, 0, DEVICE_CLASS_HUMIDITY
            ),
        }
    ).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)
Esempio n. 27
0
                unit_of_measurement=UNIT_CELSIUS,
                icon=ICON_THERMOMETER,
                accuracy_decimals=2,
                device_class=DEVICE_CLASS_TEMPERATURE,
                state_class=STATE_CLASS_MEASUREMENT,
            ),
            cv.Optional(CONF_HUMIDITY): sensor.sensor_schema(
                unit_of_measurement=UNIT_PERCENT,
                icon=ICON_WATER_PERCENT,
                accuracy_decimals=2,
                device_class=DEVICE_CLASS_HUMIDITY,
                state_class=STATE_CLASS_MEASUREMENT,
            ),
            cv.Optional(CONF_AUTOMATIC_SELF_CALIBRATION, default=True): cv.boolean,
            cv.Optional(CONF_ALTITUDE_COMPENSATION, default="0m"): cv.All(
                cv.float_with_unit("altitude", "(m|m a.s.l.|MAMSL|MASL)"),
                cv.int_range(min=0, max=0xFFFF, max_included=False),
            ),
            cv.Optional(CONF_AMBIENT_PRESSURE_COMPENSATION): cv.pressure,
            cv.Optional(CONF_TEMPERATURE_OFFSET, default="4°C"): cv.temperature,
            cv.Optional(CONF_AMBIENT_PRESSURE_COMPENSATION_SOURCE): cv.use_id(
                sensor.Sensor
            ),
        }
    )
    .extend(cv.polling_component_schema("60s"))
    .extend(i2c.i2c_device_schema(0x62))
)

SENSOR_MAP = {
    CONF_CO2: "set_co2_sensor",
    CONF_TEMPERATURE: "set_temperature_sensor",
Esempio n. 28
0
    cg.PollingComponent,
    ble_client.BLEClientNode,
)
BLETextSensorNotifyTrigger = ble_client_ns.class_(
    "BLETextSensorNotifyTrigger", automation.Trigger.template(cg.std_string))

CONFIG_SCHEMA = cv.All(
    text_sensor.TEXT_SENSOR_SCHEMA.extend({
        cv.GenerateID():
        cv.declare_id(BLETextSensor),
        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_NOTIFY, default=False):
        cv.boolean,
        cv.Optional(CONF_ON_NOTIFY):
        automation.validate_automation({
            cv.GenerateID(CONF_TRIGGER_ID):
            cv.declare_id(BLETextSensorNotifyTrigger),
        }),
    }).extend(cv.polling_component_schema("60s")).extend(
        ble_client.BLE_CLIENT_SCHEMA))


async def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    if len(config[CONF_SERVICE_UUID]) == len(
            esp32_ble_tracker.bt_uuid16_format):
Esempio n. 29
0
ST7735_MODEL = cv.enum(MODELS, upper=True, space="_")

ST7735_SCHEMA = display.FULL_DISPLAY_SCHEMA.extend({
    cv.Required(CONF_MODEL):
    ST7735_MODEL,
    cv.Optional(CONF_RESET_PIN):
    pins.gpio_output_pin_schema,
}).extend(cv.polling_component_schema("1s"))

CONFIG_SCHEMA = cv.All(
    ST7735_SCHEMA.extend({
        cv.GenerateID(): cv.declare_id(SPIST7735),
        cv.Required(CONF_DC_PIN): pins.gpio_output_pin_schema,
        cv.Required(CONF_DEVICE_WIDTH): cv.int_,
        cv.Required(CONF_DEVICE_HEIGHT): cv.int_,
        cv.Required(CONF_COL_START): cv.int_,
        cv.Required(CONF_ROW_START): cv.int_,
        cv.Optional(CONF_EIGHT_BIT_COLOR, default=False): cv.boolean,
        cv.Optional(CONF_USE_BGR, default=False): cv.boolean,
    }).extend(cv.COMPONENT_SCHEMA).extend(spi.spi_device_schema()),
    cv.has_at_most_one_key(CONF_PAGES, CONF_LAMBDA),
)


async def setup_st7735(var, config):
    await cg.register_component(var, config)
    await display.register_display(var, config)

    if CONF_RESET_PIN in config:
        reset = await cg.gpio_pin_expression(config[CONF_RESET_PIN])
        cg.add(var.set_reset_pin(reset))
Esempio n. 30
0
).extend({
    cv.GenerateID():
    cv.declare_id(PulseCounterSensor),
    cv.Required(CONF_PIN):
    validate_pulse_counter_pin,
    cv.Optional(
        CONF_COUNT_MODE,
        default={
            CONF_RISING_EDGE: "INCREMENT",
            CONF_FALLING_EDGE: "DISABLE",
        },
    ):
    cv.All(
        cv.Schema({
            cv.Required(CONF_RISING_EDGE): COUNT_MODE_SCHEMA,
            cv.Required(CONF_FALLING_EDGE): COUNT_MODE_SCHEMA,
        }),
        validate_count_mode,
    ),
    cv.Optional(CONF_INTERNAL_FILTER, default="13us"):
    validate_internal_filter,
    cv.Optional(CONF_TOTAL):
    sensor.sensor_schema(UNIT_PULSES, ICON_PULSE, 0, DEVICE_CLASS_EMPTY,
                         STATE_CLASS_NONE),
}).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)