Home IO Control
ESPHome add-on for IO-Homecontrol devices
Loading...
Searching...
No Matches
platform_lock.cpp
Go to the documentation of this file.
1/// @file platform_lock.cpp
2/// @brief Experimental lock entity for IO-Homecontrol lock devices.
3/// @ingroup hioc_platforms
4
5#include "platform_lock.h"
6
7#include "hub_internal.h"
8#include "esphome/core/log.h"
9
10namespace esphome {
11namespace home_io_control {
12
13static const char *const TAG = "home_io_control.lock";
14
16 // Locks participate in the same shared registry and callback fan-out as the other entity types.
17 this->register_device_binding_(this, /*inverted=*/false, [this](const std::string &id, const IoDevice &dev) {
18 this->on_device_update_(id, dev);
19 });
20
21 this->traits.set_assumed_state(false);
22 this->traits.set_requires_code(false);
23 this->traits.set_supports_open(false);
24 this->traits.set_supported_states(
25 {lock::LOCK_STATE_LOCKED, lock::LOCK_STATE_UNLOCKED, lock::LOCK_STATE_LOCKING, lock::LOCK_STATE_UNLOCKING});
26}
27
28void IOHomeLock::control(const lock::LockCall &call) {
29 const auto state = call.get_state();
30 if (!state.has_value())
31 return;
32
33 switch (state.value()) {
34 case lock::LOCK_STATE_LOCKED:
35 case lock::LOCK_STATE_LOCKING:
36 this->parent_->queue_set_lock_state(this->device_id_, true);
37 break;
38 case lock::LOCK_STATE_UNLOCKED:
39 case lock::LOCK_STATE_UNLOCKING:
40 this->parent_->queue_set_lock_state(this->device_id_, false);
41 break;
42 case lock::LOCK_STATE_NONE:
43 case lock::LOCK_STATE_JAMMED:
44 default:
45 break;
46 }
47}
48
49void IOHomeLock::on_device_update_(const std::string &id, const IoDevice &dev) {
50 if (id != this->device_id_ || dev.position == UNKNOWN_POSITION)
51 return;
52
53 if (!dev.is_stopped) {
54 if (dev.target != UNKNOWN_POSITION) {
55 this->publish_state(dev.target < detail::BINARY_ENTITY_ON_POSITION_THRESHOLD ? lock::LOCK_STATE_UNLOCKING
56 : lock::LOCK_STATE_LOCKING);
57 }
58 return;
59 }
60
61 this->publish_state(dev.position < detail::BINARY_ENTITY_ON_POSITION_THRESHOLD ? lock::LOCK_STATE_UNLOCKED
62 : lock::LOCK_STATE_LOCKED);
63}
64
66 LOG_LOCK("", "IO-Homecontrol Lock", this);
67 ESP_LOGCONFIG(TAG, " Device ID: %s", this->device_id_.c_str());
69 ESP_LOGCONFIG(TAG, " Status: experimental and untested");
70}
71
72} // namespace home_io_control
73} // namespace esphome
void register_device_binding_(Component *self, bool inverted, std::function< void(const std::string &, const IoDevice &)> on_update)
Perform the shared setup() registration ritual.
void log_poll_interval_config_(const char *tag) const
Emit the shared two-branch poll-interval line for dump_config().
void setup() override
Initialize the lock entity and register it with the shared hub.
void on_device_update_(const std::string &id, const IoDevice &dev)
Handle inbound device status updates.
void control(const lock::LockCall &call) override
Apply a Home Assistant lock control request.
void dump_config() override
Dump configuration to the log.
Internal helpers shared by the hub implementation .cpp files.
constexpr float BINARY_ENTITY_ON_POSITION_THRESHOLD
Shared 0-100 cutoff: values below this mean binary "on".
static constexpr float UNKNOWN_POSITION
Sentinel value meaning "position is not known yet".
static constexpr const char * TAG
Experimental lock entity for IO-Homecontrol lock-capable devices.
Runtime state of a paired IO‑Homecontrol device.
float target
Target position the device is moving toward.
float position
Current position: 0=open, 100=closed, or UNKNOWN_POSITION.
bool is_stopped
True if device is not moving.