Skip to content

Commit

Permalink
Restructure
Browse files Browse the repository at this point in the history
  • Loading branch information
AzonInc committed Oct 24, 2024
1 parent 9f6521d commit 48cc88f
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 39 deletions.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
2 changes: 0 additions & 2 deletions components/nuki_lock/button/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

NukiLockUnpairButton = nuki_lock_ns.class_("NukiLockUnpairButton", button.Button, cg.Component)

DEPENDENCIES = ["nuki_lock"]

CONF_UNPAIR_BUTTON = "unpair"

CONFIG_SCHEMA = {
Expand Down
61 changes: 35 additions & 26 deletions components/nuki_lock/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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]))

Expand Down
2 changes: 0 additions & 2 deletions components/nuki_lock/number/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
2 changes: 0 additions & 2 deletions components/nuki_lock/switch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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"]

Expand Down

0 comments on commit 48cc88f

Please sign in to comment.