mirror of
https://github.com/esphome/esphome.git
synced 2024-11-25 12:15:33 +01:00
Update components "if x in config" (#5181)
This commit is contained in:
parent
ce8091c14e
commit
f81c556b63
@ -28,6 +28,6 @@ async def to_code(config):
|
||||
dir_pin = await cg.gpio_pin_expression(config[CONF_DIR_PIN])
|
||||
cg.add(var.set_dir_pin(dir_pin))
|
||||
|
||||
if CONF_SLEEP_PIN in config:
|
||||
sleep_pin = await cg.gpio_pin_expression(config[CONF_SLEEP_PIN])
|
||||
if sleep_pin_config := config.get(CONF_SLEEP_PIN):
|
||||
sleep_pin = await cg.gpio_pin_expression(sleep_pin_config)
|
||||
cg.add(var.set_sleep_pin(sleep_pin))
|
||||
|
@ -89,14 +89,14 @@ async def to_code(config):
|
||||
pin = await cg.gpio_pin_expression(config[CONF_PIN])
|
||||
cg.add(var.set_pin(pin))
|
||||
|
||||
if CONF_RAW in config:
|
||||
cg.add(var.set_output_raw(config[CONF_RAW]))
|
||||
if raw := config.get(CONF_RAW):
|
||||
cg.add(var.set_output_raw(raw))
|
||||
|
||||
if CONF_ATTENUATION in config:
|
||||
if config[CONF_ATTENUATION] == "auto":
|
||||
if attenuation := config.get(CONF_ATTENUATION):
|
||||
if attenuation == "auto":
|
||||
cg.add(var.set_autorange(cg.global_ns.true))
|
||||
else:
|
||||
cg.add(var.set_attenuation(config[CONF_ATTENUATION]))
|
||||
cg.add(var.set_attenuation(attenuation))
|
||||
|
||||
if CORE.is_esp32:
|
||||
variant = get_esp32_variant()
|
||||
|
@ -48,16 +48,16 @@ async def to_code(config):
|
||||
await cg.register_component(var, config)
|
||||
await display.register_display(var, config)
|
||||
|
||||
if CONF_PIXEL_MAPPER in config:
|
||||
if pixel_mapper := config.get(CONF_PIXEL_MAPPER):
|
||||
pixel_mapper_template_ = await cg.process_lambda(
|
||||
config[CONF_PIXEL_MAPPER],
|
||||
pixel_mapper,
|
||||
[(int, "x"), (int, "y")],
|
||||
return_type=cg.int_,
|
||||
)
|
||||
cg.add(var.set_pixel_mapper(pixel_mapper_template_))
|
||||
|
||||
if CONF_LAMBDA in config:
|
||||
if lambda_config := config.get(CONF_LAMBDA):
|
||||
lambda_ = await cg.process_lambda(
|
||||
config[CONF_LAMBDA], [(display.DisplayRef, "it")], return_type=cg.void
|
||||
lambda_config, [(display.DisplayRef, "it")], return_type=cg.void
|
||||
)
|
||||
cg.add(var.set_writer(lambda_))
|
||||
|
@ -72,8 +72,8 @@ async def to_code(config):
|
||||
await cg.register_component(var, config)
|
||||
await i2c.register_i2c_device(var, config)
|
||||
|
||||
if CONF_IRQ_PIN in config:
|
||||
irq_pin = await cg.gpio_pin_expression(config[CONF_IRQ_PIN])
|
||||
if irq_pin_config := config.get(CONF_IRQ_PIN):
|
||||
irq_pin = await cg.gpio_pin_expression(irq_pin_config)
|
||||
cg.add(var.set_irq_pin(irq_pin))
|
||||
|
||||
for key in [
|
||||
|
@ -45,10 +45,10 @@ async def to_code(config):
|
||||
await cg.register_component(var, config)
|
||||
await i2c.register_i2c_device(var, config)
|
||||
|
||||
if CONF_TEMPERATURE in config:
|
||||
sens = await sensor.new_sensor(config[CONF_TEMPERATURE])
|
||||
if temperature := config.get(CONF_TEMPERATURE):
|
||||
sens = await sensor.new_sensor(temperature)
|
||||
cg.add(var.set_temperature_sensor(sens))
|
||||
|
||||
if CONF_HUMIDITY in config:
|
||||
sens = await sensor.new_sensor(config[CONF_HUMIDITY])
|
||||
if humidity := config.get(CONF_HUMIDITY):
|
||||
sens = await sensor.new_sensor(humidity)
|
||||
cg.add(var.set_humidity_sensor(sens))
|
||||
|
@ -99,8 +99,8 @@ async def register_alarm_control_panel(var, config):
|
||||
async def alarm_action_arm_away_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_CODE in config:
|
||||
templatable_ = await cg.templatable(config[CONF_CODE], args, cg.std_string)
|
||||
if code_config := config.get(CONF_CODE):
|
||||
templatable_ = await cg.templatable(code_config, args, cg.std_string)
|
||||
cg.add(var.set_code(templatable_))
|
||||
return var
|
||||
|
||||
@ -111,8 +111,8 @@ async def alarm_action_arm_away_to_code(config, action_id, template_arg, args):
|
||||
async def alarm_action_arm_home_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_CODE in config:
|
||||
templatable_ = await cg.templatable(config[CONF_CODE], args, cg.std_string)
|
||||
if code_config := config.get(CONF_CODE):
|
||||
templatable_ = await cg.templatable(code_config, args, cg.std_string)
|
||||
cg.add(var.set_code(templatable_))
|
||||
return var
|
||||
|
||||
@ -123,8 +123,8 @@ async def alarm_action_arm_home_to_code(config, action_id, template_arg, args):
|
||||
async def alarm_action_disarm_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_CODE in config:
|
||||
templatable_ = await cg.templatable(config[CONF_CODE], args, cg.std_string)
|
||||
if code_config := config.get(CONF_CODE):
|
||||
templatable_ = await cg.templatable(code_config, args, cg.std_string)
|
||||
cg.add(var.set_code(templatable_))
|
||||
return var
|
||||
|
||||
|
@ -60,26 +60,26 @@ async def to_code(config):
|
||||
await cg.register_component(var, config)
|
||||
await ble_client.register_ble_node(var, config)
|
||||
|
||||
if CONF_FLOW in config:
|
||||
sens = await sensor.new_sensor(config[CONF_FLOW])
|
||||
if flow_config := config.get(CONF_FLOW):
|
||||
sens = await sensor.new_sensor(flow_config)
|
||||
cg.add(var.set_flow_sensor(sens))
|
||||
|
||||
if CONF_HEAD in config:
|
||||
sens = await sensor.new_sensor(config[CONF_HEAD])
|
||||
if head_config := config.get(CONF_HEAD):
|
||||
sens = await sensor.new_sensor(head_config)
|
||||
cg.add(var.set_head_sensor(sens))
|
||||
|
||||
if CONF_POWER in config:
|
||||
sens = await sensor.new_sensor(config[CONF_POWER])
|
||||
if power_config := config.get(CONF_POWER):
|
||||
sens = await sensor.new_sensor(power_config)
|
||||
cg.add(var.set_power_sensor(sens))
|
||||
|
||||
if CONF_CURRENT in config:
|
||||
sens = await sensor.new_sensor(config[CONF_CURRENT])
|
||||
if current_config := config.get(CONF_CURRENT):
|
||||
sens = await sensor.new_sensor(current_config)
|
||||
cg.add(var.set_current_sensor(sens))
|
||||
|
||||
if CONF_SPEED in config:
|
||||
sens = await sensor.new_sensor(config[CONF_SPEED])
|
||||
if speed_config := config.get(CONF_SPEED):
|
||||
sens = await sensor.new_sensor(speed_config)
|
||||
cg.add(var.set_speed_sensor(sens))
|
||||
|
||||
if CONF_VOLTAGE in config:
|
||||
sens = await sensor.new_sensor(config[CONF_VOLTAGE])
|
||||
if voltage_config := config.get(CONF_VOLTAGE):
|
||||
sens = await sensor.new_sensor(voltage_config)
|
||||
cg.add(var.set_voltage_sensor(sens))
|
||||
|
@ -47,10 +47,10 @@ async def to_code(config):
|
||||
await cg.register_component(var, config)
|
||||
await i2c.register_i2c_device(var, config)
|
||||
|
||||
if CONF_TEMPERATURE in config:
|
||||
sens = await sensor.new_sensor(config[CONF_TEMPERATURE])
|
||||
if temperature_config := config.get(CONF_TEMPERATURE):
|
||||
sens = await sensor.new_sensor(temperature_config)
|
||||
cg.add(var.set_temperature_sensor(sens))
|
||||
|
||||
if CONF_HUMIDITY in config:
|
||||
sens = await sensor.new_sensor(config[CONF_HUMIDITY])
|
||||
if humidity_config := config.get(CONF_HUMIDITY):
|
||||
sens = await sensor.new_sensor(humidity_config)
|
||||
cg.add(var.set_humidity_sensor(sens))
|
||||
|
@ -44,10 +44,10 @@ async def to_code(config):
|
||||
await cg.register_component(var, config)
|
||||
await ble_client.register_ble_node(var, config)
|
||||
|
||||
if CONF_BATTERY_LEVEL in config:
|
||||
sens = await sensor.new_sensor(config[CONF_BATTERY_LEVEL])
|
||||
if battery_level_config := config.get(CONF_BATTERY_LEVEL):
|
||||
sens = await sensor.new_sensor(battery_level_config)
|
||||
cg.add(var.set_battery(sens))
|
||||
|
||||
if CONF_ILLUMINANCE in config:
|
||||
sens = await sensor.new_sensor(config[CONF_ILLUMINANCE])
|
||||
if illuminance_config := config.get(CONF_ILLUMINANCE):
|
||||
sens = await sensor.new_sensor(illuminance_config)
|
||||
cg.add(var.set_illuminance(sens))
|
||||
|
@ -115,8 +115,8 @@ async def animation_action_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_FRAME in config:
|
||||
template_ = await cg.templatable(config[CONF_FRAME], args, cg.uint16)
|
||||
if frame := config.get(CONF_FRAME):
|
||||
template_ = await cg.templatable(frame, args, cg.uint16)
|
||||
cg.add(var.set_frame(template_))
|
||||
return var
|
||||
|
||||
@ -289,8 +289,8 @@ async def to_code(config):
|
||||
espImage.IMAGE_TYPE[config[CONF_TYPE]],
|
||||
)
|
||||
cg.add(var.set_transparency(transparent))
|
||||
if CONF_LOOP in config:
|
||||
start = config[CONF_LOOP][CONF_START_FRAME]
|
||||
end = config[CONF_LOOP].get(CONF_END_FRAME, frames)
|
||||
count = config[CONF_LOOP].get(CONF_REPEAT, -1)
|
||||
if loop_config := config.get(CONF_LOOP):
|
||||
start = loop_config[CONF_START_FRAME]
|
||||
end = loop_config.get(CONF_END_FRAME, frames)
|
||||
count = loop_config.get(CONF_REPEAT, -1)
|
||||
cg.add(var.set_loop(start, end, count))
|
||||
|
@ -116,9 +116,8 @@ async def to_code(config):
|
||||
cg.add(var.register_user_service(trigger))
|
||||
await automation.build_automation(trigger, func_args, conf)
|
||||
|
||||
if CONF_ENCRYPTION in config:
|
||||
conf = config[CONF_ENCRYPTION]
|
||||
decoded = base64.b64decode(conf[CONF_KEY])
|
||||
if encryption_config := config.get(CONF_ENCRYPTION):
|
||||
decoded = base64.b64decode(encryption_config[CONF_KEY])
|
||||
cg.add(var.set_noise_psk(list(decoded)))
|
||||
cg.add_define("USE_API_NOISE")
|
||||
cg.add_library("esphome/noise-c", "0.1.4")
|
||||
|
@ -31,12 +31,10 @@ CONFIG_SCHEMA = cv.Schema(
|
||||
async def to_code(config):
|
||||
hub = await cg.get_variable(config[CONF_AS3935_ID])
|
||||
|
||||
if CONF_DISTANCE in config:
|
||||
conf = config[CONF_DISTANCE]
|
||||
distance_sensor = await sensor.new_sensor(conf)
|
||||
cg.add(hub.set_distance_sensor(distance_sensor))
|
||||
if distance_config := config.get(CONF_DISTANCE):
|
||||
sens = await sensor.new_sensor(distance_config)
|
||||
cg.add(hub.set_distance_sensor(sens))
|
||||
|
||||
if CONF_LIGHTNING_ENERGY in config:
|
||||
conf = config[CONF_LIGHTNING_ENERGY]
|
||||
lightning_energy_sensor = await sensor.new_sensor(conf)
|
||||
cg.add(hub.set_energy_sensor(lightning_energy_sensor))
|
||||
if lightning_energy_config := config.get(CONF_LIGHTNING_ENERGY):
|
||||
sens = await sensor.new_sensor(lightning_energy_config)
|
||||
cg.add(hub.set_energy_sensor(sens))
|
||||
|
@ -107,6 +107,6 @@ async def to_code(config):
|
||||
cg.add(var.set_astep(config[CONF_ASTEP]))
|
||||
|
||||
for conf_id, set_sensor_func in SENSORS.items():
|
||||
if conf_id in config:
|
||||
sens = await sensor.new_sensor(config[conf_id])
|
||||
if sens_config := config.get(conf_id):
|
||||
sens = await sensor.new_sensor(sens_config)
|
||||
cg.add(getattr(var, set_sensor_func)(sens))
|
||||
|
@ -83,18 +83,18 @@ async def to_code(config):
|
||||
|
||||
cg.add(var.set_address(config[CONF_MAC_ADDRESS].as_hex))
|
||||
|
||||
if CONF_TEMPERATURE in config:
|
||||
sens = await sensor.new_sensor(config[CONF_TEMPERATURE])
|
||||
if temperature_config := config.get(CONF_TEMPERATURE):
|
||||
sens = await sensor.new_sensor(temperature_config)
|
||||
cg.add(var.set_temperature(sens))
|
||||
if CONF_HUMIDITY in config:
|
||||
sens = await sensor.new_sensor(config[CONF_HUMIDITY])
|
||||
if humidity_config := config.get(CONF_HUMIDITY):
|
||||
sens = await sensor.new_sensor(humidity_config)
|
||||
cg.add(var.set_humidity(sens))
|
||||
if CONF_BATTERY_LEVEL in config:
|
||||
sens = await sensor.new_sensor(config[CONF_BATTERY_LEVEL])
|
||||
if battery_level_config := config.get(CONF_BATTERY_LEVEL):
|
||||
sens = await sensor.new_sensor(battery_level_config)
|
||||
cg.add(var.set_battery_level(sens))
|
||||
if CONF_BATTERY_VOLTAGE in config:
|
||||
sens = await sensor.new_sensor(config[CONF_BATTERY_VOLTAGE])
|
||||
if battery_voltage_config := config.get(CONF_BATTERY_VOLTAGE):
|
||||
sens = await sensor.new_sensor(battery_voltage_config)
|
||||
cg.add(var.set_battery_voltage(sens))
|
||||
if CONF_SIGNAL_STRENGTH in config:
|
||||
sens = await sensor.new_sensor(config[CONF_SIGNAL_STRENGTH])
|
||||
if signal_strength_config := config.get(CONF_SIGNAL_STRENGTH):
|
||||
sens = await sensor.new_sensor(signal_strength_config)
|
||||
cg.add(var.set_signal_strength(sens))
|
||||
|
@ -124,29 +124,29 @@ async def to_code(config):
|
||||
await cg.register_component(var, config)
|
||||
await spi.register_spi_device(var, config)
|
||||
|
||||
if CONF_VOLTAGE in config:
|
||||
sens = await sensor.new_sensor(config[CONF_VOLTAGE])
|
||||
if voltage_config := config.get(CONF_VOLTAGE):
|
||||
sens = await sensor.new_sensor(voltage_config)
|
||||
cg.add(var.set_voltage_sensor(sens))
|
||||
if CONF_CURRENT in config:
|
||||
sens = await sensor.new_sensor(config[CONF_CURRENT])
|
||||
if current_config := config.get(CONF_CURRENT):
|
||||
sens = await sensor.new_sensor(current_config)
|
||||
cg.add(var.set_current_sensor(sens))
|
||||
if CONF_POWER in config:
|
||||
sens = await sensor.new_sensor(config[CONF_POWER])
|
||||
if power_config := config.get(CONF_POWER):
|
||||
sens = await sensor.new_sensor(power_config)
|
||||
cg.add(var.set_power_sensor(sens))
|
||||
if CONF_REACTIVE_POWER in config:
|
||||
sens = await sensor.new_sensor(config[CONF_REACTIVE_POWER])
|
||||
if reactive_power_config := config.get(CONF_REACTIVE_POWER):
|
||||
sens = await sensor.new_sensor(reactive_power_config)
|
||||
cg.add(var.set_reactive_power_sensor(sens))
|
||||
if CONF_POWER_FACTOR in config:
|
||||
sens = await sensor.new_sensor(config[CONF_POWER_FACTOR])
|
||||
if power_factor_config := config.get(CONF_POWER_FACTOR):
|
||||
sens = await sensor.new_sensor(power_factor_config)
|
||||
cg.add(var.set_power_factor_sensor(sens))
|
||||
if CONF_FORWARD_ACTIVE_ENERGY in config:
|
||||
sens = await sensor.new_sensor(config[CONF_FORWARD_ACTIVE_ENERGY])
|
||||
if forward_active_energy_config := config.get(CONF_FORWARD_ACTIVE_ENERGY):
|
||||
sens = await sensor.new_sensor(forward_active_energy_config)
|
||||
cg.add(var.set_forward_active_energy_sensor(sens))
|
||||
if CONF_REVERSE_ACTIVE_ENERGY in config:
|
||||
sens = await sensor.new_sensor(config[CONF_REVERSE_ACTIVE_ENERGY])
|
||||
if reverse_active_energy_config := config.get(CONF_REVERSE_ACTIVE_ENERGY):
|
||||
sens = await sensor.new_sensor(reverse_active_energy_config)
|
||||
cg.add(var.set_reverse_active_energy_sensor(sens))
|
||||
if CONF_FREQUENCY in config:
|
||||
sens = await sensor.new_sensor(config[CONF_FREQUENCY])
|
||||
if frequency_config := config.get(CONF_FREQUENCY):
|
||||
sens = await sensor.new_sensor(frequency_config)
|
||||
cg.add(var.set_freq_sensor(sens))
|
||||
cg.add(var.set_line_freq(config[CONF_LINE_FREQUENCY]))
|
||||
cg.add(var.set_meter_constant(config[CONF_METER_CONSTANT]))
|
||||
|
@ -151,33 +151,35 @@ async def to_code(config):
|
||||
conf = config[phase]
|
||||
cg.add(var.set_volt_gain(i, conf[CONF_GAIN_VOLTAGE]))
|
||||
cg.add(var.set_ct_gain(i, conf[CONF_GAIN_CT]))
|
||||
if CONF_VOLTAGE in conf:
|
||||
sens = await sensor.new_sensor(conf[CONF_VOLTAGE])
|
||||
if voltage_config := conf.get(CONF_VOLTAGE):
|
||||
sens = await sensor.new_sensor(voltage_config)
|
||||
cg.add(var.set_voltage_sensor(i, sens))
|
||||
if CONF_CURRENT in conf:
|
||||
sens = await sensor.new_sensor(conf[CONF_CURRENT])
|
||||
if current_config := conf.get(CONF_CURRENT):
|
||||
sens = await sensor.new_sensor(current_config)
|
||||
cg.add(var.set_current_sensor(i, sens))
|
||||
if CONF_POWER in conf:
|
||||
sens = await sensor.new_sensor(conf[CONF_POWER])
|
||||
if power_config := conf.get(CONF_POWER):
|
||||
sens = await sensor.new_sensor(power_config)
|
||||
cg.add(var.set_power_sensor(i, sens))
|
||||
if CONF_REACTIVE_POWER in conf:
|
||||
sens = await sensor.new_sensor(conf[CONF_REACTIVE_POWER])
|
||||
if reactive_power_config := conf.get(CONF_REACTIVE_POWER):
|
||||
sens = await sensor.new_sensor(reactive_power_config)
|
||||
cg.add(var.set_reactive_power_sensor(i, sens))
|
||||
if CONF_POWER_FACTOR in conf:
|
||||
sens = await sensor.new_sensor(conf[CONF_POWER_FACTOR])
|
||||
if power_factor_config := conf.get(CONF_POWER_FACTOR):
|
||||
sens = await sensor.new_sensor(power_factor_config)
|
||||
cg.add(var.set_power_factor_sensor(i, sens))
|
||||
if CONF_FORWARD_ACTIVE_ENERGY in conf:
|
||||
sens = await sensor.new_sensor(conf[CONF_FORWARD_ACTIVE_ENERGY])
|
||||
if forward_active_energy_config := conf.get(CONF_FORWARD_ACTIVE_ENERGY):
|
||||
sens = await sensor.new_sensor(forward_active_energy_config)
|
||||
cg.add(var.set_forward_active_energy_sensor(i, sens))
|
||||
if CONF_REVERSE_ACTIVE_ENERGY in conf:
|
||||
sens = await sensor.new_sensor(conf[CONF_REVERSE_ACTIVE_ENERGY])
|
||||
if reverse_active_energy_config := conf.get(CONF_REVERSE_ACTIVE_ENERGY):
|
||||
sens = await sensor.new_sensor(reverse_active_energy_config)
|
||||
cg.add(var.set_reverse_active_energy_sensor(i, sens))
|
||||
if CONF_FREQUENCY in config:
|
||||
sens = await sensor.new_sensor(config[CONF_FREQUENCY])
|
||||
|
||||
if frequency_config := config.get(CONF_FREQUENCY):
|
||||
sens = await sensor.new_sensor(frequency_config)
|
||||
cg.add(var.set_freq_sensor(sens))
|
||||
if CONF_CHIP_TEMPERATURE in config:
|
||||
sens = await sensor.new_sensor(config[CONF_CHIP_TEMPERATURE])
|
||||
if chip_temperature_config := config.get(CONF_CHIP_TEMPERATURE):
|
||||
sens = await sensor.new_sensor(chip_temperature_config)
|
||||
cg.add(var.set_chip_temperature_sensor(sens))
|
||||
|
||||
cg.add(var.set_line_freq(config[CONF_LINE_FREQUENCY]))
|
||||
cg.add(var.set_current_phases(config[CONF_CURRENT_PHASES]))
|
||||
cg.add(var.set_pga_gain(config[CONF_GAIN_PGA]))
|
||||
|
@ -87,6 +87,6 @@ async def to_code(config):
|
||||
(CONF_MOISTURE, var.set_soil_moisture),
|
||||
(CONF_ILLUMINANCE, var.set_illuminance),
|
||||
]:
|
||||
if config_key in config:
|
||||
sens = await sensor.new_sensor(config[config_key])
|
||||
if sensor_config := config.get(config_key):
|
||||
sens = await sensor.new_sensor(sensor_config)
|
||||
cg.add(setter(sens))
|
||||
|
@ -57,19 +57,18 @@ async def to_code(config):
|
||||
var.get_idle_trigger(), [], config[CONF_IDLE_ACTION]
|
||||
)
|
||||
|
||||
if CONF_COOL_ACTION in config:
|
||||
if cool_action_config := config.get(CONF_COOL_ACTION):
|
||||
await automation.build_automation(
|
||||
var.get_cool_trigger(), [], config[CONF_COOL_ACTION]
|
||||
var.get_cool_trigger(), [], cool_action_config
|
||||
)
|
||||
cg.add(var.set_supports_cool(True))
|
||||
if CONF_HEAT_ACTION in config:
|
||||
if heat_action_config := config.get(CONF_HEAT_ACTION):
|
||||
await automation.build_automation(
|
||||
var.get_heat_trigger(), [], config[CONF_HEAT_ACTION]
|
||||
var.get_heat_trigger(), [], heat_action_config
|
||||
)
|
||||
cg.add(var.set_supports_heat(True))
|
||||
|
||||
if CONF_AWAY_CONFIG in config:
|
||||
away = config[CONF_AWAY_CONFIG]
|
||||
if away := config.get(CONF_AWAY_CONFIG):
|
||||
away_config = BangBangClimateTargetTempConfig(
|
||||
away[CONF_DEFAULT_TARGET_TEMPERATURE_LOW],
|
||||
away[CONF_DEFAULT_TARGET_TEMPERATURE_HIGH],
|
||||
|
@ -45,8 +45,8 @@ async def to_code(config):
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
await cg.register_component(var, config)
|
||||
await ble_client.register_ble_node(var, config)
|
||||
if CONF_TIME_ID in config:
|
||||
time_ = await cg.get_variable(config[CONF_TIME_ID])
|
||||
if time_id := config.get(CONF_TIME_ID):
|
||||
time_ = await cg.get_variable(time_id)
|
||||
cg.add(var.set_time_id(time_))
|
||||
if CONF_RECEIVE_TIMEOUT in config:
|
||||
cg.add(var.set_status_timeout(config[CONF_RECEIVE_TIMEOUT]))
|
||||
if receive_timeout := config.get(CONF_RECEIVE_TIMEOUT):
|
||||
cg.add(var.set_status_timeout(receive_timeout))
|
||||
|
@ -29,10 +29,10 @@ async def to_code(config):
|
||||
output_ = await cg.get_variable(config[CONF_OUTPUT])
|
||||
cg.add(var.set_output(output_))
|
||||
|
||||
if CONF_OSCILLATION_OUTPUT in config:
|
||||
oscillation_output = await cg.get_variable(config[CONF_OSCILLATION_OUTPUT])
|
||||
if oscillation_output_id := config.get(CONF_OSCILLATION_OUTPUT):
|
||||
oscillation_output = await cg.get_variable(oscillation_output_id)
|
||||
cg.add(var.set_oscillating(oscillation_output))
|
||||
|
||||
if CONF_DIRECTION_OUTPUT in config:
|
||||
direction_output = await cg.get_variable(config[CONF_DIRECTION_OUTPUT])
|
||||
if direction_output_id := config.get(CONF_DIRECTION_OUTPUT):
|
||||
direction_output = await cg.get_variable(direction_output_id)
|
||||
cg.add(var.set_direction(direction_output))
|
||||
|
@ -467,14 +467,14 @@ def binary_sensor_schema(
|
||||
async def setup_binary_sensor_core_(var, config):
|
||||
await setup_entity(var, config)
|
||||
|
||||
if CONF_DEVICE_CLASS in config:
|
||||
cg.add(var.set_device_class(config[CONF_DEVICE_CLASS]))
|
||||
if CONF_PUBLISH_INITIAL_STATE in config:
|
||||
cg.add(var.set_publish_initial_state(config[CONF_PUBLISH_INITIAL_STATE]))
|
||||
if CONF_INVERTED in config:
|
||||
cg.add(var.set_inverted(config[CONF_INVERTED]))
|
||||
if CONF_FILTERS in config:
|
||||
filters = await cg.build_registry_list(FILTER_REGISTRY, config[CONF_FILTERS])
|
||||
if device_class := config.get(CONF_DEVICE_CLASS):
|
||||
cg.add(var.set_device_class(device_class))
|
||||
if publish_initial_state := config.get(CONF_PUBLISH_INITIAL_STATE):
|
||||
cg.add(var.set_publish_initial_state(publish_initial_state))
|
||||
if inverted := config.get(CONF_INVERTED):
|
||||
cg.add(var.set_inverted(inverted))
|
||||
if filters_config := config.get(CONF_FILTERS):
|
||||
filters = await cg.build_registry_list(FILTER_REGISTRY, filters_config)
|
||||
cg.add(var.add_filters(filters))
|
||||
|
||||
for conf in config.get(CONF_ON_PRESS, []):
|
||||
@ -518,8 +518,8 @@ async def setup_binary_sensor_core_(var, config):
|
||||
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
|
||||
await automation.build_automation(trigger, [(bool, "x")], conf)
|
||||
|
||||
if CONF_MQTT_ID in config:
|
||||
mqtt_ = cg.new_Pvariable(config[CONF_MQTT_ID], var)
|
||||
if mqtt_id := config.get(CONF_MQTT_ID):
|
||||
mqtt_ = cg.new_Pvariable(mqtt_id, var)
|
||||
await mqtt.register_mqtt_component(mqtt_, config)
|
||||
|
||||
|
||||
|
@ -93,35 +93,27 @@ async def to_code(config):
|
||||
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)
|
||||
if voltage_config := config.get(CONF_VOLTAGE):
|
||||
sens = await sensor.new_sensor(voltage_config)
|
||||
cg.add(var.set_voltage_sensor(sens))
|
||||
if CONF_CURRENT_1 in config:
|
||||
conf = config[CONF_CURRENT_1]
|
||||
sens = await sensor.new_sensor(conf)
|
||||
if current_1_config := config.get(CONF_CURRENT_1):
|
||||
sens = await sensor.new_sensor(current_1_config)
|
||||
cg.add(var.set_current_sensor_1(sens))
|
||||
if CONF_CURRENT_2 in config:
|
||||
conf = config[CONF_CURRENT_2]
|
||||
sens = await sensor.new_sensor(conf)
|
||||
if current_2_config := config.get(CONF_CURRENT_2):
|
||||
sens = await sensor.new_sensor(current_2_config)
|
||||
cg.add(var.set_current_sensor_2(sens))
|
||||
if CONF_ACTIVE_POWER_1 in config:
|
||||
conf = config[CONF_ACTIVE_POWER_1]
|
||||
sens = await sensor.new_sensor(conf)
|
||||
if active_power_1_config := config.get(CONF_ACTIVE_POWER_1):
|
||||
sens = await sensor.new_sensor(active_power_1_config)
|
||||
cg.add(var.set_power_sensor_1(sens))
|
||||
if CONF_ACTIVE_POWER_2 in config:
|
||||
conf = config[CONF_ACTIVE_POWER_2]
|
||||
sens = await sensor.new_sensor(conf)
|
||||
if active_power_2_config := config.get(CONF_ACTIVE_POWER_2):
|
||||
sens = await sensor.new_sensor(active_power_2_config)
|
||||
cg.add(var.set_power_sensor_2(sens))
|
||||
if CONF_ENERGY_1 in config:
|
||||
conf = config[CONF_ENERGY_1]
|
||||
sens = await sensor.new_sensor(conf)
|
||||
if energy_1_config := config.get(CONF_ENERGY_1):
|
||||
sens = await sensor.new_sensor(energy_1_config)
|
||||
cg.add(var.set_energy_sensor_1(sens))
|
||||
if CONF_ENERGY_2 in config:
|
||||
conf = config[CONF_ENERGY_2]
|
||||
sens = await sensor.new_sensor(conf)
|
||||
if energy_2_config := config.get(CONF_ENERGY_2):
|
||||
sens = await sensor.new_sensor(energy_2_config)
|
||||
cg.add(var.set_energy_sensor_2(sens))
|
||||
if CONF_ENERGY_TOTAL in config:
|
||||
conf = config[CONF_ENERGY_TOTAL]
|
||||
sens = await sensor.new_sensor(conf)
|
||||
if energy_total_config := config.get(CONF_ENERGY_TOTAL):
|
||||
sens = await sensor.new_sensor(energy_total_config)
|
||||
cg.add(var.set_energy_sensor_sum(sens))
|
||||
|
@ -79,27 +79,21 @@ async def to_code(config):
|
||||
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)
|
||||
if voltage_config := config.get(CONF_VOLTAGE):
|
||||
sens = await sensor.new_sensor(voltage_config)
|
||||
cg.add(var.set_voltage_sensor(sens))
|
||||
if CONF_CURRENT in config:
|
||||
conf = config[CONF_CURRENT]
|
||||
sens = await sensor.new_sensor(conf)
|
||||
if current_config := config.get(CONF_CURRENT):
|
||||
sens = await sensor.new_sensor(current_config)
|
||||
cg.add(var.set_current_sensor(sens))
|
||||
if CONF_POWER in config:
|
||||
conf = config[CONF_POWER]
|
||||
sens = await sensor.new_sensor(conf)
|
||||
if power_config := config.get(CONF_POWER):
|
||||
sens = await sensor.new_sensor(power_config)
|
||||
cg.add(var.set_power_sensor(sens))
|
||||
if CONF_ENERGY in config:
|
||||
conf = config[CONF_ENERGY]
|
||||
sens = await sensor.new_sensor(conf)
|
||||
if energy_config := config.get(CONF_ENERGY):
|
||||
sens = await sensor.new_sensor(energy_config)
|
||||
cg.add(var.set_energy_sensor(sens))
|
||||
if CONF_INTERNAL_TEMPERATURE in config:
|
||||
conf = config[CONF_INTERNAL_TEMPERATURE]
|
||||
sens = await sensor.new_sensor(conf)
|
||||
if internal_temperature_config := config.get(CONF_INTERNAL_TEMPERATURE):
|
||||
sens = await sensor.new_sensor(internal_temperature_config)
|
||||
cg.add(var.set_internal_temperature_sensor(sens))
|
||||
if CONF_EXTERNAL_TEMPERATURE in config:
|
||||
conf = config[CONF_EXTERNAL_TEMPERATURE]
|
||||
sens = await sensor.new_sensor(conf)
|
||||
if external_temperature_config := config.get(CONF_EXTERNAL_TEMPERATURE):
|
||||
sens = await sensor.new_sensor(external_temperature_config)
|
||||
cg.add(var.set_external_temperature_sensor(sens))
|
||||
|
@ -71,23 +71,18 @@ async def to_code(config):
|
||||
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)
|
||||
if voltage_config := config.get(CONF_VOLTAGE):
|
||||
sens = await sensor.new_sensor(voltage_config)
|
||||
cg.add(var.set_voltage_sensor(sens))
|
||||
if CONF_CURRENT in config:
|
||||
conf = config[CONF_CURRENT]
|
||||
sens = await sensor.new_sensor(conf)
|
||||
if current_config := config.get(CONF_CURRENT):
|
||||
sens = await sensor.new_sensor(current_config)
|
||||
cg.add(var.set_current_sensor(sens))
|
||||
if CONF_POWER in config:
|
||||
conf = config[CONF_POWER]
|
||||
sens = await sensor.new_sensor(conf)
|
||||
if power_config := config.get(CONF_POWER):
|
||||
sens = await sensor.new_sensor(power_config)
|
||||
cg.add(var.set_power_sensor(sens))
|
||||
if CONF_ENERGY in config:
|
||||
conf = config[CONF_ENERGY]
|
||||
sens = await sensor.new_sensor(conf)
|
||||
if energy_config := config.get(CONF_ENERGY):
|
||||
sens = await sensor.new_sensor(energy_config)
|
||||
cg.add(var.set_energy_sensor(sens))
|
||||
if CONF_FREQUENCY in config:
|
||||
conf = config[CONF_FREQUENCY]
|
||||
sens = await sensor.new_sensor(conf)
|
||||
if frequency_config := config.get(CONF_FREQUENCY):
|
||||
sens = await sensor.new_sensor(frequency_config)
|
||||
cg.add(var.set_frequency_sensor(sens))
|
||||
|
@ -129,32 +129,18 @@ async def characteristic_sensor_to_code(config):
|
||||
)
|
||||
cg.add(var.set_char_uuid128(uuid128))
|
||||
|
||||
if CONF_DESCRIPTOR_UUID in config:
|
||||
if len(config[CONF_DESCRIPTOR_UUID]) == len(esp32_ble_tracker.bt_uuid16_format):
|
||||
cg.add(
|
||||
var.set_descr_uuid16(
|
||||
esp32_ble_tracker.as_hex(config[CONF_DESCRIPTOR_UUID])
|
||||
)
|
||||
)
|
||||
elif len(config[CONF_DESCRIPTOR_UUID]) == len(
|
||||
esp32_ble_tracker.bt_uuid32_format
|
||||
):
|
||||
cg.add(
|
||||
var.set_descr_uuid32(
|
||||
esp32_ble_tracker.as_hex(config[CONF_DESCRIPTOR_UUID])
|
||||
)
|
||||
)
|
||||
elif len(config[CONF_DESCRIPTOR_UUID]) == len(
|
||||
esp32_ble_tracker.bt_uuid128_format
|
||||
):
|
||||
uuid128 = esp32_ble_tracker.as_reversed_hex_array(
|
||||
config[CONF_DESCRIPTOR_UUID]
|
||||
)
|
||||
if descriptor_uuid := config.get(CONF_DESCRIPTOR_UUID):
|
||||
if len(descriptor_uuid) == len(esp32_ble_tracker.bt_uuid16_format):
|
||||
cg.add(var.set_descr_uuid16(esp32_ble_tracker.as_hex(descriptor_uuid)))
|
||||
elif len(descriptor_uuid) == len(esp32_ble_tracker.bt_uuid32_format):
|
||||
cg.add(var.set_descr_uuid32(esp32_ble_tracker.as_hex(descriptor_uuid)))
|
||||
elif len(descriptor_uuid) == len(esp32_ble_tracker.bt_uuid128_format):
|
||||
uuid128 = esp32_ble_tracker.as_reversed_hex_array(descriptor_uuid)
|
||||
cg.add(var.set_descr_uuid128(uuid128))
|
||||
|
||||
if CONF_LAMBDA in config:
|
||||
if lambda_config := config.get(CONF_LAMBDA):
|
||||
lambda_ = await cg.process_lambda(
|
||||
config[CONF_LAMBDA], [(adv_data_t_const_ref, "x")], return_type=cg.float_
|
||||
lambda_config, [(adv_data_t_const_ref, "x")], return_type=cg.float_
|
||||
)
|
||||
cg.add(var.set_data_to_value(lambda_))
|
||||
|
||||
|
@ -88,27 +88,13 @@ async def to_code(config):
|
||||
)
|
||||
cg.add(var.set_char_uuid128(uuid128))
|
||||
|
||||
if CONF_DESCRIPTOR_UUID in config:
|
||||
if len(config[CONF_DESCRIPTOR_UUID]) == len(esp32_ble_tracker.bt_uuid16_format):
|
||||
cg.add(
|
||||
var.set_descr_uuid16(
|
||||
esp32_ble_tracker.as_hex(config[CONF_DESCRIPTOR_UUID])
|
||||
)
|
||||
)
|
||||
elif len(config[CONF_DESCRIPTOR_UUID]) == len(
|
||||
esp32_ble_tracker.bt_uuid32_format
|
||||
):
|
||||
cg.add(
|
||||
var.set_descr_uuid32(
|
||||
esp32_ble_tracker.as_hex(config[CONF_DESCRIPTOR_UUID])
|
||||
)
|
||||
)
|
||||
elif len(config[CONF_DESCRIPTOR_UUID]) == len(
|
||||
esp32_ble_tracker.bt_uuid128_format
|
||||
):
|
||||
uuid128 = esp32_ble_tracker.as_reversed_hex_array(
|
||||
config[CONF_DESCRIPTOR_UUID]
|
||||
)
|
||||
if descriptor_uuid := config:
|
||||
if len(descriptor_uuid) == len(esp32_ble_tracker.bt_uuid16_format):
|
||||
cg.add(var.set_descr_uuid16(esp32_ble_tracker.as_hex(descriptor_uuid)))
|
||||
elif len(descriptor_uuid) == len(esp32_ble_tracker.bt_uuid32_format):
|
||||
cg.add(var.set_descr_uuid32(esp32_ble_tracker.as_hex(descriptor_uuid)))
|
||||
elif len(descriptor_uuid) == len(esp32_ble_tracker.bt_uuid128_format):
|
||||
uuid128 = esp32_ble_tracker.as_reversed_hex_array(descriptor_uuid)
|
||||
cg.add(var.set_descr_uuid128(uuid128))
|
||||
|
||||
await cg.register_component(var, config)
|
||||
|
@ -55,35 +55,27 @@ async def to_code(config):
|
||||
await cg.register_component(var, config)
|
||||
await esp32_ble_tracker.register_ble_device(var, config)
|
||||
|
||||
if CONF_MIN_RSSI in config:
|
||||
cg.add(var.set_minimum_rssi(config[CONF_MIN_RSSI]))
|
||||
if min_rssi := config.get(CONF_MIN_RSSI):
|
||||
cg.add(var.set_minimum_rssi(min_rssi))
|
||||
|
||||
if CONF_MAC_ADDRESS in config:
|
||||
cg.add(var.set_address(config[CONF_MAC_ADDRESS].as_hex))
|
||||
if mac_address := config.get(CONF_MAC_ADDRESS):
|
||||
cg.add(var.set_address(mac_address.as_hex))
|
||||
|
||||
if CONF_SERVICE_UUID in config:
|
||||
if len(config[CONF_SERVICE_UUID]) == len(esp32_ble_tracker.bt_uuid16_format):
|
||||
cg.add(
|
||||
var.set_service_uuid16(
|
||||
esp32_ble_tracker.as_hex(config[CONF_SERVICE_UUID])
|
||||
)
|
||||
)
|
||||
elif len(config[CONF_SERVICE_UUID]) == len(esp32_ble_tracker.bt_uuid32_format):
|
||||
cg.add(
|
||||
var.set_service_uuid32(
|
||||
esp32_ble_tracker.as_hex(config[CONF_SERVICE_UUID])
|
||||
)
|
||||
)
|
||||
elif len(config[CONF_SERVICE_UUID]) == len(esp32_ble_tracker.bt_uuid128_format):
|
||||
uuid128 = esp32_ble_tracker.as_reversed_hex_array(config[CONF_SERVICE_UUID])
|
||||
if service_uuid := config.get(CONF_SERVICE_UUID):
|
||||
if len(service_uuid) == len(esp32_ble_tracker.bt_uuid16_format):
|
||||
cg.add(var.set_service_uuid16(esp32_ble_tracker.as_hex(service_uuid)))
|
||||
elif len(service_uuid) == len(esp32_ble_tracker.bt_uuid32_format):
|
||||
cg.add(var.set_service_uuid32(esp32_ble_tracker.as_hex(service_uuid)))
|
||||
elif len(service_uuid) == len(esp32_ble_tracker.bt_uuid128_format):
|
||||
uuid128 = esp32_ble_tracker.as_reversed_hex_array(service_uuid)
|
||||
cg.add(var.set_service_uuid128(uuid128))
|
||||
|
||||
if CONF_IBEACON_UUID in config:
|
||||
ibeacon_uuid = esp32_ble_tracker.as_hex_array(str(config[CONF_IBEACON_UUID]))
|
||||
if ibeacon_uuid := config.get(CONF_IBEACON_UUID):
|
||||
ibeacon_uuid = esp32_ble_tracker.as_hex_array(str(ibeacon_uuid))
|
||||
cg.add(var.set_ibeacon_uuid(ibeacon_uuid))
|
||||
|
||||
if CONF_IBEACON_MAJOR in config:
|
||||
cg.add(var.set_ibeacon_major(config[CONF_IBEACON_MAJOR]))
|
||||
if ibeacon_major := config.get(CONF_IBEACON_MAJOR):
|
||||
cg.add(var.set_ibeacon_major(ibeacon_major))
|
||||
|
||||
if CONF_IBEACON_MINOR in config:
|
||||
cg.add(var.set_ibeacon_minor(config[CONF_IBEACON_MINOR]))
|
||||
if ibeacon_minor := config.get(CONF_IBEACON_MINOR):
|
||||
cg.add(var.set_ibeacon_minor(ibeacon_minor))
|
||||
|
@ -57,32 +57,24 @@ async def to_code(config):
|
||||
await cg.register_component(var, config)
|
||||
await esp32_ble_tracker.register_ble_device(var, config)
|
||||
|
||||
if CONF_MAC_ADDRESS in config:
|
||||
cg.add(var.set_address(config[CONF_MAC_ADDRESS].as_hex))
|
||||
if mac_address := config.get(CONF_MAC_ADDRESS):
|
||||
cg.add(var.set_address(mac_address.as_hex))
|
||||
|
||||
if CONF_SERVICE_UUID in config:
|
||||
if len(config[CONF_SERVICE_UUID]) == len(esp32_ble_tracker.bt_uuid16_format):
|
||||
cg.add(
|
||||
var.set_service_uuid16(
|
||||
esp32_ble_tracker.as_hex(config[CONF_SERVICE_UUID])
|
||||
)
|
||||
)
|
||||
elif len(config[CONF_SERVICE_UUID]) == len(esp32_ble_tracker.bt_uuid32_format):
|
||||
cg.add(
|
||||
var.set_service_uuid32(
|
||||
esp32_ble_tracker.as_hex(config[CONF_SERVICE_UUID])
|
||||
)
|
||||
)
|
||||
elif len(config[CONF_SERVICE_UUID]) == len(esp32_ble_tracker.bt_uuid128_format):
|
||||
uuid128 = esp32_ble_tracker.as_reversed_hex_array(config[CONF_SERVICE_UUID])
|
||||
if service_uuid := config.get(CONF_SERVICE_UUID):
|
||||
if len(service_uuid) == len(esp32_ble_tracker.bt_uuid16_format):
|
||||
cg.add(var.set_service_uuid16(esp32_ble_tracker.as_hex(service_uuid)))
|
||||
elif len(service_uuid) == len(esp32_ble_tracker.bt_uuid32_format):
|
||||
cg.add(var.set_service_uuid32(esp32_ble_tracker.as_hex(service_uuid)))
|
||||
elif len(service_uuid) == len(esp32_ble_tracker.bt_uuid128_format):
|
||||
uuid128 = esp32_ble_tracker.as_reversed_hex_array(service_uuid)
|
||||
cg.add(var.set_service_uuid128(uuid128))
|
||||
|
||||
if CONF_IBEACON_UUID in config:
|
||||
ibeacon_uuid = esp32_ble_tracker.as_hex_array(str(config[CONF_IBEACON_UUID]))
|
||||
if ibeacon_uuid := config.get(CONF_IBEACON_UUID):
|
||||
ibeacon_uuid = esp32_ble_tracker.as_hex_array(str(ibeacon_uuid))
|
||||
cg.add(var.set_ibeacon_uuid(ibeacon_uuid))
|
||||
|
||||
if CONF_IBEACON_MAJOR in config:
|
||||
cg.add(var.set_ibeacon_major(config[CONF_IBEACON_MAJOR]))
|
||||
if ibeacon_major := config.get(CONF_IBEACON_MAJOR):
|
||||
cg.add(var.set_ibeacon_major(ibeacon_major))
|
||||
|
||||
if CONF_IBEACON_MINOR in config:
|
||||
cg.add(var.set_ibeacon_minor(config[CONF_IBEACON_MINOR]))
|
||||
if ibeacon_minor := config.get(CONF_IBEACON_MINOR):
|
||||
cg.add(var.set_ibeacon_minor(ibeacon_minor))
|
||||
|
@ -98,22 +98,19 @@ async def to_code(config):
|
||||
await cg.register_component(var, config)
|
||||
await i2c.register_i2c_device(var, config)
|
||||
|
||||
if CONF_TEMPERATURE in config:
|
||||
conf = config[CONF_TEMPERATURE]
|
||||
sens = await sensor.new_sensor(conf)
|
||||
if temperature_config := config.get(CONF_TEMPERATURE):
|
||||
sens = await sensor.new_sensor(temperature_config)
|
||||
cg.add(var.set_temperature_sensor(sens))
|
||||
cg.add(var.set_temperature_oversampling(conf[CONF_OVERSAMPLING]))
|
||||
cg.add(var.set_temperature_oversampling(temperature_config[CONF_OVERSAMPLING]))
|
||||
|
||||
if CONF_PRESSURE in config:
|
||||
conf = config[CONF_PRESSURE]
|
||||
sens = await sensor.new_sensor(conf)
|
||||
if pressure_config := config.get(CONF_PRESSURE):
|
||||
sens = await sensor.new_sensor(pressure_config)
|
||||
cg.add(var.set_pressure_sensor(sens))
|
||||
cg.add(var.set_pressure_oversampling(conf[CONF_OVERSAMPLING]))
|
||||
cg.add(var.set_pressure_oversampling(pressure_config[CONF_OVERSAMPLING]))
|
||||
|
||||
if CONF_HUMIDITY in config:
|
||||
conf = config[CONF_HUMIDITY]
|
||||
sens = await sensor.new_sensor(conf)
|
||||
if humidity_config := config.get(CONF_HUMIDITY):
|
||||
sens = await sensor.new_sensor(humidity_config)
|
||||
cg.add(var.set_humidity_sensor(sens))
|
||||
cg.add(var.set_humidity_oversampling(conf[CONF_OVERSAMPLING]))
|
||||
cg.add(var.set_humidity_oversampling(humidity_config[CONF_OVERSAMPLING]))
|
||||
|
||||
cg.add(var.set_iir_filter(config[CONF_IIR_FILTER]))
|
||||
|
@ -130,27 +130,23 @@ async def to_code(config):
|
||||
await cg.register_component(var, config)
|
||||
await i2c.register_i2c_device(var, config)
|
||||
|
||||
if CONF_TEMPERATURE in config:
|
||||
conf = config[CONF_TEMPERATURE]
|
||||
sens = await sensor.new_sensor(conf)
|
||||
if temperature_config := config.get(CONF_TEMPERATURE):
|
||||
sens = await sensor.new_sensor(temperature_config)
|
||||
cg.add(var.set_temperature_sensor(sens))
|
||||
cg.add(var.set_temperature_oversampling(conf[CONF_OVERSAMPLING]))
|
||||
cg.add(var.set_temperature_oversampling(temperature_config[CONF_OVERSAMPLING]))
|
||||
|
||||
if CONF_PRESSURE in config:
|
||||
conf = config[CONF_PRESSURE]
|
||||
sens = await sensor.new_sensor(conf)
|
||||
if pressure_config := config.get(CONF_PRESSURE):
|
||||
sens = await sensor.new_sensor(pressure_config)
|
||||
cg.add(var.set_pressure_sensor(sens))
|
||||
cg.add(var.set_pressure_oversampling(conf[CONF_OVERSAMPLING]))
|
||||
cg.add(var.set_pressure_oversampling(pressure_config[CONF_OVERSAMPLING]))
|
||||
|
||||
if CONF_HUMIDITY in config:
|
||||
conf = config[CONF_HUMIDITY]
|
||||
sens = await sensor.new_sensor(conf)
|
||||
if humidity_config := config.get(CONF_HUMIDITY):
|
||||
sens = await sensor.new_sensor(humidity_config)
|
||||
cg.add(var.set_humidity_sensor(sens))
|
||||
cg.add(var.set_humidity_oversampling(conf[CONF_OVERSAMPLING]))
|
||||
cg.add(var.set_humidity_oversampling(humidity_config[CONF_OVERSAMPLING]))
|
||||
|
||||
if CONF_GAS_RESISTANCE in config:
|
||||
conf = config[CONF_GAS_RESISTANCE]
|
||||
sens = await sensor.new_sensor(conf)
|
||||
if gas_resistance_config := config.get(CONF_GAS_RESISTANCE):
|
||||
sens = await sensor.new_sensor(gas_resistance_config)
|
||||
cg.add(var.set_gas_resistance_sensor(sens))
|
||||
|
||||
cg.add(var.set_iir_filter(IIR_FILTER_OPTIONS[config[CONF_IIR_FILTER]]))
|
||||
|
@ -108,12 +108,13 @@ CONFIG_SCHEMA = cv.Schema(
|
||||
|
||||
|
||||
async def setup_conf(config, key, hub):
|
||||
if key in config:
|
||||
conf = config[key]
|
||||
sens = await sensor.new_sensor(conf)
|
||||
if sensor_config := config.get(key):
|
||||
sens = await sensor.new_sensor(sensor_config)
|
||||
cg.add(getattr(hub, f"set_{key}_sensor")(sens))
|
||||
if CONF_SAMPLE_RATE in conf:
|
||||
cg.add(getattr(hub, f"set_{key}_sample_rate")(conf[CONF_SAMPLE_RATE]))
|
||||
if CONF_SAMPLE_RATE in sensor_config:
|
||||
cg.add(
|
||||
getattr(hub, f"set_{key}_sample_rate")(sensor_config[CONF_SAMPLE_RATE])
|
||||
)
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
|
@ -21,9 +21,8 @@ CONFIG_SCHEMA = cv.Schema(
|
||||
|
||||
|
||||
async def setup_conf(config, key, hub):
|
||||
if key in config:
|
||||
conf = config[key]
|
||||
sens = await text_sensor.new_text_sensor(conf)
|
||||
if sensor_config := config.get(key):
|
||||
sens = await text_sensor.new_text_sensor(sensor_config)
|
||||
cg.add(getattr(hub, f"set_{key}_text_sensor")(sens))
|
||||
|
||||
|
||||
|
@ -47,12 +47,10 @@ async def to_code(config):
|
||||
await cg.register_component(var, config)
|
||||
await i2c.register_i2c_device(var, config)
|
||||
|
||||
if CONF_TEMPERATURE in config:
|
||||
conf = config[CONF_TEMPERATURE]
|
||||
sens = await sensor.new_sensor(conf)
|
||||
if temperature_config := config.get(CONF_TEMPERATURE):
|
||||
sens = await sensor.new_sensor(temperature_config)
|
||||
cg.add(var.set_temperature(sens))
|
||||
|
||||
if CONF_PRESSURE in config:
|
||||
conf = config[CONF_PRESSURE]
|
||||
sens = await sensor.new_sensor(conf)
|
||||
if pressure_config := config.get(CONF_PRESSURE):
|
||||
sens = await sensor.new_sensor(pressure_config)
|
||||
cg.add(var.set_pressure(sens))
|
||||
|
@ -83,16 +83,14 @@ async def to_code(config):
|
||||
await cg.register_component(var, config)
|
||||
await i2c.register_i2c_device(var, config)
|
||||
|
||||
if CONF_TEMPERATURE in config:
|
||||
conf = config[CONF_TEMPERATURE]
|
||||
sens = await sensor.new_sensor(conf)
|
||||
if temperature_config := config.get(CONF_TEMPERATURE):
|
||||
sens = await sensor.new_sensor(temperature_config)
|
||||
cg.add(var.set_temperature_sensor(sens))
|
||||
cg.add(var.set_temperature_oversampling(conf[CONF_OVERSAMPLING]))
|
||||
cg.add(var.set_temperature_oversampling(temperature_config[CONF_OVERSAMPLING]))
|
||||
|
||||
if CONF_PRESSURE in config:
|
||||
conf = config[CONF_PRESSURE]
|
||||
sens = await sensor.new_sensor(conf)
|
||||
if pressure_config := config.get(CONF_PRESSURE):
|
||||
sens = await sensor.new_sensor(pressure_config)
|
||||
cg.add(var.set_pressure_sensor(sens))
|
||||
cg.add(var.set_pressure_oversampling(conf[CONF_OVERSAMPLING]))
|
||||
cg.add(var.set_pressure_oversampling(pressure_config[CONF_OVERSAMPLING]))
|
||||
|
||||
cg.add(var.set_iir_filter(config[CONF_IIR_FILTER]))
|
||||
|
@ -87,14 +87,16 @@ async def to_code(config):
|
||||
await cg.register_component(var, config)
|
||||
await i2c.register_i2c_device(var, config)
|
||||
cg.add(var.set_iir_filter_config(config[CONF_IIR_FILTER]))
|
||||
if CONF_TEMPERATURE in config:
|
||||
conf = config[CONF_TEMPERATURE]
|
||||
sens = await sensor.new_sensor(conf)
|
||||
if temperature_config := config.get(CONF_TEMPERATURE):
|
||||
sens = await sensor.new_sensor(temperature_config)
|
||||
cg.add(var.set_temperature_sensor(sens))
|
||||
cg.add(var.set_temperature_oversampling_config(conf[CONF_OVERSAMPLING]))
|
||||
cg.add(
|
||||
var.set_temperature_oversampling_config(
|
||||
temperature_config[CONF_OVERSAMPLING]
|
||||
)
|
||||
)
|
||||
|
||||
if CONF_PRESSURE in config:
|
||||
conf = config[CONF_PRESSURE]
|
||||
sens = await sensor.new_sensor(conf)
|
||||
if pressure_config := config.get(CONF_PRESSURE):
|
||||
sens = await sensor.new_sensor(pressure_config)
|
||||
cg.add(var.set_pressure_sensor(sens))
|
||||
cg.add(var.set_pressure_oversampling_config(conf[CONF_OVERSAMPLING]))
|
||||
cg.add(var.set_pressure_oversampling_config(pressure_config[CONF_OVERSAMPLING]))
|
||||
|
@ -85,11 +85,11 @@ async def setup_button_core_(var, config):
|
||||
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
|
||||
await automation.build_automation(trigger, [], conf)
|
||||
|
||||
if CONF_DEVICE_CLASS in config:
|
||||
cg.add(var.set_device_class(config[CONF_DEVICE_CLASS]))
|
||||
if device_class := config.get(CONF_DEVICE_CLASS):
|
||||
cg.add(var.set_device_class(device_class))
|
||||
|
||||
if CONF_MQTT_ID in config:
|
||||
mqtt_ = cg.new_Pvariable(config[CONF_MQTT_ID], var)
|
||||
if mqtt_id := config.get(CONF_MQTT_ID):
|
||||
mqtt_ = cg.new_Pvariable(mqtt_id, var)
|
||||
await mqtt.register_mqtt_component(mqtt_, config)
|
||||
|
||||
|
||||
|
@ -17,11 +17,10 @@ CONF_ON_FRAME = "on_frame"
|
||||
|
||||
|
||||
def validate_id(config):
|
||||
if CONF_CAN_ID in config:
|
||||
id_value = config[CONF_CAN_ID]
|
||||
if can_id := config.get(CONF_CAN_ID):
|
||||
id_ext = config[CONF_USE_EXTENDED_ID]
|
||||
if not id_ext:
|
||||
if id_value > 0x7FF:
|
||||
if can_id > 0x7FF:
|
||||
raise cv.Invalid("Standard IDs must be 11 Bit (0x000-0x7ff / 0-2047)")
|
||||
return config
|
||||
|
||||
@ -145,8 +144,8 @@ async def canbus_action_to_code(config, action_id, template_arg, args):
|
||||
var = cg.new_Pvariable(action_id, template_arg)
|
||||
await cg.register_parented(var, config[CONF_CANBUS_ID])
|
||||
|
||||
if CONF_CAN_ID in config:
|
||||
can_id = await cg.templatable(config[CONF_CAN_ID], args, cg.uint32)
|
||||
if can_id := config.get(CONF_CAN_ID):
|
||||
can_id = await cg.templatable(can_id, args, cg.uint32)
|
||||
cg.add(var.set_can_id(can_id))
|
||||
use_extended_id = await cg.templatable(
|
||||
config[CONF_USE_EXTENDED_ID], args, cg.uint32
|
||||
|
@ -37,8 +37,8 @@ async def to_code(config):
|
||||
cg.add(var.set_touch_threshold(config[CONF_TOUCH_THRESHOLD]))
|
||||
cg.add(var.set_allow_multiple_touches(config[CONF_ALLOW_MULTIPLE_TOUCHES]))
|
||||
|
||||
if CONF_RESET_PIN in config:
|
||||
pin = await cg.gpio_pin_expression(config[CONF_RESET_PIN])
|
||||
if reset_pin_config := config.get(CONF_RESET_PIN):
|
||||
pin = await cg.gpio_pin_expression(reset_pin_config)
|
||||
cg.add(var.set_reset_pin(pin))
|
||||
|
||||
await cg.register_component(var, config)
|
||||
|
@ -69,16 +69,16 @@ async def to_code(config):
|
||||
sens = await sensor.new_sensor(config[CONF_TVOC])
|
||||
cg.add(var.set_tvoc(sens))
|
||||
|
||||
if CONF_VERSION in config:
|
||||
sens = await text_sensor.new_text_sensor(config[CONF_VERSION])
|
||||
if version_config := config.get(CONF_VERSION):
|
||||
sens = await text_sensor.new_text_sensor(version_config)
|
||||
cg.add(var.set_version(sens))
|
||||
|
||||
if CONF_BASELINE in config:
|
||||
cg.add(var.set_baseline(config[CONF_BASELINE]))
|
||||
if baseline := config.get(CONF_BASELINE):
|
||||
cg.add(var.set_baseline(baseline))
|
||||
|
||||
if CONF_TEMPERATURE in config:
|
||||
sens = await cg.get_variable(config[CONF_TEMPERATURE])
|
||||
if temperature_id := config.get(CONF_TEMPERATURE):
|
||||
sens = await cg.get_variable(temperature_id)
|
||||
cg.add(var.set_temperature(sens))
|
||||
if CONF_HUMIDITY in config:
|
||||
sens = await cg.get_variable(config[CONF_HUMIDITY])
|
||||
if humidity_id := config.get(CONF_HUMIDITY):
|
||||
sens = await cg.get_variable(humidity_id)
|
||||
cg.add(var.set_humidity(sens))
|
||||
|
@ -44,11 +44,11 @@ async def register_climate_ir(var, config):
|
||||
|
||||
cg.add(var.set_supports_cool(config[CONF_SUPPORTS_COOL]))
|
||||
cg.add(var.set_supports_heat(config[CONF_SUPPORTS_HEAT]))
|
||||
if CONF_SENSOR in config:
|
||||
sens = await cg.get_variable(config[CONF_SENSOR])
|
||||
if sensor_id := config.get(CONF_SENSOR):
|
||||
sens = await cg.get_variable(sensor_id)
|
||||
cg.add(var.set_sensor(sens))
|
||||
if CONF_RECEIVER_ID in config:
|
||||
receiver = await cg.get_variable(config[CONF_RECEIVER_ID])
|
||||
if receiver_id := config.get(CONF_RECEIVER_ID):
|
||||
receiver = await cg.get_variable(receiver_id)
|
||||
cg.add(receiver.register_listener(var))
|
||||
|
||||
transmitter = await cg.get_variable(config[CONF_TRANSMITTER_ID])
|
||||
|
@ -113,17 +113,14 @@ async def to_code(config):
|
||||
cg.add(var.set_hpf_enable(config[CONF_CURRENT_HPF], config[CONF_VOLTAGE_HPF]))
|
||||
cg.add(var.set_pulse_energy_wh(config[CONF_PULSE_ENERGY]))
|
||||
|
||||
if CONF_VOLTAGE in config:
|
||||
conf = config[CONF_VOLTAGE]
|
||||
sens = await sensor.new_sensor(conf)
|
||||
if voltage_config := config.get(CONF_VOLTAGE):
|
||||
sens = await sensor.new_sensor(voltage_config)
|
||||
cg.add(var.set_voltage_sensor(sens))
|
||||
if CONF_CURRENT in config:
|
||||
conf = config[CONF_CURRENT]
|
||||
sens = await sensor.new_sensor(conf)
|
||||
if current_config := config.get(CONF_CURRENT):
|
||||
sens = await sensor.new_sensor(current_config)
|
||||
cg.add(var.set_current_sensor(sens))
|
||||
if CONF_POWER in config:
|
||||
conf = config[CONF_POWER]
|
||||
sens = await sensor.new_sensor(conf)
|
||||
if power_config := config.get(CONF_POWER):
|
||||
sens = await sensor.new_sensor(power_config)
|
||||
cg.add(var.set_power_sensor(sens))
|
||||
|
||||
|
||||
|
@ -69,19 +69,15 @@ async def to_code(config):
|
||||
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)
|
||||
if voltage_config := config.get(CONF_VOLTAGE):
|
||||
sens = await sensor.new_sensor(voltage_config)
|
||||
cg.add(var.set_voltage_sensor(sens))
|
||||
if CONF_CURRENT in config:
|
||||
conf = config[CONF_CURRENT]
|
||||
sens = await sensor.new_sensor(conf)
|
||||
if current_config := config.get(CONF_CURRENT):
|
||||
sens = await sensor.new_sensor(current_config)
|
||||
cg.add(var.set_current_sensor(sens))
|
||||
if CONF_POWER in config:
|
||||
conf = config[CONF_POWER]
|
||||
sens = await sensor.new_sensor(conf)
|
||||
if power_config := config.get(CONF_POWER):
|
||||
sens = await sensor.new_sensor(power_config)
|
||||
cg.add(var.set_power_sensor(sens))
|
||||
if CONF_ENERGY in config:
|
||||
conf = config[CONF_ENERGY]
|
||||
sens = await sensor.new_sensor(conf)
|
||||
if energy_config := config.get(CONF_ENERGY):
|
||||
sens = await sensor.new_sensor(energy_config)
|
||||
cg.add(var.set_energy_sensor(sens))
|
||||
|
@ -66,59 +66,57 @@ CONFIG_SCHEMA = cover.COVER_SCHEMA.extend(
|
||||
).extend(cv.COMPONENT_SCHEMA)
|
||||
|
||||
|
||||
def to_code(config):
|
||||
async def to_code(config):
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
yield cg.register_component(var, config)
|
||||
yield cover.register_cover(var, config)
|
||||
await cg.register_component(var, config)
|
||||
await cover.register_cover(var, config)
|
||||
|
||||
yield automation.build_automation(
|
||||
await automation.build_automation(
|
||||
var.get_stop_trigger(), [], config[CONF_STOP_ACTION]
|
||||
)
|
||||
|
||||
# OPEN
|
||||
bin = yield cg.get_variable(config[CONF_OPEN_SENSOR])
|
||||
bin = await cg.get_variable(config[CONF_OPEN_SENSOR])
|
||||
cg.add(var.set_open_sensor(bin))
|
||||
cg.add(
|
||||
var.set_open_moving_current_threshold(
|
||||
config[CONF_OPEN_MOVING_CURRENT_THRESHOLD]
|
||||
)
|
||||
)
|
||||
if CONF_OPEN_OBSTACLE_CURRENT_THRESHOLD in config:
|
||||
cg.add(
|
||||
var.set_open_obstacle_current_threshold(
|
||||
config[CONF_OPEN_OBSTACLE_CURRENT_THRESHOLD]
|
||||
)
|
||||
)
|
||||
if open_obsticle_current_threshold := config.get(
|
||||
CONF_OPEN_OBSTACLE_CURRENT_THRESHOLD
|
||||
):
|
||||
cg.add(var.set_open_obstacle_current_threshold(open_obsticle_current_threshold))
|
||||
cg.add(var.set_open_duration(config[CONF_OPEN_DURATION]))
|
||||
yield automation.build_automation(
|
||||
await automation.build_automation(
|
||||
var.get_open_trigger(), [], config[CONF_OPEN_ACTION]
|
||||
)
|
||||
|
||||
# CLOSE
|
||||
bin = yield cg.get_variable(config[CONF_CLOSE_SENSOR])
|
||||
bin = await cg.get_variable(config[CONF_CLOSE_SENSOR])
|
||||
cg.add(var.set_close_sensor(bin))
|
||||
cg.add(
|
||||
var.set_close_moving_current_threshold(
|
||||
config[CONF_CLOSE_MOVING_CURRENT_THRESHOLD]
|
||||
)
|
||||
)
|
||||
if CONF_CLOSE_OBSTACLE_CURRENT_THRESHOLD in config:
|
||||
if close_obsticle_current_threshold := config.get(
|
||||
CONF_CLOSE_OBSTACLE_CURRENT_THRESHOLD
|
||||
):
|
||||
cg.add(
|
||||
var.set_close_obstacle_current_threshold(
|
||||
config[CONF_CLOSE_OBSTACLE_CURRENT_THRESHOLD]
|
||||
)
|
||||
var.set_close_obstacle_current_threshold(close_obsticle_current_threshold)
|
||||
)
|
||||
cg.add(var.set_close_duration(config[CONF_CLOSE_DURATION]))
|
||||
yield automation.build_automation(
|
||||
await automation.build_automation(
|
||||
var.get_close_trigger(), [], config[CONF_CLOSE_ACTION]
|
||||
)
|
||||
|
||||
cg.add(var.set_obstacle_rollback(config[CONF_OBSTACLE_ROLLBACK]))
|
||||
if CONF_MAX_DURATION in config:
|
||||
cg.add(var.set_max_duration(config[CONF_MAX_DURATION]))
|
||||
if max_duration := config.get(CONF_MAX_DURATION):
|
||||
cg.add(var.set_max_duration(max_duration))
|
||||
cg.add(var.set_malfunction_detection(config[CONF_MALFUNCTION_DETECTION]))
|
||||
if CONF_MALFUNCTION_ACTION in config:
|
||||
yield automation.build_automation(
|
||||
var.get_malfunction_trigger(), [], config[CONF_MALFUNCTION_ACTION]
|
||||
if malfunction_action := config.get(CONF_MALFUNCTION_ACTION):
|
||||
await automation.build_automation(
|
||||
var.get_malfunction_trigger(), [], malfunction_action
|
||||
)
|
||||
cg.add(var.set_start_sensing_delay(config[CONF_START_SENSING_DELAY]))
|
||||
|
@ -37,16 +37,12 @@ async def to_code(config):
|
||||
|
||||
cwhite = await cg.get_variable(config[CONF_COLD_WHITE])
|
||||
cg.add(var.set_cold_white(cwhite))
|
||||
if CONF_COLD_WHITE_COLOR_TEMPERATURE in config:
|
||||
cg.add(
|
||||
var.set_cold_white_temperature(config[CONF_COLD_WHITE_COLOR_TEMPERATURE])
|
||||
)
|
||||
if cold_white_color_temperature := config.get(CONF_COLD_WHITE_COLOR_TEMPERATURE):
|
||||
cg.add(var.set_cold_white_temperature(cold_white_color_temperature))
|
||||
|
||||
wwhite = await cg.get_variable(config[CONF_WARM_WHITE])
|
||||
cg.add(var.set_warm_white(wwhite))
|
||||
if CONF_WARM_WHITE_COLOR_TEMPERATURE in config:
|
||||
cg.add(
|
||||
var.set_warm_white_temperature(config[CONF_WARM_WHITE_COLOR_TEMPERATURE])
|
||||
)
|
||||
if warm_white_color_temperature := config.get(CONF_WARM_WHITE_COLOR_TEMPERATURE):
|
||||
cg.add(var.set_warm_white_temperature(warm_white_color_temperature))
|
||||
|
||||
cg.add(var.set_constant_brightness(config[CONF_CONSTANT_BRIGHTNESS]))
|
||||
|
Loading…
Reference in New Issue
Block a user