From 810a437540e7786cdfc5930430bad6ff13c3bfbb Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 18 Dec 2024 11:29:57 -1000 Subject: [PATCH] chore: add black and isort the pre-commit Its annoying to have to do this manually and we tend to forget --- .pre-commit-config.yaml | 8 +++ components/ratgdo/__init__.py | 95 ++++++++++++++++++----------- components/ratgdo/cover/__init__.py | 4 +- 3 files changed, 68 insertions(+), 39 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 53d48a3..084df77 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,3 +16,11 @@ repos: - "c" - "cuda" args: [-style=Webkit, -i] +- repo: https://github.com/PyCQA/isort + rev: 5.13.2 + hooks: + - id: isort +- repo: https://github.com/psf/black + rev: 24.10.0 + hooks: + - id: black diff --git a/components/ratgdo/__init__.py b/components/ratgdo/__init__.py index 5153cad..dc3da8c 100644 --- a/components/ratgdo/__init__.py +++ b/components/ratgdo/__init__.py @@ -2,8 +2,8 @@ import esphome.codegen as cg import esphome.config_validation as cv import voluptuous as vol from esphome import automation, pins -from esphome.const import CONF_ID, CONF_TRIGGER_ID from esphome.components import binary_sensor +from esphome.const import CONF_ID, CONF_TRIGGER_ID DEPENDENCIES = ["preferences"] MULTI_CONF = True @@ -44,43 +44,59 @@ CONF_DRY_CONTACT_OPEN_SENSOR = "dry_contact_open_sensor" CONF_DRY_CONTACT_CLOSE_SENSOR = "dry_contact_close_sensor" CONF_DRY_CONTACT_SENSOR_GROUP = "dry_contact_sensor_group" + def validate_protocol(config): - if config.get(CONF_PROTOCOL, None) == PROTOCOL_DRYCONTACT and (CONF_DRY_CONTACT_CLOSE_SENSOR not in config or CONF_DRY_CONTACT_OPEN_SENSOR not in config): - raise cv.Invalid("dry_contact_close_sensor and dry_contact_open_sensor are required when using protocol drycontact") - if config.get(CONF_PROTOCOL, None) != PROTOCOL_DRYCONTACT and (CONF_DRY_CONTACT_CLOSE_SENSOR in config or CONF_DRY_CONTACT_OPEN_SENSOR in config): - raise cv.Invalid("dry_contact_close_sensor and dry_contact_open_sensor are only valid when using protocol drycontact") -# if config.get(CONF_PROTOCOL, None) == PROTOCOL_DRYCONTACT and CONF_DRY_CONTACT_OPEN_SENSOR not in config: -# raise cv.Invalid("dry_contact_open_sensor is required when using protocol drycontact") + if config.get(CONF_PROTOCOL, None) == PROTOCOL_DRYCONTACT and ( + CONF_DRY_CONTACT_CLOSE_SENSOR not in config + or CONF_DRY_CONTACT_OPEN_SENSOR not in config + ): + raise cv.Invalid( + "dry_contact_close_sensor and dry_contact_open_sensor are required when using protocol drycontact" + ) + if config.get(CONF_PROTOCOL, None) != PROTOCOL_DRYCONTACT and ( + CONF_DRY_CONTACT_CLOSE_SENSOR in config + or CONF_DRY_CONTACT_OPEN_SENSOR in config + ): + raise cv.Invalid( + "dry_contact_close_sensor and dry_contact_open_sensor are only valid when using protocol drycontact" + ) + # if config.get(CONF_PROTOCOL, None) == PROTOCOL_DRYCONTACT and CONF_DRY_CONTACT_OPEN_SENSOR not in config: + # raise cv.Invalid("dry_contact_open_sensor is required when using protocol drycontact") return config + CONFIG_SCHEMA = cv.All( cv.Schema( - { - cv.GenerateID(): cv.declare_id(RATGDO), - cv.Optional( - CONF_OUTPUT_GDO, default=DEFAULT_OUTPUT_GDO - ): pins.gpio_output_pin_schema, - cv.Optional( - CONF_INPUT_GDO, default=DEFAULT_INPUT_GDO - ): pins.gpio_input_pin_schema, - cv.Optional(CONF_INPUT_OBST, default=DEFAULT_INPUT_OBST): cv.Any( - cv.none, pins.gpio_input_pin_schema - ), - cv.Optional(CONF_DISCRETE_OPEN_PIN): pins.gpio_output_pin_schema, - cv.Optional(CONF_DISCRETE_CLOSE_PIN): pins.gpio_output_pin_schema, - cv.Optional(CONF_ON_SYNC_FAILED): automation.validate_automation( - { - cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(SyncFailed), - } - ), - cv.Optional(CONF_PROTOCOL, default=PROTOCOL_SECPLUSV2): cv.All(vol.In( - SUPPORTED_PROTOCOLS - )), - # cv.Inclusive(CONF_DRY_CONTACT_OPEN_SENSOR,CONF_DRY_CONTACT_SENSOR_GROUP): cv.use_id(binary_sensor.BinarySensor), - # cv.Inclusive(CONF_DRY_CONTACT_CLOSE_SENSOR,CONF_DRY_CONTACT_SENSOR_GROUP): cv.use_id(binary_sensor.BinarySensor), - cv.Optional(CONF_DRY_CONTACT_OPEN_SENSOR): cv.use_id(binary_sensor.BinarySensor), - cv.Optional(CONF_DRY_CONTACT_CLOSE_SENSOR): cv.use_id(binary_sensor.BinarySensor), - } + { + cv.GenerateID(): cv.declare_id(RATGDO), + cv.Optional( + CONF_OUTPUT_GDO, default=DEFAULT_OUTPUT_GDO + ): pins.gpio_output_pin_schema, + cv.Optional( + CONF_INPUT_GDO, default=DEFAULT_INPUT_GDO + ): pins.gpio_input_pin_schema, + cv.Optional(CONF_INPUT_OBST, default=DEFAULT_INPUT_OBST): cv.Any( + cv.none, pins.gpio_input_pin_schema + ), + cv.Optional(CONF_DISCRETE_OPEN_PIN): pins.gpio_output_pin_schema, + cv.Optional(CONF_DISCRETE_CLOSE_PIN): pins.gpio_output_pin_schema, + cv.Optional(CONF_ON_SYNC_FAILED): automation.validate_automation( + { + cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(SyncFailed), + } + ), + cv.Optional(CONF_PROTOCOL, default=PROTOCOL_SECPLUSV2): cv.All( + vol.In(SUPPORTED_PROTOCOLS) + ), + # cv.Inclusive(CONF_DRY_CONTACT_OPEN_SENSOR,CONF_DRY_CONTACT_SENSOR_GROUP): cv.use_id(binary_sensor.BinarySensor), + # cv.Inclusive(CONF_DRY_CONTACT_CLOSE_SENSOR,CONF_DRY_CONTACT_SENSOR_GROUP): cv.use_id(binary_sensor.BinarySensor), + cv.Optional(CONF_DRY_CONTACT_OPEN_SENSOR): cv.use_id( + binary_sensor.BinarySensor + ), + cv.Optional(CONF_DRY_CONTACT_CLOSE_SENSOR): cv.use_id( + binary_sensor.BinarySensor + ), + } ).extend(cv.COMPONENT_SCHEMA), validate_protocol, ) @@ -109,11 +125,18 @@ async def to_code(config): cg.add(var.set_input_obst_pin(pin)) if CONF_DRY_CONTACT_OPEN_SENSOR in config and config[CONF_DRY_CONTACT_OPEN_SENSOR]: - dry_contact_open_sensor = await cg.get_variable(config[CONF_DRY_CONTACT_OPEN_SENSOR]) + dry_contact_open_sensor = await cg.get_variable( + config[CONF_DRY_CONTACT_OPEN_SENSOR] + ) cg.add(var.set_dry_contact_open_sensor(dry_contact_open_sensor)) - if CONF_DRY_CONTACT_CLOSE_SENSOR in config and config[CONF_DRY_CONTACT_CLOSE_SENSOR]: - dry_contact_close_sensor = await cg.get_variable(config[CONF_DRY_CONTACT_CLOSE_SENSOR]) + if ( + CONF_DRY_CONTACT_CLOSE_SENSOR in config + and config[CONF_DRY_CONTACT_CLOSE_SENSOR] + ): + dry_contact_close_sensor = await cg.get_variable( + config[CONF_DRY_CONTACT_CLOSE_SENSOR] + ) cg.add(var.set_dry_contact_close_sensor(dry_contact_close_sensor)) for conf in config.get(CONF_ON_SYNC_FAILED, []): diff --git a/components/ratgdo/cover/__init__.py b/components/ratgdo/cover/__init__.py index ea8ba1e..95685a0 100644 --- a/components/ratgdo/cover/__init__.py +++ b/components/ratgdo/cover/__init__.py @@ -18,9 +18,7 @@ CoverOpeningTrigger = ratgdo_ns.class_( CoverClosingTrigger = ratgdo_ns.class_( "CoverClosingTrigger", automation.Trigger.template() ) -CoverStateTrigger = ratgdo_ns.class_( - "CoverStateTrigger", automation.Trigger.template() -) +CoverStateTrigger = ratgdo_ns.class_("CoverStateTrigger", automation.Trigger.template()) CONF_ON_OPENING = "on_opening" CONF_ON_CLOSING = "on_closing"