Esempio n. 1
0
CONF_REFERENCE_VOLTAGE = 'reference_voltage'
CONF_CONFIGURATION = 'configuration'
CONF_RESISTOR = 'resistor'

ResistanceConfiguration = resistance_ns.enum('ResistanceConfiguration')
CONFIGURATIONS = {
    'DOWNSTREAM': ResistanceConfiguration.DOWNSTREAM,
    'UPSTREAM': ResistanceConfiguration.UPSTREAM,
}

CONFIG_SCHEMA = sensor.sensor_schema(UNIT_OHM, ICON_FLASH, 1).extend({
    cv.GenerateID(): cv.declare_id(ResistanceSensor),
    cv.Required(CONF_SENSOR): cv.use_id(sensor.Sensor),
    cv.Required(CONF_CONFIGURATION): cv.enum(CONFIGURATIONS, upper=True),
    cv.Required(CONF_RESISTOR): cv.resistance,
    cv.Optional(CONF_REFERENCE_VOLTAGE, default='3.3V'): cv.voltage,
}).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 = yield cg.get_variable(config[CONF_SENSOR])
    cg.add(var.set_sensor(sens))
    cg.add(var.set_configuration(config[CONF_CONFIGURATION]))
    cg.add(var.set_resistor(config[CONF_RESISTOR]))
    cg.add(var.set_reference_voltage(config[CONF_REFERENCE_VOLTAGE]))
Esempio n. 2
0
    0: display_ns.DISPLAY_ROTATION_0_DEGREES,
    90: display_ns.DISPLAY_ROTATION_90_DEGREES,
    180: display_ns.DISPLAY_ROTATION_180_DEGREES,
    270: display_ns.DISPLAY_ROTATION_270_DEGREES,
}


def validate_rotation(value):
    value = cv.string(value)
    if value.endswith("°"):
        value = value[:-1]
    return cv.enum(DISPLAY_ROTATIONS, int=True)(value)


BASIC_DISPLAY_SCHEMA = cv.Schema({
    cv.Optional(CONF_LAMBDA): cv.lambda_,
})

FULL_DISPLAY_SCHEMA = BASIC_DISPLAY_SCHEMA.extend({
    cv.Optional(CONF_ROTATION):
    validate_rotation,
    cv.Optional(CONF_PAGES):
    cv.All(
        cv.ensure_list({
            cv.GenerateID(): cv.declare_id(DisplayPage),
            cv.Required(CONF_LAMBDA): cv.lambda_,
        }),
        cv.Length(min=1),
    ),
    cv.Optional(CONF_ON_PAGE_CHANGE):
    automation.validate_automation({
Esempio n. 3
0
)

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

xiaomi_gcls002_ns = cg.esphome_ns.namespace("xiaomi_gcls002")
XiaomiGCLS002 = xiaomi_gcls002_ns.class_("XiaomiGCLS002",
                                         esp32_ble_tracker.ESPBTDeviceListener,
                                         cg.Component)

CONFIG_SCHEMA = (cv.Schema({
    cv.GenerateID():
    cv.declare_id(XiaomiGCLS002),
    cv.Required(CONF_MAC_ADDRESS):
    cv.mac_address,
    cv.Optional(CONF_TEMPERATURE):
    sensor.sensor_schema(
        UNIT_CELSIUS,
        ICON_EMPTY,
        1,
        DEVICE_CLASS_TEMPERATURE,
        STATE_CLASS_MEASUREMENT,
    ),
    cv.Optional(CONF_MOISTURE):
    sensor.sensor_schema(
        UNIT_PERCENT,
        ICON_WATER_PERCENT,
        0,
        DEVICE_CLASS_EMPTY,
        STATE_CLASS_MEASUREMENT,
    ),
Esempio n. 4
0
                "global log level {}.".format(level, tag, global_level))
    return value


Logger = logger_ns.class_("Logger", cg.Component)
LoggerMessageTrigger = logger_ns.class_(
    "LoggerMessageTrigger",
    automation.Trigger.template(cg.int_, cg.const_char_ptr, cg.const_char_ptr),
)

CONF_ESP8266_STORE_LOG_STRINGS_IN_FLASH = "esp8266_store_log_strings_in_flash"
CONFIG_SCHEMA = cv.All(
    cv.Schema({
        cv.GenerateID():
        cv.declare_id(Logger),
        cv.Optional(CONF_BAUD_RATE, default=115200):
        cv.positive_int,
        cv.Optional(CONF_TX_BUFFER_SIZE, default=512):
        cv.validate_bytes,
        cv.Optional(CONF_HARDWARE_UART, default="UART0"):
        uart_selection,
        cv.Optional(CONF_LEVEL, default="DEBUG"):
        is_log_level,
        cv.Optional(CONF_LOGS, default={}):
        cv.Schema({
            cv.string: is_log_level,
        }),
        cv.Optional(CONF_ON_MESSAGE):
        automation.validate_automation({
            cv.GenerateID(CONF_TRIGGER_ID):
            cv.declare_id(LoggerMessageTrigger),
Esempio n. 5
0
    return value


def _parse_platform_version(value):
    try:
        # if platform version is a valid version constraint, prefix the default package
        cv.platformio_version_constraint(value)
        return f"platformio/espressif8266 @ {value}"
    except cv.Invalid:
        return value


CONF_PLATFORM_VERSION = "platform_version"
ARDUINO_FRAMEWORK_SCHEMA = cv.All(
    cv.Schema({
        cv.Optional(CONF_VERSION, default="recommended"): cv.string_strict,
        cv.Optional(CONF_SOURCE): cv.string_strict,
        cv.Optional(CONF_PLATFORM_VERSION): _parse_platform_version,
    }),
    _arduino_check_versions,
)

BUILD_FLASH_MODES = ["qio", "qout", "dio", "dout"]
CONFIG_SCHEMA = cv.All(
    cv.Schema({
        cv.Required(CONF_BOARD):
        cv.string_strict,
        cv.Optional(CONF_FRAMEWORK, default={}):
        ARDUINO_FRAMEWORK_SCHEMA,
        cv.Optional(CONF_RESTORE_FROM_FLASH, default=False):
        cv.boolean,
Esempio n. 6
0
}


def validate(config):
    if CONF_AQI in config and CONF_PM_2_5 not in config:
        raise cv.Invalid("AQI sensor requires PM 2.5")
    if CONF_AQI in config and CONF_PM_10_0 not in config:
        raise cv.Invalid("AQI sensor requires PM 10 sensors")
    return config


CONFIG_SCHEMA = cv.All(
    cv.Schema({
        cv.GenerateID():
        cv.declare_id(HM3301Component),
        cv.Optional(CONF_PM_1_0):
        sensor.sensor_schema(UNIT_MICROGRAMS_PER_CUBIC_METER,
                             ICON_CHEMICAL_WEAPON, 0),
        cv.Optional(CONF_PM_2_5):
        sensor.sensor_schema(UNIT_MICROGRAMS_PER_CUBIC_METER,
                             ICON_CHEMICAL_WEAPON, 0),
        cv.Optional(CONF_PM_10_0):
        sensor.sensor_schema(UNIT_MICROGRAMS_PER_CUBIC_METER,
                             ICON_CHEMICAL_WEAPON, 0),
        cv.Optional(CONF_AQI):
        sensor.sensor_schema(UNIT_INDEX, ICON_CHEMICAL_WEAPON, 0).extend({
            cv.Required(CONF_CALCULATION_TYPE):
            cv.enum(AQI_CALCULATION_TYPE, upper=True),
        })
    }).extend(cv.polling_component_schema('60s')).extend(
        i2c.i2c_device_schema(0x40)), validate)
Esempio n. 7
0
    CONF_BINDKEY

CODEOWNERS = ['@vevsvevs']
DEPENDENCIES = ['esp32_ble_tracker']
AUTO_LOAD = ['xiaomi_ble']

xiaomi_mhoc401_ns = cg.esphome_ns.namespace('xiaomi_mhoc401')
XiaomiMHOC401 = xiaomi_mhoc401_ns.class_('XiaomiMHOC401',
                                         esp32_ble_tracker.ESPBTDeviceListener,
                                         cg.Component)

CONFIG_SCHEMA = cv.Schema({
    cv.GenerateID(): cv.declare_id(XiaomiMHOC401),
    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_THERMOMETER, 1),
    cv.Optional(CONF_HUMIDITY): sensor.sensor_schema(UNIT_PERCENT, ICON_WATER_PERCENT, 0),
    cv.Optional(CONF_BATTERY_LEVEL): sensor.sensor_schema(UNIT_PERCENT, ICON_BATTERY, 0),
}).extend(esp32_ble_tracker.ESP_BLE_DEVICE_SCHEMA).extend(cv.COMPONENT_SCHEMA)


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

    cg.add(var.set_address(config[CONF_MAC_ADDRESS].as_hex))
    cg.add(var.set_bindkey(config[CONF_BINDKEY]))

    if CONF_TEMPERATURE in config:
        sens = yield sensor.new_sensor(config[CONF_TEMPERATURE])
Esempio n. 8
0
    "95KBPS": CanSpeed.CAN_95KBPS,
    "100KBPS": CanSpeed.CAN_100KBPS,
    "125KBPS": CanSpeed.CAN_125KBPS,
    "200KBPS": CanSpeed.CAN_200KBPS,
    "250KBPS": CanSpeed.CAN_250KBPS,
    "500KBPS": CanSpeed.CAN_500KBPS,
    "1000KBPS": CanSpeed.CAN_1000KBPS,
}

CANBUS_SCHEMA = cv.Schema(
    {
        cv.GenerateID():
        cv.declare_id(CanbusComponent),
        cv.Required(CONF_CAN_ID):
        cv.int_range(min=0, max=0x1FFFFFFF),
        cv.Optional(CONF_BIT_RATE, default="125KBPS"):
        cv.enum(CAN_SPEEDS, upper=True),
        cv.Optional(CONF_USE_EXTENDED_ID, default=False):
        cv.boolean,
        cv.Optional(CONF_ON_FRAME):
        automation.validate_automation(
            {
                cv.GenerateID(CONF_TRIGGER_ID):
                cv.declare_id(CanbusTrigger),
                cv.Required(CONF_CAN_ID):
                cv.int_range(min=0, max=0x1FFFFFFF),
                cv.Optional(CONF_CAN_ID_MASK, default=0x1FFFFFFF):
                cv.int_range(min=0, max=0x1FFFFFFF),
                cv.Optional(CONF_USE_EXTENDED_ID, default=False):
                cv.boolean,
            },
Esempio n. 9
0
DEPENDENCIES = ["i2c"]

scd4x_ns = cg.esphome_ns.namespace("scd4x")
SCD4XComponent = scd4x_ns.class_("SCD4XComponent", cg.PollingComponent, i2c.I2CDevice)

CONF_AUTOMATIC_SELF_CALIBRATION = "automatic_self_calibration"
CONF_ALTITUDE_COMPENSATION = "altitude_compensation"
CONF_AMBIENT_PRESSURE_COMPENSATION = "ambient_pressure_compensation"
CONF_TEMPERATURE_OFFSET = "temperature_offset"
CONF_AMBIENT_PRESSURE_COMPENSATION_SOURCE = "ambient_pressure_compensation_source"

CONFIG_SCHEMA = (
    cv.Schema(
        {
            cv.GenerateID(): cv.declare_id(SCD4XComponent),
            cv.Optional(CONF_CO2): sensor.sensor_schema(
                unit_of_measurement=UNIT_PARTS_PER_MILLION,
                icon=ICON_MOLECULE_CO2,
                accuracy_decimals=0,
                device_class=DEVICE_CLASS_CARBON_DIOXIDE,
                state_class=STATE_CLASS_MEASUREMENT,
            ),
            cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema(
                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,
Esempio n. 10
0
CalibrateLinearFilter = sensor_ns.class_("CalibrateLinearFilter", Filter)
CalibratePolynomialFilter = sensor_ns.class_("CalibratePolynomialFilter",
                                             Filter)
SensorInRangeCondition = sensor_ns.class_("SensorInRangeCondition", Filter)

unit_of_measurement = cv.string_strict
accuracy_decimals = cv.int_
icon = cv.icon
device_class = cv.one_of(*DEVICE_CLASSES, lower=True, space="_")

SENSOR_SCHEMA = cv.MQTT_COMPONENT_SCHEMA.extend({
    cv.OnlyWith(CONF_MQTT_ID, "mqtt"):
    cv.declare_id(mqtt.MQTTSensorComponent),
    cv.GenerateID():
    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),
Esempio n. 11
0
DEPENDENCIES = ["esp32_ble_tracker"]
AUTO_LOAD = ["xiaomi_ble"]

xiaomi_lywsd03mmc_ns = cg.esphome_ns.namespace("xiaomi_lywsd03mmc")
XiaomiLYWSD03MMC = xiaomi_lywsd03mmc_ns.class_(
    "XiaomiLYWSD03MMC", esp32_ble_tracker.ESPBTDeviceListener, cg.Component)

CONFIG_SCHEMA = (cv.Schema({
    cv.GenerateID():
    cv.declare_id(XiaomiLYWSD03MMC),
    cv.Required(CONF_BINDKEY):
    cv.bind_key,
    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,
    ),
    cv.Optional(CONF_BATTERY_LEVEL):
    sensor.sensor_schema(
Esempio n. 12
0
CONF_CHARGE_MODE = "charge_mode"
CONF_INPUT_VOLTAGE = "input_voltage"
CONF_BATTERY_VOLTAGE = "battery_voltage"
CONF_CHARGING_CURRENT = "charging_current"
CONF_LOAD_VOLTAGE = "load_voltage"
CONF_LOAD_CURRENT = "load_current"
CONF_CHARGING_POWER = "charging_power"
CONF_LOAD_POWER = "load_power"
CONF_BATTERY_TEMP = "battery_temp"
CONF_INTERNAL_TEMP = "internal_temp"
CONF_BATTERY_LEVEL = "battery_level"

CONFIG_SCHEMA = uart.UART_DEVICE_SCHEMA.extend({
    cv.GenerateID(): cv.declare_id(ESmart3Component),
    cv.Optional(CONF_CHARGE_MODE): sensor.sensor_schema(UNIT_EMPTY, ICON_EMPTY, 0),
    cv.Optional(CONF_INPUT_VOLTAGE): sensor.sensor_schema(UNIT_VOLT, ICON_FLASH, 1),
    cv.Optional(CONF_BATTERY_VOLTAGE): sensor.sensor_schema(UNIT_VOLT, ICON_FLASH, 1),
    cv.Optional(CONF_CHARGING_CURRENT): sensor.sensor_schema(UNIT_AMPERE, ICON_CURRENT_AC, 1),
    cv.Optional(CONF_LOAD_VOLTAGE): sensor.sensor_schema(UNIT_VOLT, ICON_FLASH, 1),
    cv.Optional(CONF_LOAD_CURRENT): sensor.sensor_schema(UNIT_AMPERE, ICON_CURRENT_AC, 1),
    cv.Optional(CONF_CHARGING_POWER): sensor.sensor_schema(UNIT_WATT, ICON_POWER, 0),
    cv.Optional(CONF_LOAD_POWER): sensor.sensor_schema(UNIT_WATT, ICON_POWER, 0),
    cv.Optional(CONF_BATTERY_TEMP): sensor.sensor_schema(UNIT_CELSIUS, ICON_THERMOMETER, 0),
    cv.Optional(CONF_INTERNAL_TEMP): sensor.sensor_schema(UNIT_CELSIUS, ICON_THERMOMETER, 0),
    cv.Optional(CONF_BATTERY_LEVEL): sensor.sensor_schema(UNIT_PERCENT, ICON_PERCENT, 0),
}).extend(cv.polling_component_schema('60s'))

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

ValuePositionType = graph_ns.enum("ValuePositionType")
VALUE_POSITION_TYPE = {
    "NONE": ValuePositionType.VALUE_POSITION_TYPE_NONE,
    "AUTO": ValuePositionType.VALUE_POSITION_TYPE_AUTO,
    "BESIDE": ValuePositionType.VALUE_POSITION_TYPE_BESIDE,
    "BELOW": ValuePositionType.VALUE_POSITION_TYPE_BELOW,
}

GRAPH_TRACE_SCHEMA = cv.Schema({
    cv.GenerateID():
    cv.declare_id(GraphTrace),
    cv.Required(CONF_SENSOR):
    cv.use_id(sensor.Sensor),
    cv.Optional(CONF_NAME):
    cv.string,
    cv.Optional(CONF_LINE_THICKNESS):
    cv.positive_int,
    cv.Optional(CONF_LINE_TYPE):
    cv.enum(LINE_TYPE, upper=True),
    cv.Optional(CONF_COLOR):
    cv.use_id(color.ColorStruct),
})

GRAPH_LEGEND_SCHEMA = cv.Schema({
    cv.GenerateID(CONF_ID):
    cv.declare_id(GraphLegend),
    cv.Required(CONF_NAME_FONT):
    cv.use_id(Font),
    cv.Optional(CONF_VALUE_FONT):
Esempio n. 14
0

def inherit_accuracy_decimals(decimals, config):
    return decimals + 2


CONFIG_SCHEMA = (sensor.sensor_schema(
    TotalDailyEnergy,
    device_class=DEVICE_CLASS_ENERGY,
    state_class=STATE_CLASS_TOTAL_INCREASING,
).extend({
    cv.GenerateID(CONF_TIME_ID):
    cv.use_id(time.RealTimeClock),
    cv.Required(CONF_POWER_ID):
    cv.use_id(sensor.Sensor),
    cv.Optional(CONF_RESTORE, default=True):
    cv.boolean,
    cv.Optional("min_save_interval"):
    cv.invalid(
        "`min_save_interval` was removed in 2022.6.0. Please use the `preferences` -> `flash_write_interval` to adjust."
    ),
    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):
Esempio n. 15
0
mcp23S17_ns = cg.esphome_ns.namespace('mcp23s17')
mcp23S17GPIOMode = mcp23S17_ns.enum('MCP23S17GPIOMode')
mcp23S17_GPIO_MODES = {
    'INPUT': mcp23S17GPIOMode.MCP23S17_INPUT,
    'INPUT_PULLUP': mcp23S17GPIOMode.MCP23S17_INPUT_PULLUP,
    'OUTPUT': mcp23S17GPIOMode.MCP23S17_OUTPUT,
}

mcp23S17 = mcp23S17_ns.class_('MCP23S17', cg.Component, spi.SPIDevice)
mcp23S17GPIOPin = mcp23S17_ns.class_('MCP23S17GPIOPin', cg.GPIOPin)

CONFIG_SCHEMA = cv.Schema({
    cv.Required(CONF_ID):
    cv.declare_id(mcp23S17),
    cv.Optional(CONF_DEVICEADDRESS, default=0):
    cv.uint8_t,
}).extend(cv.COMPONENT_SCHEMA).extend(spi.spi_device_schema())


def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    cg.add(var.set_device_address(config[CONF_DEVICEADDRESS]))
    yield cg.register_component(var, config)
    yield spi.register_spi_device(var, config)


CONF_MCP23S17 = 'mcp23s17'

mcp23S17_OUTPUT_PIN_SCHEMA = cv.Schema({
    cv.GenerateID(CONF_MCP23S17):
Esempio n. 16
0
    "WS2803",
    "SM16716",
    "P9813",
    "APA102",
    "SK9822",
    "DOTSTAR",
]

CONFIG_SCHEMA = fastled_base.BASE_SCHEMA.extend({
    cv.Required(CONF_CHIPSET):
    cv.one_of(*CHIPSETS, upper=True),
    cv.Required(CONF_DATA_PIN):
    pins.output_pin,
    cv.Required(CONF_CLOCK_PIN):
    pins.output_pin,
    cv.Optional(CONF_DATA_RATE):
    cv.frequency,
})


def to_code(config):
    var = yield fastled_base.new_fastled_light(config)

    rgb_order = cg.RawExpression(config[CONF_RGB_ORDER] if CONF_RGB_ORDER in
                                 config else "RGB")
    data_rate = None

    if CONF_DATA_RATE in config:
        data_rate_khz = int(config[CONF_DATA_RATE] / 1000)
        if data_rate_khz < 1000:
            data_rate = cg.RawExpression(f"DATA_RATE_KHZ({data_rate_khz})")
Esempio n. 17
0
)

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

xiaomi_lywsdcgq_ns = cg.esphome_ns.namespace("xiaomi_lywsdcgq")
XiaomiLYWSDCGQ = xiaomi_lywsdcgq_ns.class_(
    "XiaomiLYWSDCGQ", esp32_ble_tracker.ESPBTDeviceListener, cg.Component
)

CONFIG_SCHEMA = (
    cv.Schema(
        {
            cv.GenerateID(): cv.declare_id(XiaomiLYWSDCGQ),
            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=1,
                device_class=DEVICE_CLASS_HUMIDITY,
                state_class=STATE_CLASS_MEASUREMENT,
            ),
            cv.Optional(CONF_BATTERY_LEVEL): sensor.sensor_schema(
                unit_of_measurement=UNIT_PERCENT,
                accuracy_decimals=0,
                device_class=DEVICE_CLASS_BATTERY,
Esempio n. 18
0

def _validate(config):
    if CONF_WAVE_CHANNEL_ID in config and CONF_COMPONENT_ID not in config:
        raise cv.Invalid(
            f"{CONF_COMPONENT_ID} is required when {CONF_WAVE_CHANNEL_ID} is set"
        )

    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),
Esempio n. 19
0
    CONF_LEVEL,
    CONF_MAX_POWER,
    CONF_MIN_POWER,
    CONF_POWER_SUPPLY,
)
from esphome.core import CORE


CODEOWNERS = ["@esphome/core"]
IS_PLATFORM_COMPONENT = True

CONF_ZERO_MEANS_ZERO = "zero_means_zero"

BINARY_OUTPUT_SCHEMA = cv.Schema(
    {
        cv.Optional(CONF_POWER_SUPPLY): cv.use_id(power_supply.PowerSupply),
        cv.Optional(CONF_INVERTED): cv.boolean,
    }
)

FLOAT_OUTPUT_SCHEMA = BINARY_OUTPUT_SCHEMA.extend(
    {
        cv.Optional(CONF_MAX_POWER): cv.percentage,
        cv.Optional(CONF_MIN_POWER): cv.percentage,
        cv.Optional(CONF_ZERO_MEANS_ZERO, default=False): cv.boolean,
    }
)

output_ns = cg.esphome_ns.namespace("output")
BinaryOutput = output_ns.class_("BinaryOutput")
BinaryOutputPtr = BinaryOutput.operator("ptr")
Esempio n. 20
0
e131_ns = cg.esphome_ns.namespace('e131')
E131AddressableLightEffect = e131_ns.class_('E131AddressableLightEffect',
                                            AddressableLightEffect)
E131Component = e131_ns.class_('E131Component', cg.Component)

METHODS = {'UNICAST': 'E131_UNICAST', 'MULTICAST': 'E131_MULTICAST'}

CHANNELS = {'MONO': 'E131_MONO', 'RGB': 'E131_RGB', 'RGBW': 'E131_RGBW'}

CONF_UNIVERSE = 'universe'
CONF_E131_ID = 'e131_id'

CONFIG_SCHEMA = cv.Schema({
    cv.GenerateID():
    cv.declare_id(E131Component),
    cv.Optional(CONF_METHOD, default='MULTICAST'):
    cv.one_of(*METHODS, upper=True),
})


def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
    yield cg.register_component(var, config)
    cg.add(var.set_method(getattr(cg.global_ns, METHODS[config[CONF_METHOD]])))


def register_addressable_effect(name, effect_type, default_name, schema,
                                *extra_validators):
    ADDRESSABLE_EFFECTS.append(name)
    return register_effect(name, effect_type, default_name, schema,
                           *extra_validators)
import esphome.config_validation as cv
from esphome.components import sensor, voltage_sampler
from esphome.const import CONF_SENSOR, CONF_ID, ICON_FLASH, UNIT_AMPERE

AUTO_LOAD = ['voltage_sampler']

CONF_SAMPLE_DURATION = 'sample_duration'

ct_clamp_ns = cg.esphome_ns.namespace('ct_clamp')
CTClampSensor = ct_clamp_ns.class_('CTClampSensor', sensor.Sensor,
                                   cg.PollingComponent)

CONFIG_SCHEMA = sensor.sensor_schema(UNIT_AMPERE, ICON_FLASH, 2).extend({
    cv.GenerateID():
    cv.declare_id(CTClampSensor),
    cv.Required(CONF_SENSOR):
    cv.use_id(voltage_sampler.VoltageSampler),
    cv.Optional(CONF_SAMPLE_DURATION, default='200ms'):
    cv.positive_time_period_milliseconds,
}).extend(cv.polling_component_schema('60s'))


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

    sens = yield cg.get_variable(config[CONF_SENSOR])
    cg.add(var.set_source(sens))
    cg.add(var.set_sample_duration(config[CONF_SAMPLE_DURATION]))
Esempio n. 22
0
wifi_info_ns = cg.esphome_ns.namespace("wifi_info")
IPAddressWiFiInfo = wifi_info_ns.class_("IPAddressWiFiInfo",
                                        text_sensor.TextSensor,
                                        cg.PollingComponent)
ScanResultsWiFiInfo = wifi_info_ns.class_("ScanResultsWiFiInfo",
                                          text_sensor.TextSensor,
                                          cg.PollingComponent)
SSIDWiFiInfo = wifi_info_ns.class_("SSIDWiFiInfo", text_sensor.TextSensor,
                                   cg.PollingComponent)
BSSIDWiFiInfo = wifi_info_ns.class_("BSSIDWiFiInfo", text_sensor.TextSensor,
                                    cg.PollingComponent)
MacAddressWifiInfo = wifi_info_ns.class_("MacAddressWifiInfo",
                                         text_sensor.TextSensor, cg.Component)

CONFIG_SCHEMA = cv.Schema({
    cv.Optional(CONF_IP_ADDRESS):
    text_sensor.text_sensor_schema(
        klass=IPAddressWiFiInfo,
        entity_category=ENTITY_CATEGORY_DIAGNOSTIC).extend(
            cv.polling_component_schema("1s")),
    cv.Optional(CONF_SCAN_RESULTS):
    text_sensor.text_sensor_schema(
        klass=ScanResultsWiFiInfo,
        entity_category=ENTITY_CATEGORY_DIAGNOSTIC).extend(
            cv.polling_component_schema("60s")),
    cv.Optional(CONF_SSID):
    text_sensor.text_sensor_schema(
        klass=SSIDWiFiInfo, entity_category=ENTITY_CATEGORY_DIAGNOSTIC).extend(
            cv.polling_component_schema("1s")),
    cv.Optional(CONF_BSSID):
    text_sensor.text_sensor_schema(
Esempio n. 23
0
from .. import mqtt_subscribe_ns

DEPENDENCIES = ["mqtt"]

CONF_MQTT_PARENT_ID = "mqtt_parent_id"
MQTTSubscribeTextSensor = mqtt_subscribe_ns.class_("MQTTSubscribeTextSensor",
                                                   text_sensor.TextSensor,
                                                   cg.Component)

CONFIG_SCHEMA = text_sensor.TEXT_SENSOR_SCHEMA.extend({
    cv.GenerateID():
    cv.declare_id(MQTTSubscribeTextSensor),
    cv.GenerateID(CONF_MQTT_PARENT_ID):
    cv.use_id(mqtt.MQTTClientComponent),
    cv.Required(CONF_TOPIC):
    cv.subscribe_topic,
    cv.Optional(CONF_QOS, default=0):
    cv.mqtt_qos,
}).extend(cv.COMPONENT_SCHEMA)


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

    parent = yield cg.get_variable(config[CONF_MQTT_PARENT_ID])
    cg.add(var.set_parent(parent))
    cg.add(var.set_topic(config[CONF_TOPIC]))
    cg.add(var.set_qos(config[CONF_QOS]))
Esempio n. 24
0
ST7735Model = st7735_ns.enum("ST7735Model")

MODELS = {
    "INITR_GREENTAB": ST7735Model.ST7735_INITR_GREENTAB,
    "INITR_REDTAB": ST7735Model.ST7735_INITR_REDTAB,
    "INITR_BLACKTAB": ST7735Model.ST7735_INITR_BLACKTAB,
    "INITR_MINI160X80": ST7735Model.ST7735_INITR_MINI_160X80,
    "INITR_18BLACKTAB": ST7735Model.ST7735_INITR_18BLACKTAB,
    "INITR_18REDTAB": ST7735Model.ST7735_INITR_18REDTAB,
}
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),
Esempio n. 25
0
DEPENDENCIES = ['esp32_ble_tracker']
AUTO_LOAD = ['xiaomi_ble']

xiaomi_mue4094rt_ns = cg.esphome_ns.namespace('xiaomi_mue4094rt')
XiaomiMUE4094RT = xiaomi_mue4094rt_ns.class_(
    'XiaomiMUE4094RT', binary_sensor.BinarySensor, cg.Component,
    esp32_ble_tracker.ESPBTDeviceListener)

CONFIG_SCHEMA = cv.All(
    binary_sensor.BINARY_SENSOR_SCHEMA.extend({
        cv.GenerateID():
        cv.declare_id(XiaomiMUE4094RT),
        cv.Required(CONF_MAC_ADDRESS):
        cv.mac_address,
        cv.Optional(CONF_DEVICE_CLASS, default='motion'):
        binary_sensor.device_class,
        cv.Optional(CONF_TIMEOUT, default='5s'):
        cv.positive_time_period_milliseconds,
    }).extend(esp32_ble_tracker.ESP_BLE_DEVICE_SCHEMA).extend(
        cv.COMPONENT_SCHEMA))


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

    cg.add(var.set_address(config[CONF_MAC_ADDRESS].as_hex))
    cg.add(var.set_time(config[CONF_TIMEOUT]))
Esempio n. 26
0
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.const import (CONF_ID, CONF_NUM_ATTEMPTS, CONF_PASSWORD,
                           CONF_PORT, CONF_REBOOT_TIMEOUT, CONF_SAFE_MODE)
from esphome.core import CORE, coroutine_with_priority

CODEOWNERS = ['@esphome/core']
DEPENDENCIES = ['network']

ota_ns = cg.esphome_ns.namespace('ota')
OTAComponent = ota_ns.class_('OTAComponent', cg.Component)

CONFIG_SCHEMA = cv.Schema({
    cv.GenerateID():
    cv.declare_id(OTAComponent),
    cv.Optional(CONF_SAFE_MODE, default=True):
    cv.boolean,
    cv.SplitDefault(CONF_PORT, esp8266=8266, esp32=3232):
    cv.port,
    cv.Optional(CONF_PASSWORD, default=''):
    cv.string,
    cv.Optional(CONF_REBOOT_TIMEOUT, default='5min'):
    cv.positive_time_period_milliseconds,
    cv.Optional(CONF_NUM_ATTEMPTS, default='10'):
    cv.positive_not_null_int
}).extend(cv.COMPONENT_SCHEMA)


@coroutine_with_priority(50.0)
def to_code(config):
    var = cg.new_Pvariable(config[CONF_ID])
Esempio n. 27
0
from . import DallasComponent, dallas_ns

DallasTemperatureSensor = dallas_ns.class_("DallasTemperatureSensor",
                                           sensor.Sensor)

CONFIG_SCHEMA = cv.All(
    sensor.sensor_schema(
        DallasTemperatureSensor,
        unit_of_measurement=UNIT_CELSIUS,
        accuracy_decimals=1,
        device_class=DEVICE_CLASS_TEMPERATURE,
        state_class=STATE_CLASS_MEASUREMENT,
    ).extend({
        cv.GenerateID(CONF_DALLAS_ID):
        cv.use_id(DallasComponent),
        cv.Optional(CONF_ADDRESS):
        cv.hex_int,
        cv.Optional(CONF_INDEX):
        cv.positive_int,
        cv.Optional(CONF_RESOLUTION, default=12):
        cv.int_range(min=9, max=12),
    }),
    cv.has_exactly_one_key(CONF_ADDRESS, CONF_INDEX),
)


async def to_code(config):
    hub = await cg.get_variable(config[CONF_DALLAS_ID])
    var = await sensor.new_sensor(config)

    if CONF_ADDRESS in config:
Esempio n. 28
0
)

CODEOWNERS = ["@senexcrenshaw"]

DEPENDENCIES = ["uart"]
AUTO_LOAD = ["binary_sensor", "switch", "sensor", "text_sensor"]

SetupTrigger = nextion_ns.class_("SetupTrigger", automation.Trigger.template())
SleepTrigger = nextion_ns.class_("SleepTrigger", automation.Trigger.template())
WakeTrigger = nextion_ns.class_("WakeTrigger", automation.Trigger.template())
PageTrigger = nextion_ns.class_("PageTrigger", automation.Trigger.template())

CONFIG_SCHEMA = (display.BASIC_DISPLAY_SCHEMA.extend({
    cv.GenerateID():
    cv.declare_id(Nextion),
    cv.Optional(CONF_TFT_URL):
    cv.All(cv.string, cv.only_with_arduino),
    cv.Optional(CONF_BRIGHTNESS, default=1.0):
    cv.percentage,
    cv.Optional(CONF_ON_SETUP):
    automation.validate_automation({
        cv.GenerateID(CONF_TRIGGER_ID):
        cv.declare_id(SetupTrigger),
    }),
    cv.Optional(CONF_ON_SLEEP):
    automation.validate_automation({
        cv.GenerateID(CONF_TRIGGER_ID):
        cv.declare_id(SleepTrigger),
    }),
    cv.Optional(CONF_ON_WAKE):
    automation.validate_automation({
Esempio n. 29
0
CODEOWNERS = ["@rbaron"]

DEPENDENCIES = ["esp32_ble_tracker"]

b_parasite_ns = cg.esphome_ns.namespace("b_parasite")
BParasite = b_parasite_ns.class_("BParasite",
                                 esp32_ble_tracker.ESPBTDeviceListener,
                                 cg.Component)

CONFIG_SCHEMA = (cv.Schema({
    cv.GenerateID():
    cv.declare_id(BParasite),
    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=1,
        device_class=DEVICE_CLASS_HUMIDITY,
        state_class=STATE_CLASS_MEASUREMENT,
    ),
    cv.Optional(CONF_BATTERY_VOLTAGE):
    sensor.sensor_schema(
Esempio n. 30
0
DeltaFilter = sensor_ns.class_("DeltaFilter", Filter)
OrFilter = sensor_ns.class_("OrFilter", Filter)
CalibrateLinearFilter = sensor_ns.class_("CalibrateLinearFilter", Filter)
CalibratePolynomialFilter = sensor_ns.class_("CalibratePolynomialFilter", Filter)
SensorInRangeCondition = sensor_ns.class_("SensorInRangeCondition", Filter)

validate_unit_of_measurement = cv.string_strict
validate_accuracy_decimals = cv.int_
validate_icon = cv.icon
validate_device_class = cv.one_of(*DEVICE_CLASSES, lower=True, space="_")

SENSOR_SCHEMA = cv.ENTITY_BASE_SCHEMA.extend(cv.MQTT_COMPONENT_SCHEMA).extend(
    {
        cv.OnlyWith(CONF_MQTT_ID, "mqtt"): cv.declare_id(mqtt.MQTTSensorComponent),
        cv.GenerateID(): cv.declare_id(Sensor),
        cv.Optional(CONF_UNIT_OF_MEASUREMENT): validate_unit_of_measurement,
        cv.Optional(CONF_ACCURACY_DECIMALS): validate_accuracy_decimals,
        cv.Optional(CONF_DEVICE_CLASS): validate_device_class,
        cv.Optional(CONF_STATE_CLASS): validate_state_class,
        cv.Optional("last_reset_type"): cv.invalid(
            "last_reset_type has been removed since 2021.9.0. state_class: total_increasing should be used for total values."
        ),
        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),