From 00f9af70a92da04894e0d349a01d26dc9887c62c Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Mon, 7 Aug 2023 11:48:23 +1200 Subject: [PATCH] Fix some configs after #5181 (#5209) --- esphome/components/adc/sensor.py | 3 +-- esphome/components/animation/__init__.py | 2 +- esphome/components/bedjet/__init__.py | 2 +- esphome/components/binary_sensor/__init__.py | 2 +- .../components/ble_presence/binary_sensor.py | 4 ++-- esphome/components/ble_rssi/sensor.py | 4 ++-- esphome/components/canbus/__init__.py | 10 +++++----- esphome/components/ccs811/sensor.py | 2 +- esphome/components/current_based/cover.py | 20 ++++++++++++------- 9 files changed, 27 insertions(+), 22 deletions(-) diff --git a/esphome/components/adc/sensor.py b/esphome/components/adc/sensor.py index 99d3652698..c1ae22214d 100644 --- a/esphome/components/adc/sensor.py +++ b/esphome/components/adc/sensor.py @@ -89,8 +89,7 @@ async def to_code(config): pin = await cg.gpio_pin_expression(config[CONF_PIN]) cg.add(var.set_pin(pin)) - if raw := config.get(CONF_RAW): - cg.add(var.set_output_raw(raw)) + cg.add(var.set_output_raw(config[CONF_RAW])) if attenuation := config.get(CONF_ATTENUATION): if attenuation == "auto": diff --git a/esphome/components/animation/__init__.py b/esphome/components/animation/__init__.py index 7fc1e0dcd0..52e14f0a43 100644 --- a/esphome/components/animation/__init__.py +++ b/esphome/components/animation/__init__.py @@ -115,7 +115,7 @@ 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 frame := config.get(CONF_FRAME): + if (frame := config.get(CONF_FRAME)) is not None: template_ = await cg.templatable(frame, args, cg.uint16) cg.add(var.set_frame(template_)) return var diff --git a/esphome/components/bedjet/__init__.py b/esphome/components/bedjet/__init__.py index 4ff3c34075..395a5f25e4 100644 --- a/esphome/components/bedjet/__init__.py +++ b/esphome/components/bedjet/__init__.py @@ -48,5 +48,5 @@ async def to_code(config): if time_id := config.get(CONF_TIME_ID): time_ = await cg.get_variable(time_id) cg.add(var.set_time_id(time_)) - if receive_timeout := config.get(CONF_RECEIVE_TIMEOUT): + if (receive_timeout := config.get(CONF_RECEIVE_TIMEOUT)) is not None: cg.add(var.set_status_timeout(receive_timeout)) diff --git a/esphome/components/binary_sensor/__init__.py b/esphome/components/binary_sensor/__init__.py index fee6b6b434..babe46e082 100644 --- a/esphome/components/binary_sensor/__init__.py +++ b/esphome/components/binary_sensor/__init__.py @@ -467,7 +467,7 @@ def binary_sensor_schema( async def setup_binary_sensor_core_(var, config): await setup_entity(var, config) - if device_class := config.get(CONF_DEVICE_CLASS): + if (device_class := config.get(CONF_DEVICE_CLASS)) is not None: 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)) diff --git a/esphome/components/ble_presence/binary_sensor.py b/esphome/components/ble_presence/binary_sensor.py index 2320d45287..81878391bb 100644 --- a/esphome/components/ble_presence/binary_sensor.py +++ b/esphome/components/ble_presence/binary_sensor.py @@ -74,8 +74,8 @@ async def to_code(config): ibeacon_uuid = esp32_ble_tracker.as_hex_array(str(ibeacon_uuid)) cg.add(var.set_ibeacon_uuid(ibeacon_uuid)) - if ibeacon_major := config.get(CONF_IBEACON_MAJOR): + if (ibeacon_major := config.get(CONF_IBEACON_MAJOR)) is not None: cg.add(var.set_ibeacon_major(ibeacon_major)) - if ibeacon_minor := config.get(CONF_IBEACON_MINOR): + if (ibeacon_minor := config.get(CONF_IBEACON_MINOR)) is not None: cg.add(var.set_ibeacon_minor(ibeacon_minor)) diff --git a/esphome/components/ble_rssi/sensor.py b/esphome/components/ble_rssi/sensor.py index 014843ab60..4246d311ab 100644 --- a/esphome/components/ble_rssi/sensor.py +++ b/esphome/components/ble_rssi/sensor.py @@ -73,8 +73,8 @@ async def to_code(config): ibeacon_uuid = esp32_ble_tracker.as_hex_array(str(ibeacon_uuid)) cg.add(var.set_ibeacon_uuid(ibeacon_uuid)) - if ibeacon_major := config.get(CONF_IBEACON_MAJOR): + if (ibeacon_major := config.get(CONF_IBEACON_MAJOR)) is not None: cg.add(var.set_ibeacon_major(ibeacon_major)) - if ibeacon_minor := config.get(CONF_IBEACON_MINOR): + if (ibeacon_minor := config.get(CONF_IBEACON_MINOR)) is not None: cg.add(var.set_ibeacon_minor(ibeacon_minor)) diff --git a/esphome/components/canbus/__init__.py b/esphome/components/canbus/__init__.py index efa55b220e..c5a9924644 100644 --- a/esphome/components/canbus/__init__.py +++ b/esphome/components/canbus/__init__.py @@ -17,11 +17,11 @@ CONF_ON_FRAME = "on_frame" def validate_id(config): - if can_id := config.get(CONF_CAN_ID): - id_ext = config[CONF_USE_EXTENDED_ID] - if not id_ext: - if can_id > 0x7FF: - raise cv.Invalid("Standard IDs must be 11 Bit (0x000-0x7ff / 0-2047)") + can_id = config[CONF_CAN_ID] + id_ext = config[CONF_USE_EXTENDED_ID] + if not id_ext: + if can_id > 0x7FF: + raise cv.Invalid("Standard IDs must be 11 Bit (0x000-0x7ff / 0-2047)") return config diff --git a/esphome/components/ccs811/sensor.py b/esphome/components/ccs811/sensor.py index 4133255b15..66d9274fe8 100644 --- a/esphome/components/ccs811/sensor.py +++ b/esphome/components/ccs811/sensor.py @@ -73,7 +73,7 @@ async def to_code(config): sens = await text_sensor.new_text_sensor(version_config) cg.add(var.set_version(sens)) - if baseline := config.get(CONF_BASELINE): + if (baseline := config.get(CONF_BASELINE)) is not None: cg.add(var.set_baseline(baseline)) if temperature_id := config.get(CONF_TEMPERATURE): diff --git a/esphome/components/current_based/cover.py b/esphome/components/current_based/cover.py index 41732305a1..1fa4eaa03f 100644 --- a/esphome/components/current_based/cover.py +++ b/esphome/components/current_based/cover.py @@ -83,10 +83,13 @@ async def to_code(config): config[CONF_OPEN_MOVING_CURRENT_THRESHOLD] ) ) - if open_obsticle_current_threshold := config.get( - CONF_OPEN_OBSTACLE_CURRENT_THRESHOLD - ): + if ( + open_obsticle_current_threshold := config.get( + CONF_OPEN_OBSTACLE_CURRENT_THRESHOLD + ) + ) is not None: cg.add(var.set_open_obstacle_current_threshold(open_obsticle_current_threshold)) + cg.add(var.set_open_duration(config[CONF_OPEN_DURATION])) await automation.build_automation( var.get_open_trigger(), [], config[CONF_OPEN_ACTION] @@ -100,19 +103,22 @@ async def to_code(config): config[CONF_CLOSE_MOVING_CURRENT_THRESHOLD] ) ) - if close_obsticle_current_threshold := config.get( - CONF_CLOSE_OBSTACLE_CURRENT_THRESHOLD - ): + if ( + close_obsticle_current_threshold := config.get( + CONF_CLOSE_OBSTACLE_CURRENT_THRESHOLD + ) + ) is not None: cg.add( var.set_close_obstacle_current_threshold(close_obsticle_current_threshold) ) + cg.add(var.set_close_duration(config[CONF_CLOSE_DURATION])) await automation.build_automation( var.get_close_trigger(), [], config[CONF_CLOSE_ACTION] ) cg.add(var.set_obstacle_rollback(config[CONF_OBSTACLE_ROLLBACK])) - if max_duration := config.get(CONF_MAX_DURATION): + if (max_duration := config.get(CONF_MAX_DURATION)) is not None: cg.add(var.set_max_duration(max_duration)) cg.add(var.set_malfunction_detection(config[CONF_MALFUNCTION_DETECTION])) if malfunction_action := config.get(CONF_MALFUNCTION_ACTION):