From 48cc88fd3a016cea701b834cdd5a4d2105e65c25 Mon Sep 17 00:00:00 2001 From: Florian Date: Thu, 24 Oct 2024 13:58:47 +0200 Subject: [PATCH] Restructure --- components/nuki_lock/__init__.py | 0 .../__init__.py => binary_sensor.py} | 2 +- components/nuki_lock/button/__init__.py | 2 - components/nuki_lock/lock.py | 61 +++++++++++-------- components/nuki_lock/number/__init__.py | 2 - .../{sensor/__init__.py => sensor.py} | 2 +- components/nuki_lock/switch/__init__.py | 2 - .../__init__.py => text_sensor.py} | 6 +- 8 files changed, 38 insertions(+), 39 deletions(-) create mode 100644 components/nuki_lock/__init__.py rename components/nuki_lock/{binary_sensor/__init__.py => binary_sensor.py} (96%) rename components/nuki_lock/{sensor/__init__.py => sensor.py} (92%) rename components/nuki_lock/{text_sensor/__init__.py => text_sensor.py} (82%) diff --git a/components/nuki_lock/__init__.py b/components/nuki_lock/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/components/nuki_lock/binary_sensor/__init__.py b/components/nuki_lock/binary_sensor.py similarity index 96% rename from components/nuki_lock/binary_sensor/__init__.py rename to components/nuki_lock/binary_sensor.py index 8c7a37a..c3c4376 100644 --- a/components/nuki_lock/binary_sensor/__init__.py +++ b/components/nuki_lock/binary_sensor.py @@ -7,7 +7,7 @@ DEVICE_CLASS_BATTERY, DEVICE_CLASS_DOOR ) -from .. import CONF_NUKI_LOCK_ID, NukiLockComponent, nuki_lock_ns +from . import CONF_NUKI_LOCK_ID, NukiLockComponent DEPENDENCIES = ["nuki_lock"] diff --git a/components/nuki_lock/button/__init__.py b/components/nuki_lock/button/__init__.py index 8da9f5c..1a33337 100644 --- a/components/nuki_lock/button/__init__.py +++ b/components/nuki_lock/button/__init__.py @@ -8,8 +8,6 @@ NukiLockUnpairButton = nuki_lock_ns.class_("NukiLockUnpairButton", button.Button, cg.Component) -DEPENDENCIES = ["nuki_lock"] - CONF_UNPAIR_BUTTON = "unpair" CONFIG_SCHEMA = { diff --git a/components/nuki_lock/lock.py b/components/nuki_lock/lock.py index 170c815..babe049 100644 --- a/components/nuki_lock/lock.py +++ b/components/nuki_lock/lock.py @@ -7,6 +7,15 @@ CONF_TRIGGER_ID ) +DEPENDENCIES = ["lock"] + +nuki_lock_ns = cg.esphome_ns.namespace('nuki_lock') +NukiLockComponent = nuki_lock_ns.class_('NukiLockComponent', cg.Component, lock.Lock) + +PairingModeOnTrigger = nuki_lock_ns.class_("PairingModeOnTrigger", automation.Trigger.template()) +PairingModeOffTrigger = nuki_lock_ns.class_("PairingModeOffTrigger", automation.Trigger.template()) +PairedTrigger = nuki_lock_ns.class_("PairedTrigger", automation.Trigger.template()) + CONF_NUKI_LOCK_ID = "nuki_lock_id" CONF_SECURITY_PIN = "security_pin" @@ -18,38 +27,38 @@ CONF_ON_PAIRING_MODE_OFF = "on_pairing_mode_off_action" CONF_ON_PAIRED = "on_paired_action" -nuki_lock_ns = cg.esphome_ns.namespace('nuki_lock') -NukiLockComponent = nuki_lock_ns.class_('NukiLockComponent', lock.Lock, cg.Component) - -PairingModeOnTrigger = nuki_lock_ns.class_("PairingModeOnTrigger", automation.Trigger.template()) -PairingModeOffTrigger = nuki_lock_ns.class_("PairingModeOffTrigger", automation.Trigger.template()) -PairedTrigger = nuki_lock_ns.class_("PairedTrigger", automation.Trigger.template()) - -CONFIG_SCHEMA = lock.LOCK_SCHEMA.extend({ - cv.GenerateID(): cv.declare_id(NukiLockComponent), - cv.Optional(CONF_PAIRING_TIMEOUT, default="300s"): cv.positive_time_period_seconds, - cv.Optional(CONF_ON_PAIRING_MODE_ON): automation.validate_automation( - { - cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(PairingModeOnTrigger), - } - ), - cv.Optional(CONF_ON_PAIRING_MODE_OFF): automation.validate_automation( - { - cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(PairingModeOffTrigger), - } - ), - cv.Optional(CONF_ON_PAIRED): automation.validate_automation( - { - cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(PairedTrigger), - } - ), -}).extend(cv.polling_component_schema("500ms")) +CONFIG_SCHEMA = cv.Schema( + { + cv.GenerateID(): cv.declare_id(NukiLockComponent), + cv.Optional(CONF_SECURITY_PIN, default=0): cv.uint16_t, + cv.Optional(CONF_PAIRING_TIMEOUT, default="300s"): cv.positive_time_period_seconds, + cv.Optional(CONF_ON_PAIRING_MODE_ON): automation.validate_automation( + { + cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(PairingModeOnTrigger), + } + ), + cv.Optional(CONF_ON_PAIRING_MODE_OFF): automation.validate_automation( + { + cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(PairingModeOffTrigger), + } + ), + cv.Optional(CONF_ON_PAIRED): automation.validate_automation( + { + cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(PairedTrigger), + } + ), + } +) +CONFIG_SCHEMA = cv.All( + CONFIG_SCHEMA.extend(lock.LOCK_SCHEMA).extend(cv.COMPONENT_SCHEMA).extend(cv.polling_component_schema("500ms")) +) async def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) await cg.register_component(var, config) await lock.register_lock(var, config) + if CONF_SECURITY_PIN in config: cg.add(var.set_security_pin(config[CONF_SECURITY_PIN])) diff --git a/components/nuki_lock/number/__init__.py b/components/nuki_lock/number/__init__.py index e7f32b1..0b6d331 100644 --- a/components/nuki_lock/number/__init__.py +++ b/components/nuki_lock/number/__init__.py @@ -8,8 +8,6 @@ NukiLockLedBrightnessNumber = nuki_lock_ns.class_("NukiLockLedBrightnessNumber", number.Number, cg.Component) -DEPENDENCIES = ["nuki_lock"] - CONF_LED_BRIGHTNESS_NUMBER = "led_brightness" CONFIG_SCHEMA = { diff --git a/components/nuki_lock/sensor/__init__.py b/components/nuki_lock/sensor.py similarity index 92% rename from components/nuki_lock/sensor/__init__.py rename to components/nuki_lock/sensor.py index 9725779..e465704 100644 --- a/components/nuki_lock/sensor/__init__.py +++ b/components/nuki_lock/sensor.py @@ -5,7 +5,7 @@ UNIT_PERCENT, DEVICE_CLASS_BATTERY, ) -from .. import CONF_NUKI_LOCK_ID, NukiLockComponent, nuki_lock_ns +from . import CONF_NUKI_LOCK_ID, NukiLockComponent DEPENDENCIES = ["nuki_lock"] diff --git a/components/nuki_lock/switch/__init__.py b/components/nuki_lock/switch/__init__.py index d26db8b..c5fe740 100644 --- a/components/nuki_lock/switch/__init__.py +++ b/components/nuki_lock/switch/__init__.py @@ -11,8 +11,6 @@ NukiLockButtonEnabledSwitch = nuki_lock_ns.class_("NukiLockButtonEnabledSwitch", switch.Switch, cg.Component) NukiLockLedEnabledSwitch = nuki_lock_ns.class_("NukiLockLedEnabledSwitch", switch.Switch, cg.Component) -DEPENDENCIES = ["nuki_lock"] - CONF_PAIRING_MODE_SWITCH = "pairing_mode" CONF_BUTTON_ENABLED_SWITCH = "button_enabled" CONF_LED_ENABLED_SWITCH = "led_enabled" diff --git a/components/nuki_lock/text_sensor/__init__.py b/components/nuki_lock/text_sensor.py similarity index 82% rename from components/nuki_lock/text_sensor/__init__.py rename to components/nuki_lock/text_sensor.py index a575f2f..7990d79 100644 --- a/components/nuki_lock/text_sensor/__init__.py +++ b/components/nuki_lock/text_sensor.py @@ -1,11 +1,7 @@ import esphome.codegen as cg from esphome.components import text_sensor import esphome.config_validation as cv -from esphome.const import ( - UNIT_PERCENT, - DEVICE_CLASS_BATTERY, -) -from .. import CONF_NUKI_LOCK_ID, NukiLockComponent, nuki_lock_ns +from . import CONF_NUKI_LOCK_ID, NukiLockComponent DEPENDENCIES = ["nuki_lock"]