Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
  • Loading branch information
AzonInc committed Mar 24, 2024
1 parent c1782b3 commit d337d29
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
31 changes: 30 additions & 1 deletion components/nuki_lock/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,18 @@
import esphome.config_validation as cv
from esphome import automation
from esphome.components import lock, binary_sensor, text_sensor, sensor, switch, button
from esphome.const import CONF_ID, CONF_BATTERY_LEVEL, DEVICE_CLASS_CONNECTIVITY, DEVICE_CLASS_BATTERY, DEVICE_CLASS_DOOR, UNIT_PERCENT, ENTITY_CATEGORY_CONFIG, ENTITY_CATEGORY_DIAGNOSTIC
from esphome.const import (
CONF_ID,
CONF_BATTERY_LEVEL,
DEVICE_CLASS_CONNECTIVITY,
DEVICE_CLASS_BATTERY,
DEVICE_CLASS_DOOR,
UNIT_PERCENT,
ENTITY_CATEGORY_CONFIG,
ENTITY_CATEGORY_DIAGNOSTIC,
CONF_TURN_OFF_ACTION,
CONF_TURN_ON_ACTION
)

AUTO_LOAD = ["binary_sensor", "text_sensor", "sensor", "switch", "button"]

Expand Down Expand Up @@ -61,6 +72,15 @@
NukiLockPairingModeSwitch,
entity_category=ENTITY_CATEGORY_CONFIG,
icon="mdi:bluetooth-connect",
).extend(
{
cv.Optional(CONF_TURN_OFF_ACTION): automation.validate_automation(
single=True
),
cv.Optional(CONF_TURN_ON_ACTION): automation.validate_automation(
single=True
),
}
),
}).extend(cv.polling_component_schema("500ms"))

Expand Down Expand Up @@ -102,6 +122,15 @@ async def to_code(config):
if CONF_PAIRING_MODE_SWITCH in config:
sw = await switch.new_switch(config[CONF_PAIRING_MODE_SWITCH])
await cg.register_parented(sw, config[CONF_ID])
if CONF_TURN_OFF_ACTION in config:
await automation.build_automation(
sw.get_turn_off_trigger(), [], config[CONF_TURN_OFF_ACTION]
)
if CONF_TURN_ON_ACTION in config:
await automation.build_automation(
sw.get_turn_on_trigger(), [], config[CONF_TURN_ON_ACTION]
)

cg.add(var.set_pairing_mode_switch(sw))

@automation.register_action(
Expand Down
15 changes: 15 additions & 0 deletions components/nuki_lock/nuki_lock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,9 @@ namespace esphome
LOG_BUTTON(TAG, "Unpair", this);
}


NukiLockPairingModeSwitch::NukiLockPairingModeSwitch() : turn_on_trigger_(new Trigger<>()), turn_off_trigger_(new Trigger<>()) {}

void NukiLockPairingModeSwitch::setup()
{
this->publish_state(false);
Expand All @@ -603,7 +606,19 @@ namespace esphome
void NukiLockPairingModeSwitch::write_state(bool state)
{
this->parent_->set_pairing_mode(state);

if(state)
{
this->turn_on_trigger_->trigger();
}
else
{
this->turn_off_trigger_->trigger();
}
}

Trigger<> *NukiLockPairingModeSwitch::get_turn_on_trigger() const { return this->turn_on_trigger_; }
Trigger<> *NukiLockPairingModeSwitch::get_turn_off_trigger() const { return this->turn_off_trigger_; }

} //namespace nuki_lock
} //namespace esphome
4 changes: 4 additions & 0 deletions components/nuki_lock/nuki_lock.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,15 @@ namespace esphome {

class NukiLockPairingModeSwitch : public Component, public switch_::Switch {
public:
Trigger<> *get_turn_on_trigger() const;
Trigger<> *get_turn_off_trigger() const;
void set_parent(NukiLockComponent *parent) { this->parent_ = parent; }
protected:
void setup() override;
void dump_config() override;
void write_state(bool state) override;
Trigger<> *turn_on_trigger_;
Trigger<> *turn_off_trigger_;
NukiLockComponent *parent_;
};

Expand Down

0 comments on commit d337d29

Please sign in to comment.