CONF_TUYA_ID = "tuya_id" CONFIG_SCHEMA = (cv.Schema({ cv.GenerateID(): cv.declare_id(Tuya), cv.Optional(CONF_TIME_ID): cv.use_id(time.RealTimeClock), cv.Optional(CONF_IGNORE_MCU_UPDATE_ON_DATAPOINTS): cv.ensure_list(cv.uint8_t), cv.Optional(CONF_ON_DATAPOINT_UPDATE): automation.validate_automation( { cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(DATAPOINT_TRIGGERS[DPTYPE_ANY]), cv.Required(CONF_SENSOR_DATAPOINT): cv.uint8_t, cv.Optional(CONF_DATAPOINT_TYPE, default=DPTYPE_ANY): cv.one_of(*DATAPOINT_TRIGGERS, lower=True), }, extra_validators=assign_declare_id, ), }).extend(cv.COMPONENT_SCHEMA).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_TIME_ID in config: time_ = await cg.get_variable(config[CONF_TIME_ID])
if value == 'inf': return 1e6 try: value = float(value) except ValueError: raise cv.Invalid(f"Expected speed as floating point number, got {value}") if value <= 0: raise cv.Invalid("Speed must be larger than 0 steps/s!") return value STEPPER_SCHEMA = cv.Schema({ cv.Required(CONF_MAX_SPEED): validate_speed, cv.Optional(CONF_ACCELERATION, default='inf'): validate_acceleration, cv.Optional(CONF_DECELERATION, default='inf'): validate_acceleration, }) @coroutine def setup_stepper_core_(stepper_var, config): if CONF_ACCELERATION in config: cg.add(stepper_var.set_acceleration(config[CONF_ACCELERATION])) if CONF_DECELERATION in config: cg.add(stepper_var.set_deceleration(config[CONF_DECELERATION])) if CONF_MAX_SPEED in config: cg.add(stepper_var.set_max_speed(config[CONF_MAX_SPEED]))
} ), ) async def dfplayer_previous_to_code(config, action_id, template_arg, args): var = cg.new_Pvariable(action_id, template_arg) await cg.register_parented(var, config[CONF_ID]) return var @automation.register_action( "dfplayer.play", PlayFileAction, cv.maybe_simple_value( { cv.GenerateID(): cv.use_id(DFPlayer), cv.Required(CONF_FILE): cv.templatable(cv.int_), cv.Optional(CONF_LOOP): cv.templatable(cv.boolean), }, key=CONF_FILE, ), ) async def dfplayer_play_to_code(config, action_id, template_arg, args): var = cg.new_Pvariable(action_id, template_arg) await cg.register_parented(var, config[CONF_ID]) template_ = await cg.templatable(config[CONF_FILE], args, float) cg.add(var.set_file(template_)) if CONF_LOOP in config: template_ = await cg.templatable(config[CONF_LOOP], args, float) cg.add(var.set_loop(template_)) return var
CONF_B: b, CONF_C: c, } CONFIG_SCHEMA = ( sensor.sensor_schema( unit_of_measurement=UNIT_CELSIUS, accuracy_decimals=1, device_class=DEVICE_CLASS_TEMPERATURE, state_class=STATE_CLASS_MEASUREMENT, ) .extend( { cv.GenerateID(): cv.declare_id(NTC), cv.Required(CONF_SENSOR): cv.use_id(sensor.Sensor), cv.Required(CONF_CALIBRATION): process_calibration, } ) .extend(cv.COMPONENT_SCHEMA) ) async def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) await cg.register_component(var, config) await sensor.register_sensor(var, config) sens = await cg.get_variable(config[CONF_SENSOR]) cg.add(var.set_sensor(sens)) calib = config[CONF_CALIBRATION]
def valid_pwm_pin(value): num = value[CONF_NUMBER] cv.one_of(0, 1, 2, 3, 4, 5, 9, 10, 12, 13, 14, 15, 16)(num) return value esp8266_pwm_ns = cg.esphome_ns.namespace("esp8266_pwm") ESP8266PWM = esp8266_pwm_ns.class_("ESP8266PWM", output.FloatOutput, cg.Component) SetFrequencyAction = esp8266_pwm_ns.class_("SetFrequencyAction", automation.Action) validate_frequency = cv.All(cv.frequency, cv.Range(min=1.0e-6)) CONFIG_SCHEMA = output.FLOAT_OUTPUT_SCHEMA.extend( { cv.Required(CONF_ID): cv.declare_id(ESP8266PWM), cv.Required(CONF_PIN): cv.All( pins.internal_gpio_output_pin_schema, valid_pwm_pin ), cv.Optional(CONF_FREQUENCY, default="1kHz"): validate_frequency, } ).extend(cv.COMPONENT_SCHEMA) async def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) await cg.register_component(var, config) await output.register_output(var, config) pin = await cg.gpio_pin_expression(config[CONF_PIN]) cg.add(var.set_pin(pin))
from esphome.components import sensor import esphome.config_validation as cv import esphome.codegen as cg from esphome.const import CONF_ID, CONF_SENSOR_DATAPOINT from .. import tuya_ns, CONF_TUYA_ID, Tuya DEPENDENCIES = ["tuya"] CODEOWNERS = ["@jesserockz"] TuyaSensor = tuya_ns.class_("TuyaSensor", sensor.Sensor, cg.Component) CONFIG_SCHEMA = sensor.SENSOR_SCHEMA.extend( { cv.GenerateID(): cv.declare_id(TuyaSensor), cv.GenerateID(CONF_TUYA_ID): cv.use_id(Tuya), cv.Required(CONF_SENSOR_DATAPOINT): cv.uint8_t, } ).extend(cv.COMPONENT_SCHEMA) async def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) await cg.register_component(var, config) await sensor.register_sensor(var, config) paren = await cg.get_variable(config[CONF_TUYA_ID]) cg.add(var.set_tuya_parent(paren)) cg.add(var.set_sensor_id(config[CONF_SENSOR_DATAPOINT]))
CODEOWNERS = ["@ahpohl"] 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_CELSIUS, ICON_EMPTY, 1, DEVICE_CLASS_TEMPERATURE ), cv.Optional(CONF_HUMIDITY): sensor.sensor_schema( UNIT_PERCENT, ICON_EMPTY, 0, 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) )
cv.declare_id(WebServer), cv.Optional(CONF_PORT, default=80): cv.port, cv.Optional(CONF_CSS_URL, default="https://esphome.io/_static/webserver-v1.min.css"): cv.string, cv.Optional(CONF_CSS_INCLUDE): cv.file_, cv.Optional(CONF_JS_URL, default="https://esphome.io/_static/webserver-v1.min.js"): cv.string, cv.Optional(CONF_JS_INCLUDE): cv.file_, cv.Optional(CONF_AUTH): cv.Schema({ cv.Required(CONF_USERNAME): cv.All(cv.string_strict, cv.Length(min=1)), cv.Required(CONF_PASSWORD): cv.All(cv.string_strict, cv.Length(min=1)), }), cv.GenerateID(CONF_WEB_SERVER_BASE_ID): cv.use_id(web_server_base.WebServerBase), cv.Optional(CONF_INCLUDE_INTERNAL, default=False): cv.boolean, cv.Optional(CONF_OTA, default=True): cv.boolean, }, ).extend(cv.COMPONENT_SCHEMA), cv.only_with_arduino, )
FRAMEWORK_ESP_IDF = "esp-idf" FRAMEWORK_ARDUINO = "arduino" FRAMEWORK_SCHEMA = cv.typed_schema( { FRAMEWORK_ESP_IDF: ESP_IDF_FRAMEWORK_SCHEMA, FRAMEWORK_ARDUINO: ARDUINO_FRAMEWORK_SCHEMA, }, lower=True, space="-", default_type=FRAMEWORK_ARDUINO, ) CONFIG_SCHEMA = cv.All( cv.Schema({ cv.Required(CONF_BOARD): cv.string_strict, cv.Optional(CONF_VARIANT): cv.one_of(*VARIANTS, upper=True), cv.Optional(CONF_FRAMEWORK, default={}): FRAMEWORK_SCHEMA, }), _detect_variant, set_core_data, ) async def to_code(config): cg.add_platformio_option("board", config[CONF_BOARD]) cg.add_build_flag("-DUSE_ESP32") cg.add_define("ESPHOME_BOARD", config[CONF_BOARD]) cg.add_build_flag(f"-DUSE_ESP32_VARIANT_{config[CONF_VARIANT]}") cg.add_define("ESPHOME_VARIANT", VARIANT_FRIENDLY[config[CONF_VARIANT]])
CONF_POWER_USAGE_IN = 'current_power_usage_in' CONF_POWER_USAGE_OUT = 'current_power_usage_out' UNIT_VOLT_AMPS_REACTIVE_HOURS = 'varh' CONF_TEST_DATA = 'test_data' CONF_USE_TEST_DATA = 'use_test_data' CONF_DELAY_BEFORE_READING_DATA = 'delay_before_reading_data' CONF_MAX_WAIT_TIME_FOR_READING_DATA = 'max_wait_time_for_reading_data' CONF_NTP_SERVER = 'ntp_server' CONF_NTP_GMT_OFFSET = 'ntp_gmt_offset' CONF_NTP_DAYLIGHT_OFFSET = 'ntp_daylight_offset' CONF_INVERT_SERIAL = 'invert_serial' CONFIG_SCHEMA = cv.Schema({ cv.GenerateID(): cv.declare_id(SmartMeterSensorComponent), cv.Required(CONF_DECRYPTION_KEY): validate_decryption_key, cv.Required(CONF_TRIGGER_PIN): pins.gpio_output_pin_schema, cv.Required(CONF_RX_PIN): pins.gpio_output_pin_schema, cv.Required(CONF_TX_PIN): pins.gpio_output_pin_schema, cv.Optional(CONF_INVERT_SERIAL, default=False): boolean, cv.Optional(CONF_USE_TEST_DATA, default=False): boolean, cv.Optional(CONF_TEST_DATA): validate_test_data, cv.Optional(CONF_DELAY_BEFORE_READING_DATA, default=1000): int_,
DEPENDENCIES = ['i2c'] MULTI_CONF = True mcp23016_ns = cg.esphome_ns.namespace('mcp23016') MCP23016GPIOMode = mcp23016_ns.enum('MCP23016GPIOMode') MCP23016_GPIO_MODES = { 'INPUT': MCP23016GPIOMode.MCP23016_INPUT, 'OUTPUT': MCP23016GPIOMode.MCP23016_OUTPUT, } MCP23016 = mcp23016_ns.class_('MCP23016', cg.Component, i2c.I2CDevice) MCP23016GPIOPin = mcp23016_ns.class_('MCP23016GPIOPin', cg.GPIOPin) CONFIG_SCHEMA = cv.Schema({ cv.Required(CONF_ID): cv.declare_id(MCP23016), }).extend(cv.COMPONENT_SCHEMA).extend(i2c.i2c_device_schema(0x20)) def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) yield cg.register_component(var, config) yield i2c.register_i2c_device(var, config) CONF_MCP23016 = 'mcp23016' MCP23016_OUTPUT_PIN_SCHEMA = cv.Schema({ cv.Required(CONF_MCP23016): cv.use_id(MCP23016), cv.Required(CONF_NUMBER): cv.int_,
sensor.sensor_schema( unit_of_measurement=UNIT_MICROGRAMS_PER_CUBIC_METER, icon=ICON_CHEMICAL_WEAPON, accuracy_decimals=0, device_class=DEVICE_CLASS_PM10, state_class=STATE_CLASS_MEASUREMENT, ), cv.Optional(CONF_AQI): sensor.sensor_schema( unit_of_measurement=UNIT_INDEX, icon=ICON_CHEMICAL_WEAPON, accuracy_decimals=0, device_class=DEVICE_CLASS_AQI, state_class=STATE_CLASS_MEASUREMENT, ).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, cv.only_with_arduino, ) async def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) await cg.register_component(var, config) await i2c.register_i2c_device(var, config) if CONF_PM_1_0 in config:
pcf8574_ns = cg.esphome_ns.namespace('pcf8574') PCF8574GPIOMode = pcf8574_ns.enum('PCF8574GPIOMode') PCF8674_GPIO_MODES = { 'INPUT': PCF8574GPIOMode.PCF8574_INPUT, 'INPUT_PULLUP': PCF8574GPIOMode.PCF8574_INPUT_PULLUP, 'OUTPUT': PCF8574GPIOMode.PCF8574_OUTPUT, } PCF8574Component = pcf8574_ns.class_('PCF8574Component', cg.Component, i2c.I2CDevice) PCF8574GPIOPin = pcf8574_ns.class_('PCF8574GPIOPin', cg.GPIOPin) CONF_PCF8574 = 'pcf8574' CONF_PCF8575 = 'pcf8575' CONFIG_SCHEMA = cv.Schema({ cv.Required(CONF_ID): cv.declare_id(PCF8574Component), cv.Optional(CONF_PCF8575, default=False): cv.boolean, }).extend(cv.COMPONENT_SCHEMA).extend(i2c.i2c_device_schema(0x21)) def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) yield cg.register_component(var, config) yield i2c.register_i2c_device(var, config) cg.add(var.set_pcf8575(config[CONF_PCF8575])) PCF8574_OUTPUT_PIN_SCHEMA = cv.Schema({ cv.Required(CONF_PCF8574): cv.use_id(PCF8574Component), cv.Required(CONF_NUMBER):
return value def valid_project_name(value: str): if value.count(".") != 1: raise cv.Invalid("project name needs to have a namespace") value = value.replace(" ", "_") return value CONF_ESP8266_RESTORE_FROM_FLASH = "esp8266_restore_from_flash" CONFIG_SCHEMA = cv.All( cv.Schema({ cv.Required(CONF_NAME): cv.valid_name, cv.Optional(CONF_COMMENT): cv.string, cv.Required(CONF_BUILD_PATH): cv.string, cv.Optional(CONF_PLATFORMIO_OPTIONS, default={}): cv.Schema({ cv.string_strict: cv.Any([cv.string], cv.string), }), 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_,
"Valid characters for parts of a UID are 0123456789ABCDEF." ) from err if x < 0 or x > 255: raise cv.Invalid( "Valid values for UID parts (separated by '-') are 00 to FF") return value RC522BinarySensor = rc522_ns.class_('RC522BinarySensor', binary_sensor.BinarySensor) CONFIG_SCHEMA = binary_sensor.BINARY_SENSOR_SCHEMA.extend({ cv.GenerateID(): cv.declare_id(RC522BinarySensor), cv.GenerateID(CONF_RC522_ID): cv.use_id(RC522), cv.Required(CONF_UID): validate_uid, }) @coroutine def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) yield binary_sensor.register_binary_sensor(var, config) hub = yield cg.get_variable(config[CONF_RC522_ID]) cg.add(hub.register_tag(var)) addr = [HexInt(int(x, 16)) for x in config[CONF_UID].split('-')] cg.add(var.set_uid(addr))
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 from .. import hbridge_ns CODEOWNERS = ["@DotNetDann"] 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), }) async def to_code(config): var = cg.new_Pvariable(config[CONF_OUTPUT_ID]) await cg.register_component(var, config) await light.register_light(var, config) hside = await cg.get_variable(config[CONF_PIN_A]) cg.add(var.set_pina_pin(hside)) lside = await cg.get_variable(config[CONF_PIN_B]) cg.add(var.set_pinb_pin(lside))
def validate_pulse_meter_pin(value): value = pins.internal_gpio_input_pin_schema(value) if CORE.is_esp8266 and value[CONF_NUMBER] >= 16: raise cv.Invalid( "Pins GPIO16 and GPIO17 cannot be used as pulse counters on ESP8266." ) return value CONFIG_SCHEMA = sensor.sensor_schema( UNIT_PULSES_PER_MINUTE, ICON_PULSE, 2, DEVICE_CLASS_EMPTY, STATE_CLASS_MEASUREMENT).extend({ cv.GenerateID(): cv.declare_id(PulseMeterSensor), cv.Required(CONF_PIN): validate_pulse_meter_pin, cv.Optional(CONF_INTERNAL_FILTER, default="13us"): validate_internal_filter, cv.Optional(CONF_TIMEOUT, default="5min"): validate_timeout, cv.Optional(CONF_TOTAL): sensor.sensor_schema(UNIT_PULSES, ICON_PULSE, 0, DEVICE_CLASS_EMPTY, STATE_CLASS_NONE), }) async def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) await cg.register_component(var, config) await sensor.register_sensor(var, config)
CONFIG_BASE_COMPONENT_SCHEMA = cv.Schema({ cv.GenerateID(CONF_NEXTION_ID): cv.use_id(Nextion), cv.Optional(CONF_BACKGROUND_COLOR): cv.use_id(color), cv.Optional(CONF_FOREGROUND_COLOR): cv.use_id(color), cv.Optional(CONF_VISIBLE, default=True): cv.boolean, }) CONFIG_TEXT_COMPONENT_SCHEMA = CONFIG_BASE_COMPONENT_SCHEMA.extend( cv.Schema({ cv.Required(CONF_COMPONENT_NAME): NextionName, cv.Optional(CONF_FONT_ID): cv.int_range(min=0, max=255), })) CONFIG_BINARY_SENSOR_SCHEMA = CONFIG_BASE_COMPONENT_SCHEMA.extend( cv.Schema({ cv.Optional(CONF_COMPONENT_NAME): NextionName, cv.Optional(CONF_VARIABLE_NAME): NextionName, })) CONFIG_SENSOR_COMPONENT_SCHEMA = CONFIG_BINARY_SENSOR_SCHEMA.extend( cv.Schema({ cv.Optional(CONF_FONT_ID): cv.int_range(min=0, max=255), })) CONFIG_SWITCH_COMPONENT_SCHEMA = CONFIG_SENSOR_COMPONENT_SCHEMA.extend(
DimRelativeAction, ToggleAction, LightState, LightControlAction, AddressableLightState, AddressableSet, LightIsOnCondition, LightIsOffCondition, ) @automation.register_action( "light.toggle", ToggleAction, automation.maybe_simple_id({ cv.Required(CONF_ID): cv.use_id(LightState), cv.Optional(CONF_TRANSITION_LENGTH): cv.templatable(cv.positive_time_period_milliseconds), }), ) async def light_toggle_to_code(config, action_id, template_arg, args): paren = await cg.get_variable(config[CONF_ID]) var = cg.new_Pvariable(action_id, template_arg, paren) if CONF_TRANSITION_LENGTH in config: template_ = await cg.templatable(config[CONF_TRANSITION_LENGTH], args, cg.uint32) cg.add(var.set_transition_length(template_)) return var
"elevation": SensorType.SUN_SENSOR_ELEVATION, "azimuth": SensorType.SUN_SENSOR_AZIMUTH, } CONFIG_SCHEMA = ( sensor.sensor_schema( unit_of_measurement=UNIT_DEGREES, icon=ICON_WEATHER_SUNSET, accuracy_decimals=1, state_class=STATE_CLASS_NONE, ) .extend( { cv.GenerateID(): cv.declare_id(SunSensor), cv.GenerateID(CONF_SUN_ID): cv.use_id(Sun), cv.Required(CONF_TYPE): cv.enum(TYPES, lower=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) cg.add(var.set_type(config[CONF_TYPE])) paren = await cg.get_variable(config[CONF_SUN_ID]) cg.add(var.set_parent(paren))
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] != 'a': raise cv.Invalid( "The 'full_update_every' option is only available for models " "'1.54in', '2.13in' and '2.90in'.") 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)) def to_code(config):
cv.positive_time_period_milliseconds, }), cv.Optional(CONF_ON_DOUBLE_CLICK): automation.validate_automation({ cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(DoubleClickTrigger), cv.Optional(CONF_MIN_LENGTH, default='50ms'): cv.positive_time_period_milliseconds, cv.Optional(CONF_MAX_LENGTH, default='350ms'): cv.positive_time_period_milliseconds, }), cv.Optional(CONF_ON_MULTI_CLICK): automation.validate_automation({ cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(MultiClickTrigger), cv.Required(CONF_TIMING): cv.All([parse_multi_click_timing_str], validate_multi_click_timing), cv.Optional(CONF_INVALID_COOLDOWN, default='1s'): cv.positive_time_period_milliseconds, }), cv.Optional(CONF_ON_STATE): automation.validate_automation({ cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(StateTrigger), }), cv.Optional(CONF_INVERTED): cv.invalid("The inverted binary_sensor property has been replaced by the " "new 'invert' binary sensor filter. Please see " "https://esphome.io/components/binary_sensor/index.html."), })
UNIT_KILOGRAM, ICON_SCALE_BATHROOM, DEVICE_CLASS_EMPTY, ) DEPENDENCIES = ["esp32_ble_tracker"] xiaomi_miscale_ns = cg.esphome_ns.namespace("xiaomi_miscale") XiaomiMiscale = xiaomi_miscale_ns.class_("XiaomiMiscale", esp32_ble_tracker.ESPBTDeviceListener, cg.Component) CONFIG_SCHEMA = (cv.Schema({ cv.GenerateID(): cv.declare_id(XiaomiMiscale), cv.Required(CONF_MAC_ADDRESS): cv.mac_address, cv.Optional(CONF_WEIGHT): sensor.sensor_schema( UNIT_KILOGRAM, ICON_SCALE_BATHROOM, 2, DEVICE_CLASS_EMPTY, STATE_CLASS_MEASUREMENT, ), }).extend(esp32_ble_tracker.ESP_BLE_DEVICE_SCHEMA).extend(cv.COMPONENT_SCHEMA)) async def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) await cg.register_component(var, config)
CONF_MOSI_PIN, CONF_SPI_ID, CONF_CS_PIN, ) from esphome.core import coroutine, coroutine_with_priority CODEOWNERS = ["@esphome/core"] spi_ns = cg.esphome_ns.namespace("spi") SPIComponent = spi_ns.class_("SPIComponent", cg.Component) SPIDevice = spi_ns.class_("SPIDevice") MULTI_CONF = True CONFIG_SCHEMA = cv.All( cv.Schema({ cv.GenerateID(): cv.declare_id(SPIComponent), cv.Required(CONF_CLK_PIN): pins.gpio_output_pin_schema, cv.Optional(CONF_MISO_PIN): pins.gpio_input_pin_schema, cv.Optional(CONF_MOSI_PIN): pins.gpio_output_pin_schema, }), cv.has_at_least_one_key(CONF_MISO_PIN, CONF_MOSI_PIN), ) @coroutine_with_priority(1.0) def to_code(config): cg.add_global(spi_ns.using) var = cg.new_Pvariable(config[CONF_ID]) yield cg.register_component(var, config) clk = yield cg.gpio_pin_expression(config[CONF_CLK_PIN]) cg.add(var.set_clk(clk))
def register_addressable_effect(name, effect_type, default_name, schema, *extra_validators): # addressable effect can be used only in addressable ADDRESSABLE_EFFECTS.append(name) return register_effect(name, effect_type, default_name, schema, *extra_validators) @register_binary_effect( "lambda", LambdaLightEffect, "Lambda", { cv.Required(CONF_LAMBDA): cv.lambda_, cv.Optional(CONF_UPDATE_INTERVAL, default="0ms"): cv.update_interval, }, ) async def lambda_effect_to_code(config, effect_id): lambda_ = await cg.process_lambda(config[CONF_LAMBDA], [(bool, "initial_run")], return_type=cg.void) return cg.new_Pvariable(effect_id, config[CONF_NAME], lambda_, config[CONF_UPDATE_INTERVAL]) @register_binary_effect( "automation", AutomationLightEffect, "Automation",
INTERNAL_DAC_OPTIONS = { "left": i2s_dac_mode_t.I2S_DAC_CHANNEL_LEFT_EN, "right": i2s_dac_mode_t.I2S_DAC_CHANNEL_RIGHT_EN, "stereo": i2s_dac_mode_t.I2S_DAC_CHANNEL_BOTH_EN, } EXTERNAL_DAC_OPTIONS = ["mono", "stereo"] CONFIG_SCHEMA = cv.All( cv.typed_schema( { "internal": cv.Schema({ cv.GenerateID(): cv.declare_id(I2SAudioMediaPlayer), cv.Required(CONF_MODE): cv.enum(INTERNAL_DAC_OPTIONS, lower=True), }).extend(media_player.MEDIA_PLAYER_SCHEMA).extend( cv.COMPONENT_SCHEMA), "external": cv.Schema({ cv.GenerateID(): cv.declare_id(I2SAudioMediaPlayer), cv.Required(CONF_I2S_DOUT_PIN): pins.internal_gpio_output_pin_number, cv.Required(CONF_I2S_BCLK_PIN): pins.internal_gpio_output_pin_number, cv.Required(CONF_I2S_LRCLK_PIN): pins.internal_gpio_output_pin_number, cv.Optional(CONF_MUTE_PIN): pins.gpio_output_pin_schema,
CONF_STORE_BASELINE = "store_baseline" CONF_VOC_BASELINE = "voc_baseline" CONFIG_SCHEMA = (sensor.sensor_schema( UNIT_EMPTY, ICON_RADIATOR, 0, DEVICE_CLASS_EMPTY, STATE_CLASS_MEASUREMENT).extend({ cv.GenerateID(): cv.declare_id(SGP40Component), cv.Optional(CONF_STORE_BASELINE, default=True): cv.boolean, cv.Optional(CONF_VOC_BASELINE): cv.hex_uint16_t, cv.Optional(CONF_COMPENSATION): cv.Schema( { cv.Required(CONF_HUMIDITY_SOURCE): cv.use_id(sensor.Sensor), cv.Required(CONF_TEMPERATURE_SOURCE): cv.use_id(sensor.Sensor), }, ), }).extend(cv.polling_component_schema("60s")).extend( i2c.i2c_device_schema(0x59))) async def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) await cg.register_component(var, config) await i2c.register_i2c_device(var, config) await sensor.register_sensor(var, config) if CONF_COMPENSATION in config: compensation_config = config[CONF_COMPENSATION] sens = await cg.get_variable(compensation_config[CONF_HUMIDITY_SOURCE])
UNIT_PARTS_PER_BILLION, CONF_TEMPERATURE, CONF_HUMIDITY, ICON_PERIODIC_TABLE_CO2 DEPENDENCIES = ['i2c'] ccs811_ns = cg.esphome_ns.namespace('ccs811') CCS811Component = ccs811_ns.class_('CCS811Component', cg.PollingComponent, i2c.I2CDevice) CONF_ECO2 = 'eco2' CONF_TVOC = 'tvoc' CONF_BASELINE = 'baseline' CONFIG_SCHEMA = cv.Schema({ cv.GenerateID(): cv.declare_id(CCS811Component), cv.Required(CONF_ECO2): sensor.sensor_schema(UNIT_PARTS_PER_MILLION, ICON_PERIODIC_TABLE_CO2, 0), cv.Required(CONF_TVOC): sensor.sensor_schema(UNIT_PARTS_PER_BILLION, ICON_RADIATOR, 0), cv.Optional(CONF_BASELINE): cv.hex_uint16_t, cv.Optional(CONF_TEMPERATURE): cv.use_id(sensor.Sensor), cv.Optional(CONF_HUMIDITY): cv.use_id(sensor.Sensor), }).extend(cv.polling_component_schema('60s')).extend( i2c.i2c_device_schema(0x5A)) def to_code(config): var = cg.new_Pvariable(config[CONF_ID])
from esphome import pins, core from esphome.components import output import esphome.config_validation as cv import esphome.codegen as cg from esphome.const import CONF_ID, CONF_PIN, CONF_PERIOD slow_pwm_ns = cg.esphome_ns.namespace("slow_pwm") SlowPWMOutput = slow_pwm_ns.class_("SlowPWMOutput", output.FloatOutput, cg.Component) CONFIG_SCHEMA = output.FLOAT_OUTPUT_SCHEMA.extend({ cv.Required(CONF_ID): cv.declare_id(SlowPWMOutput), cv.Required(CONF_PIN): pins.gpio_output_pin_schema, cv.Required(CONF_PERIOD): cv.All( cv.positive_time_period_milliseconds, cv.Range(min=core.TimePeriod(milliseconds=100)), ), }).extend(cv.COMPONENT_SCHEMA) def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) yield cg.register_component(var, config) yield output.register_output(var, config) pin = yield cg.gpio_pin_expression(config[CONF_PIN]) cg.add(var.set_pin(pin)) cg.add(var.set_period(config[CONF_PERIOD]))
cg.add(var.set_device_class(config[CONF_DEVICE_CLASS])) if CONF_MQTT_ID in config: mqtt_ = cg.new_Pvariable(config[CONF_MQTT_ID], var) await mqtt.register_mqtt_component(mqtt_, config) async def register_cover(var, config): if not CORE.has_id(config[CONF_ID]): var = cg.Pvariable(config[CONF_ID], var) cg.add(cg.App.register_cover(var)) await setup_cover_core_(var, config) COVER_ACTION_SCHEMA = maybe_simple_id({ cv.Required(CONF_ID): cv.use_id(Cover), }) @automation.register_action("cover.open", OpenAction, COVER_ACTION_SCHEMA) async def cover_open_to_code(config, action_id, template_arg, args): paren = await cg.get_variable(config[CONF_ID]) return cg.new_Pvariable(action_id, template_arg, paren) @automation.register_action("cover.close", CloseAction, COVER_ACTION_SCHEMA) async def cover_close_to_code(config, action_id, template_arg, args): paren = await cg.get_variable(config[CONF_ID]) return cg.new_Pvariable(action_id, template_arg, paren)