Home IO Control
ESPHome add-on for IO-Homecontrol devices
Toggle main menu visibility
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 "
entity_helpers.h
"
8
#include "esphome/core/log.h"
9
10
namespace
esphome
{
11
namespace
home_io_control
{
12
13
static
const
char
*
const
TAG
=
"home_io_control.lock"
;
14
15
void
IOHomeLock::setup
() {
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
28
void
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
49
void
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
(!
effective_is_stopped
(dev)) {
54
const
float
eff_target =
effective_target
(dev);
55
if
(eff_target != UNKNOWN_POSITION) {
56
this->publish_state(eff_target <
detail::BINARY_ENTITY_ON_POSITION_THRESHOLD
? lock::LOCK_STATE_UNLOCKING
57
: lock::LOCK_STATE_LOCKING);
58
}
59
return
;
60
}
61
62
this->publish_state(dev.
position
<
detail::BINARY_ENTITY_ON_POSITION_THRESHOLD
? lock::LOCK_STATE_UNLOCKED
63
: lock::LOCK_STATE_LOCKED);
64
}
65
66
void
IOHomeLock::dump_config
() {
67
LOG_LOCK(
""
,
"IO-Homecontrol Lock"
,
this
);
68
ESP_LOGCONFIG(
TAG
,
" Device ID: %s"
, this->
device_id_
.c_str());
69
this->
log_poll_interval_config_
(
TAG
);
70
ESP_LOGCONFIG(
TAG
,
" Status: experimental and untested"
);
71
}
72
73
}
// namespace home_io_control
74
}
// namespace esphome
esphome::home_io_control::DeviceBoundEntity::device_id_
std::string device_id_
Definition
platform_entity_base.h:116
esphome::home_io_control::DeviceBoundEntity::log_poll_interval_config_
void log_poll_interval_config_(const char *tag) const
Emit the shared two-branch poll-interval line for dump_config().
Definition
platform_entity_base.h:107
esphome::home_io_control::DeviceBoundEntity::register_device_binding_
void register_device_binding_(Component *self, bool inverted, std::function< void(const std::string &, const IoDevice &)> on_update, bool schedule_initial_poll=true)
Perform the shared setup() registration ritual.
Definition
platform_entity_base.h:81
esphome::home_io_control::DeviceBoundEntity::parent_
IOHomeControlComponent * parent_
Definition
platform_entity_base.h:115
esphome::home_io_control::IOHomeControlComponent::queue_set_lock_state
virtual void queue_set_lock_state(const std::string &device_id, bool locked)
Async form of set_lock_state() that keeps radio work serialized on the main loop.
Definition
hub_operations.cpp:675
esphome::home_io_control::IOHomeLock::setup
void setup() override
Initialize the lock entity and register it with the shared hub.
Definition
platform_lock.cpp:15
esphome::home_io_control::IOHomeLock::on_device_update_
void on_device_update_(const std::string &id, const IoDevice &dev)
Handle inbound device status updates.
Definition
platform_lock.cpp:49
esphome::home_io_control::IOHomeLock::control
void control(const lock::LockCall &call) override
Apply a Home Assistant lock control request.
Definition
platform_lock.cpp:28
esphome::home_io_control::IOHomeLock::dump_config
void dump_config() override
Dump configuration to the log.
Definition
platform_lock.cpp:66
entity_helpers.h
Conversions and renderers shared by the hub and its Home Assistant entities.
esphome::home_io_control::detail::BINARY_ENTITY_ON_POSITION_THRESHOLD
constexpr float BINARY_ENTITY_ON_POSITION_THRESHOLD
Shared 0-100 cutoff: values below this mean binary "on".
Definition
entity_helpers.h:29
esphome::home_io_control
Definition
device_registry.cpp:13
esphome::home_io_control::TAG
static constexpr const char * TAG
Definition
device_registry.cpp:15
esphome::home_io_control::effective_target
float effective_target(const IoDevice &dev)
The main-position target a consumer should act on: the prediction when one stands,...
Definition
proto_device_model.h:436
esphome::home_io_control::effective_is_stopped
bool effective_is_stopped(const IoDevice &dev)
Whether a consumer should treat the device as at rest, prediction first.
Definition
proto_device_model.h:450
esphome::home_io_control::TAG
static const char *const TAG
Definition
platform_lock.cpp:13
esphome
Definition
device_registry.cpp:12
platform_lock.h
Experimental lock entity for IO-Homecontrol lock-capable devices.
esphome::home_io_control::IoDevice
Runtime state of a paired IO‑Homecontrol device.
Definition
proto_device_model.h:321
esphome::home_io_control::IoDevice::position
float position
Current position: 0=open, 100=closed, or UNKNOWN_POSITION.
Definition
proto_device_model.h:326
components
home_io_control
platform_lock.cpp
Generated by
1.18.0