Exemplo n.º 1
0
def validate_interval_uart(config):
    require_tx = False

    interval = config.get(CONF_UPDATE_INTERVAL)

    if isinstance(interval, TimePeriodMilliseconds):
        # 'never' is encoded as a very large int, not as a TimePeriodMilliseconds objects
        require_tx = True

    uart.final_validate_device_schema("pm1006",
                                      baud_rate=9600,
                                      require_rx=True,
                                      require_tx=require_tx)(config)
Exemplo n.º 2
0
def final_validate(config):
    require_tx = config[CONF_UPDATE_INTERVAL] > cv.time_period("0s")
    schema = uart.final_validate_device_schema("pmsx003",
                                               baud_rate=9600,
                                               require_rx=True,
                                               require_tx=require_tx)
    schema(config)
Exemplo n.º 3
0
    sensor.sensor_schema(
        unit_of_measurement=UNIT_WATT,
        accuracy_decimals=1,
        device_class=DEVICE_CLASS_POWER,
        state_class=STATE_CLASS_MEASUREMENT,
    ),
    cv.Optional(CONF_ENERGY):
    sensor.sensor_schema(
        unit_of_measurement=UNIT_WATT_HOURS,
        accuracy_decimals=3,
        device_class=DEVICE_CLASS_ENERGY,
        state_class=STATE_CLASS_TOTAL_INCREASING,
    ),
}).extend(cv.polling_component_schema("60s")).extend(uart.UART_DEVICE_SCHEMA))
FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema("cse7766",
                                                          baud_rate=4800,
                                                          require_rx=True)


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_VOLTAGE in config:
        conf = config[CONF_VOLTAGE]
        sens = await sensor.new_sensor(conf)
        cg.add(var.set_voltage_sensor(sens))
    if CONF_CURRENT in config:
        conf = config[CONF_CURRENT]
        sens = await sensor.new_sensor(conf)
Exemplo n.º 4
0
CONF_RECIPIENT = "recipient"
CONF_MESSAGE = "message"

CONFIG_SCHEMA = cv.All(
    cv.Schema({
        cv.GenerateID():
        cv.declare_id(Sim800LComponent),
        cv.Optional(CONF_ON_SMS_RECEIVED):
        automation.validate_automation({
            cv.GenerateID(CONF_TRIGGER_ID):
            cv.declare_id(Sim800LReceivedMessageTrigger),
        }),
    }).extend(cv.polling_component_schema("5s")).extend(
        uart.UART_DEVICE_SCHEMA))
FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema("sim800l",
                                                          require_tx=True,
                                                          require_rx=True)


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)

    for conf in config.get(CONF_ON_SMS_RECEIVED, []):
        trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
        await automation.build_automation(trigger, [(cg.std_string, "message"),
                                                    (cg.std_string, "sender")],
                                          conf)

Exemplo n.º 5
0
t6615_ns = cg.esphome_ns.namespace("t6615")
T6615Component = t6615_ns.class_("T6615Component", cg.PollingComponent,
                                 uart.UARTDevice)

CONFIG_SCHEMA = (cv.Schema({
    cv.GenerateID():
    cv.declare_id(T6615Component),
    cv.Required(CONF_CO2):
    sensor.sensor_schema(
        unit_of_measurement=UNIT_PARTS_PER_MILLION,
        accuracy_decimals=0,
        device_class=DEVICE_CLASS_CARBON_DIOXIDE,
        state_class=STATE_CLASS_MEASUREMENT,
    ),
}).extend(cv.polling_component_schema("60s")).extend(uart.UART_DEVICE_SCHEMA))

FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema("t6615",
                                                          baud_rate=19200,
                                                          require_rx=True,
                                                          require_tx=True)


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_CO2 in config:
        sens = await sensor.new_sensor(config[CONF_CO2])
        cg.add(var.set_co2_sensor(sens))
Exemplo n.º 6
0
        accuracy_decimals=2,
        state_class=STATE_CLASS_NONE,
    ),
    cv.Optional(CONF_ALTITUDE):
    sensor.sensor_schema(
        unit_of_measurement=UNIT_METER,
        accuracy_decimals=1,
        state_class=STATE_CLASS_NONE,
    ),
    cv.Optional(CONF_SATELLITES):
    sensor.sensor_schema(
        accuracy_decimals=0,
        state_class=STATE_CLASS_MEASUREMENT,
    ),
}).extend(cv.polling_component_schema("20s")).extend(uart.UART_DEVICE_SCHEMA))
FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema("gps",
                                                          require_rx=True)


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_LATITUDE in config:
        sens = await sensor.new_sensor(config[CONF_LATITUDE])
        cg.add(var.set_latitude_sensor(sens))

    if CONF_LONGITUDE in config:
        sens = await sensor.new_sensor(config[CONF_LONGITUDE])
        cg.add(var.set_longitude_sensor(sens))
Exemplo n.º 7
0
sonoff_d1_ns = cg.esphome_ns.namespace("sonoff_d1")
SonoffD1Output = sonoff_d1_ns.class_(
    "SonoffD1Output", cg.Component, uart.UARTDevice, light.LightOutput
)

CONFIG_SCHEMA = (
    light.BRIGHTNESS_ONLY_LIGHT_SCHEMA.extend(
        {
            cv.GenerateID(CONF_OUTPUT_ID): cv.declare_id(SonoffD1Output),
            cv.Optional(CONF_USE_RM433_REMOTE, default=False): cv.boolean,
            cv.Optional(CONF_MIN_VALUE, default=0): cv.int_range(min=0, max=100),
            cv.Optional(CONF_MAX_VALUE, default=100): cv.int_range(min=0, max=100),
        }
    )
    .extend(cv.COMPONENT_SCHEMA)
    .extend(uart.UART_DEVICE_SCHEMA)
)
FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema(
    "sonoff_d1", baud_rate=9600, require_tx=True, require_rx=True
)


async def to_code(config):
    var = cg.new_Pvariable(config[CONF_OUTPUT_ID])
    await cg.register_component(var, config)
    await uart.register_uart_device(var, config)
    cg.add(var.set_use_rm433_remote(config[CONF_USE_RM433_REMOTE]))
    cg.add(var.set_min_value(config[CONF_MIN_VALUE]))
    cg.add(var.set_max_value(config[CONF_MAX_VALUE]))
    await light.register_light(var, config)
Exemplo n.º 8
0
CONFIG_SCHEMA = cv.All(
    cv.Schema(
        {
            cv.GenerateID(): cv.declare_id(DFPlayer),
            cv.Optional(CONF_ON_FINISHED_PLAYBACK): automation.validate_automation(
                {
                    cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(
                        DFPlayerFinishedPlaybackTrigger
                    ),
                }
            ),
        }
    ).extend(uart.UART_DEVICE_SCHEMA)
)
FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema(
    "dfplayer", baud_rate=9600, require_tx=True
)


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)

    for conf in config.get(CONF_ON_FINISHED_PLAYBACK, []):
        trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
        await automation.build_automation(trigger, [], conf)


@automation.register_action(
    "dfplayer.play_next",