mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 07:03:55 +00:00 
			
		
		
		
	[ruff] Enable RET and fix all violations
This commit is contained in:
		| @@ -391,8 +391,7 @@ async def build_action(full_config, template_arg, args): | ||||
|     ) | ||||
|     action_id = full_config[CONF_TYPE_ID] | ||||
|     builder = registry_entry.coroutine_fun | ||||
|     ret = await builder(config, action_id, template_arg, args) | ||||
|     return ret | ||||
|     return await builder(config, action_id, template_arg, args) | ||||
|  | ||||
|  | ||||
| async def build_action_list(config, templ, arg_type): | ||||
| @@ -409,8 +408,7 @@ async def build_condition(full_config, template_arg, args): | ||||
|     ) | ||||
|     action_id = full_config[CONF_TYPE_ID] | ||||
|     builder = registry_entry.coroutine_fun | ||||
|     ret = await builder(config, action_id, template_arg, args) | ||||
|     return ret | ||||
|     return await builder(config, action_id, template_arg, args) | ||||
|  | ||||
|  | ||||
| async def build_condition_list(config, templ, args): | ||||
|   | ||||
| @@ -301,8 +301,7 @@ async def alarm_action_disarm_to_code(config, action_id, template_arg, args): | ||||
| ) | ||||
| async def alarm_action_pending_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) | ||||
|     return var | ||||
|     return cg.new_Pvariable(action_id, template_arg, paren) | ||||
|  | ||||
|  | ||||
| @automation.register_action( | ||||
| @@ -310,8 +309,7 @@ async def alarm_action_pending_to_code(config, action_id, template_arg, args): | ||||
| ) | ||||
| async def alarm_action_trigger_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) | ||||
|     return var | ||||
|     return cg.new_Pvariable(action_id, template_arg, paren) | ||||
|  | ||||
|  | ||||
| @automation.register_action( | ||||
| @@ -319,8 +317,7 @@ async def alarm_action_trigger_to_code(config, action_id, template_arg, args): | ||||
| ) | ||||
| async def alarm_action_chime_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) | ||||
|     return var | ||||
|     return cg.new_Pvariable(action_id, template_arg, paren) | ||||
|  | ||||
|  | ||||
| @automation.register_action( | ||||
| @@ -333,8 +330,7 @@ async def alarm_action_chime_to_code(config, action_id, template_arg, args): | ||||
| ) | ||||
| async def alarm_action_ready_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) | ||||
|     return var | ||||
|     return cg.new_Pvariable(action_id, template_arg, paren) | ||||
|  | ||||
|  | ||||
| @automation.register_condition( | ||||
|   | ||||
| @@ -175,8 +175,7 @@ BLE_REMOVE_BOND_ACTION_SCHEMA = cv.Schema( | ||||
| ) | ||||
| async def ble_disconnect_to_code(config, action_id, template_arg, args): | ||||
|     parent = await cg.get_variable(config[CONF_ID]) | ||||
|     var = cg.new_Pvariable(action_id, template_arg, parent) | ||||
|     return var | ||||
|     return cg.new_Pvariable(action_id, template_arg, parent) | ||||
|  | ||||
|  | ||||
| @automation.register_action( | ||||
| @@ -184,8 +183,7 @@ async def ble_disconnect_to_code(config, action_id, template_arg, args): | ||||
| ) | ||||
| async def ble_connect_to_code(config, action_id, template_arg, args): | ||||
|     parent = await cg.get_variable(config[CONF_ID]) | ||||
|     var = cg.new_Pvariable(action_id, template_arg, parent) | ||||
|     return var | ||||
|     return cg.new_Pvariable(action_id, template_arg, parent) | ||||
|  | ||||
|  | ||||
| @automation.register_action( | ||||
| @@ -282,9 +280,7 @@ async def passkey_reply_to_code(config, action_id, template_arg, args): | ||||
| ) | ||||
| async def remove_bond_to_code(config, action_id, template_arg, args): | ||||
|     parent = await cg.get_variable(config[CONF_ID]) | ||||
|     var = cg.new_Pvariable(action_id, template_arg, parent) | ||||
|  | ||||
|     return var | ||||
|     return cg.new_Pvariable(action_id, template_arg, parent) | ||||
|  | ||||
|  | ||||
| async def to_code(config): | ||||
|   | ||||
| @@ -872,7 +872,7 @@ def get_arduino_partition_csv(flash_size): | ||||
|     eeprom_partition_start = app1_partition_start + app_partition_size | ||||
|     spiffs_partition_start = eeprom_partition_start + eeprom_partition_size | ||||
|  | ||||
|     partition_csv = f"""\ | ||||
|     return f"""\ | ||||
| nvs,      data, nvs,     0x9000, 0x5000, | ||||
| otadata,  data, ota,     0xE000, 0x2000, | ||||
| app0,     app,  ota_0,   0x{app0_partition_start:X}, 0x{app_partition_size:X}, | ||||
| @@ -880,20 +880,18 @@ app1,     app,  ota_1,   0x{app1_partition_start:X}, 0x{app_partition_size:X}, | ||||
| eeprom,   data, 0x99,    0x{eeprom_partition_start:X}, 0x{eeprom_partition_size:X}, | ||||
| spiffs,   data, spiffs,  0x{spiffs_partition_start:X}, 0x{spiffs_partition_size:X} | ||||
| """ | ||||
|     return partition_csv | ||||
|  | ||||
|  | ||||
| def get_idf_partition_csv(flash_size): | ||||
|     app_partition_size = APP_PARTITION_SIZES[flash_size] | ||||
|  | ||||
|     partition_csv = f"""\ | ||||
|     return f"""\ | ||||
| otadata,  data, ota,     ,        0x2000, | ||||
| phy_init, data, phy,     ,        0x1000, | ||||
| app0,     app,  ota_0,   ,        0x{app_partition_size:X}, | ||||
| app1,     app,  ota_1,   ,        0x{app_partition_size:X}, | ||||
| nvs,      data, nvs,     ,        0x6D000, | ||||
| """ | ||||
|     return partition_csv | ||||
|  | ||||
|  | ||||
| def _format_sdkconfig_val(value: SdkconfigValueType) -> str: | ||||
|   | ||||
| @@ -187,8 +187,7 @@ def validate_supports(value): | ||||
|             "Open-drain only works with output mode", [CONF_MODE, CONF_OPEN_DRAIN] | ||||
|         ) | ||||
|  | ||||
|     value = _esp32_validations[variant].usage_validation(value) | ||||
|     return value | ||||
|     return _esp32_validations[variant].usage_validation(value) | ||||
|  | ||||
|  | ||||
| # https://docs.espressif.com/projects/esp-idf/en/v3.3.5/api-reference/peripherals/gpio.html#_CPPv416gpio_drive_cap_t | ||||
|   | ||||
| @@ -628,5 +628,4 @@ async def ble_server_descriptor_set_value(config, action_id, template_arg, args) | ||||
| ) | ||||
| async def ble_server_characteristic_notify(config, action_id, template_arg, args): | ||||
|     paren = await cg.get_variable(config[CONF_ID]) | ||||
|     var = cg.new_Pvariable(action_id, template_arg, paren) | ||||
|     return var | ||||
|     return cg.new_Pvariable(action_id, template_arg, paren) | ||||
|   | ||||
| @@ -330,8 +330,7 @@ HAIER_HON_BASE_ACTION_SCHEMA = automation.maybe_simple_id( | ||||
| ) | ||||
| async def display_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) | ||||
|     return var | ||||
|     return cg.new_Pvariable(action_id, template_arg, paren) | ||||
|  | ||||
|  | ||||
| @automation.register_action( | ||||
| @@ -342,8 +341,7 @@ async def display_action_to_code(config, action_id, template_arg, args): | ||||
| ) | ||||
| async def beeper_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) | ||||
|     return var | ||||
|     return cg.new_Pvariable(action_id, template_arg, paren) | ||||
|  | ||||
|  | ||||
| # Start self cleaning or steri-cleaning action action | ||||
| @@ -359,8 +357,7 @@ async def beeper_action_to_code(config, action_id, template_arg, args): | ||||
| ) | ||||
| async def start_cleaning_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) | ||||
|     return var | ||||
|     return cg.new_Pvariable(action_id, template_arg, paren) | ||||
|  | ||||
|  | ||||
| # Set vertical airflow direction action | ||||
| @@ -417,8 +414,7 @@ async def haier_set_horizontal_airflow_to_code(config, action_id, template_arg, | ||||
| ) | ||||
| async def health_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) | ||||
|     return var | ||||
|     return cg.new_Pvariable(action_id, template_arg, paren) | ||||
|  | ||||
|  | ||||
| @automation.register_action( | ||||
| @@ -432,8 +428,7 @@ async def health_action_to_code(config, action_id, template_arg, args): | ||||
| ) | ||||
| async def power_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) | ||||
|     return var | ||||
|     return cg.new_Pvariable(action_id, template_arg, paren) | ||||
|  | ||||
|  | ||||
| def _final_validate(config): | ||||
|   | ||||
| @@ -353,10 +353,9 @@ async def addressable_lambda_effect_to_code(config, effect_id): | ||||
|         (bool, "initial_run"), | ||||
|     ] | ||||
|     lambda_ = await cg.process_lambda(config[CONF_LAMBDA], args, return_type=cg.void) | ||||
|     var = cg.new_Pvariable( | ||||
|     return cg.new_Pvariable( | ||||
|         effect_id, config[CONF_NAME], lambda_, config[CONF_UPDATE_INTERVAL] | ||||
|     ) | ||||
|     return var | ||||
|  | ||||
|  | ||||
| @register_addressable_effect( | ||||
|   | ||||
| @@ -85,8 +85,7 @@ async def action_to_code( | ||||
|     async with LambdaContext(parameters=args, where=action_id) as context: | ||||
|         for widget in widgets: | ||||
|             await action(widget) | ||||
|     var = cg.new_Pvariable(action_id, template_arg, await context.get_lambda()) | ||||
|     return var | ||||
|     return cg.new_Pvariable(action_id, template_arg, await context.get_lambda()) | ||||
|  | ||||
|  | ||||
| async def update_to_code(config, action_id, template_arg, args): | ||||
| @@ -354,8 +353,7 @@ async def widget_focus(config, action_id, template_arg, args): | ||||
|  | ||||
|         if config[CONF_FREEZE]: | ||||
|             lv.group_focus_freeze(group, True) | ||||
|         var = cg.new_Pvariable(action_id, template_arg, await context.get_lambda()) | ||||
|         return var | ||||
|         return cg.new_Pvariable(action_id, template_arg, await context.get_lambda()) | ||||
|  | ||||
|  | ||||
| @automation.register_action( | ||||
|   | ||||
| @@ -271,8 +271,7 @@ padding = LValidator(padding_validator, int32, retmapper=literal) | ||||
|  | ||||
|  | ||||
| def zoom_validator(value): | ||||
|     value = cv.float_range(0.1, 10.0)(value) | ||||
|     return value | ||||
|     return cv.float_range(0.1, 10.0)(value) | ||||
|  | ||||
|  | ||||
| def zoom_retmapper(value): | ||||
|   | ||||
| @@ -66,8 +66,7 @@ async def style_update_to_code(config, action_id, template_arg, args): | ||||
|     async with LambdaContext(parameters=args, where=action_id) as context: | ||||
|         await style_set(style, config) | ||||
|  | ||||
|     var = cg.new_Pvariable(action_id, template_arg, await context.get_lambda()) | ||||
|     return var | ||||
|     return cg.new_Pvariable(action_id, template_arg, await context.get_lambda()) | ||||
|  | ||||
|  | ||||
| async def theme_to_code(config): | ||||
|   | ||||
| @@ -189,7 +189,7 @@ class Widget: | ||||
|         for matrix buttons | ||||
|         :return: | ||||
|         """ | ||||
|         return None | ||||
|         return | ||||
|  | ||||
|     def get_max(self): | ||||
|         return self.type.get_max(self.config) | ||||
|   | ||||
| @@ -193,7 +193,7 @@ class ButtonMatrixType(WidgetType): | ||||
|     async def to_code(self, w: Widget, config): | ||||
|         lvgl_components_required.add("BUTTONMATRIX") | ||||
|         if CONF_ROWS not in config: | ||||
|             return [] | ||||
|             return | ||||
|         text_list, ctrl_list, width_list, key_list = await get_button_data( | ||||
|             config[CONF_ROWS], w | ||||
|         ) | ||||
|   | ||||
| @@ -312,14 +312,13 @@ CONFIG_SCHEMA = cv.All( | ||||
| def exp_mqtt_message(config): | ||||
|     if config is None: | ||||
|         return cg.optional(cg.TemplateArguments(MQTTMessage)) | ||||
|     exp = cg.StructInitializer( | ||||
|     return cg.StructInitializer( | ||||
|         MQTTMessage, | ||||
|         ("topic", config[CONF_TOPIC]), | ||||
|         ("payload", config.get(CONF_PAYLOAD, "")), | ||||
|         ("qos", config[CONF_QOS]), | ||||
|         ("retain", config[CONF_RETAIN]), | ||||
|     ) | ||||
|     return exp | ||||
|  | ||||
|  | ||||
| @coroutine_with_priority(40.0) | ||||
|   | ||||
| @@ -18,13 +18,12 @@ def one_wire_device_schema(): | ||||
|  | ||||
|     :return: The 1-wire device schema, `extend` this in your config schema. | ||||
|     """ | ||||
|     schema = cv.Schema( | ||||
|     return cv.Schema( | ||||
|         { | ||||
|             cv.GenerateID(CONF_ONE_WIRE_ID): cv.use_id(OneWireBus), | ||||
|             cv.Optional(CONF_ADDRESS): cv.hex_uint64_t, | ||||
|         } | ||||
|     ) | ||||
|     return schema | ||||
|  | ||||
|  | ||||
| async def register_one_wire_device(var, config): | ||||
|   | ||||
| @@ -186,8 +186,7 @@ def _process_package(package_config, config): | ||||
|         package_config = _process_base_package(package_config) | ||||
|     if isinstance(package_config, dict): | ||||
|         recursive_package = do_packages_pass(package_config) | ||||
|     config = merge_config(recursive_package, config) | ||||
|     return config | ||||
|     return merge_config(recursive_package, config) | ||||
|  | ||||
|  | ||||
| def do_packages_pass(config: dict): | ||||
|   | ||||
| @@ -114,8 +114,7 @@ PMWCS3_CALIBRATION_SCHEMA = cv.Schema( | ||||
| ) | ||||
| async def pmwcs3_calibration_to_code(config, action_id, template_arg, args): | ||||
|     parent = await cg.get_variable(config[CONF_ID]) | ||||
|     var = cg.new_Pvariable(action_id, template_arg, parent) | ||||
|     return var | ||||
|     return cg.new_Pvariable(action_id, template_arg, parent) | ||||
|  | ||||
|  | ||||
| PMWCS3_NEW_I2C_ADDRESS_SCHEMA = cv.maybe_simple_value( | ||||
|   | ||||
| @@ -136,8 +136,7 @@ RFBRIDGE_ID_SCHEMA = cv.Schema({cv.GenerateID(): cv.use_id(RFBridgeComponent)}) | ||||
| @automation.register_action("rf_bridge.learn", RFBridgeLearnAction, RFBRIDGE_ID_SCHEMA) | ||||
| async def rf_bridge_learnx_to_code(config, action_id, template_args, args): | ||||
|     paren = await cg.get_variable(config[CONF_ID]) | ||||
|     var = cg.new_Pvariable(action_id, template_args, paren) | ||||
|     return var | ||||
|     return cg.new_Pvariable(action_id, template_args, paren) | ||||
|  | ||||
|  | ||||
| @automation.register_action( | ||||
| @@ -149,8 +148,7 @@ async def rf_bridge_start_advanced_sniffing_to_code( | ||||
|     config, action_id, template_args, args | ||||
| ): | ||||
|     paren = await cg.get_variable(config[CONF_ID]) | ||||
|     var = cg.new_Pvariable(action_id, template_args, paren) | ||||
|     return var | ||||
|     return cg.new_Pvariable(action_id, template_args, paren) | ||||
|  | ||||
|  | ||||
| @automation.register_action( | ||||
| @@ -162,8 +160,7 @@ async def rf_bridge_stop_advanced_sniffing_to_code( | ||||
|     config, action_id, template_args, args | ||||
| ): | ||||
|     paren = await cg.get_variable(config[CONF_ID]) | ||||
|     var = cg.new_Pvariable(action_id, template_args, paren) | ||||
|     return var | ||||
|     return cg.new_Pvariable(action_id, template_args, paren) | ||||
|  | ||||
|  | ||||
| @automation.register_action( | ||||
| @@ -175,8 +172,7 @@ async def rf_bridge_start_bucket_sniffing_to_code( | ||||
|     config, action_id, template_args, args | ||||
| ): | ||||
|     paren = await cg.get_variable(config[CONF_ID]) | ||||
|     var = cg.new_Pvariable(action_id, template_args, paren) | ||||
|     return var | ||||
|     return cg.new_Pvariable(action_id, template_args, paren) | ||||
|  | ||||
|  | ||||
| RFBRIDGE_SEND_ADVANCED_CODE_SCHEMA = cv.Schema( | ||||
|   | ||||
| @@ -125,8 +125,7 @@ writezero: | ||||
|  | ||||
| def time_to_cycles(time_us): | ||||
|     cycles_per_us = 57.5 | ||||
|     cycles = round(float(time_us) * cycles_per_us) | ||||
|     return cycles | ||||
|     return round(float(time_us) * cycles_per_us) | ||||
|  | ||||
|  | ||||
| CONF_PIO = "pio" | ||||
|   | ||||
| @@ -171,8 +171,7 @@ async def sim800l_dial_to_code(config, action_id, template_arg, args): | ||||
| ) | ||||
| async def sim800l_connect_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) | ||||
|     return var | ||||
|     return cg.new_Pvariable(action_id, template_arg, paren) | ||||
|  | ||||
|  | ||||
| SIM800L_SEND_USSD_SCHEMA = cv.Schema( | ||||
| @@ -201,5 +200,4 @@ async def sim800l_send_ussd_to_code(config, action_id, template_arg, args): | ||||
| ) | ||||
| async def sim800l_disconnect_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) | ||||
|     return var | ||||
|     return cg.new_Pvariable(action_id, template_arg, paren) | ||||
|   | ||||
| @@ -122,5 +122,4 @@ UFIRE_EC_RESET_SCHEMA = cv.Schema( | ||||
| ) | ||||
| async def ufire_ec_reset_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) | ||||
|     return var | ||||
|     return cg.new_Pvariable(action_id, template_arg, paren) | ||||
|   | ||||
| @@ -123,5 +123,4 @@ UFIRE_ISE_RESET_SCHEMA = cv.Schema({cv.GenerateID(): cv.use_id(UFireISEComponent | ||||
| ) | ||||
| async def ufire_ise_reset_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) | ||||
|     return var | ||||
|     return cg.new_Pvariable(action_id, template_arg, paren) | ||||
|   | ||||
| @@ -111,8 +111,7 @@ def merge_config(full_old, full_new): | ||||
|                     else: | ||||
|                         ids[new_id] = len(res) | ||||
|                 res.append(v) | ||||
|             res = [v for i, v in enumerate(res) if i not in ids_to_delete] | ||||
|             return res | ||||
|             return [v for i, v in enumerate(res) if i not in ids_to_delete] | ||||
|         if new is None: | ||||
|             return old | ||||
|  | ||||
|   | ||||
| @@ -1866,7 +1866,7 @@ def validate_registry_entry(name, registry): | ||||
|  | ||||
| def none(value): | ||||
|     if value in ("none", "None"): | ||||
|         return None | ||||
|         return | ||||
|     raise Invalid("Must be none") | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -115,7 +115,7 @@ async def build_registry_list(registry, config): | ||||
|  | ||||
| async def past_safe_mode(): | ||||
|     if CONF_SAFE_MODE not in CORE.config: | ||||
|         return | ||||
|         return None | ||||
|  | ||||
|     def _safe_mode_generator(): | ||||
|         while True: | ||||
|   | ||||
| @@ -36,7 +36,7 @@ _LOGGER = logging.getLogger(__name__) | ||||
|  | ||||
|  | ||||
| def config_from_env(): | ||||
|     config = { | ||||
|     return { | ||||
|         CONF_MQTT: { | ||||
|             CONF_USERNAME: get_str_env("ESPHOME_DASHBOARD_MQTT_USERNAME"), | ||||
|             CONF_PASSWORD: get_str_env("ESPHOME_DASHBOARD_MQTT_PASSWORD"), | ||||
| @@ -44,7 +44,6 @@ def config_from_env(): | ||||
|             CONF_PORT: get_int_env("ESPHOME_DASHBOARD_MQTT_PORT", 1883), | ||||
|         }, | ||||
|     } | ||||
|     return config | ||||
|  | ||||
|  | ||||
| def initialize( | ||||
|   | ||||
| @@ -81,8 +81,7 @@ def _print_file_read_event(path: str) -> None: | ||||
|  | ||||
| def _request_and_get_stream_on_stdin(fname: str) -> StringIO: | ||||
|     _print_file_read_event(fname) | ||||
|     raw_yaml_stream = StringIO(_read_file_content_from_json_on_stdin()) | ||||
|     return raw_yaml_stream | ||||
|     return StringIO(_read_file_content_from_json_on_stdin()) | ||||
|  | ||||
|  | ||||
| def _vscode_loader(fname: str) -> dict[str, Any]: | ||||
|   | ||||
| @@ -305,8 +305,7 @@ class ESPHomeLoaderMixin: | ||||
|         result = self.yaml_loader(self._rel_path(file)) | ||||
|         if not vars: | ||||
|             vars = {} | ||||
|         result = substitute_vars(result, vars) | ||||
|         return result | ||||
|         return substitute_vars(result, vars) | ||||
|  | ||||
|     @_add_data_ref | ||||
|     def construct_include_dir_list(self, node: yaml.Node) -> list[dict[str, Any]]: | ||||
|   | ||||
		Reference in New Issue
	
	Block a user