Home IO Control
ESPHome add-on for IO-Homecontrol devices
Toggle main menu visibility
Loading...
Searching...
No Matches
platform_climate_controls.cpp
Go to the documentation of this file.
1
/// @file platform_climate_controls.cpp
2
/// @brief Generated per-heater auxiliary entities: the window binary sensor and the open-window
3
/// detection switch.
4
/// @ingroup hioc_platforms
5
6
#include "
platform_climate_controls.h
"
7
8
#include "esphome/core/log.h"
9
10
namespace
esphome
{
11
namespace
home_io_control
{
12
13
static
const
char
*
const
TAG_WINDOW
=
"home_io_control.window"
;
14
static
const
char
*
const
TAG_DETECTION
=
"home_io_control.window_detection"
;
15
16
void
IOHomeWindowBinarySensor::setup
() {
17
this->
register_companion_binding_
([
this
](
const
IoDevice
&dev) {
18
if
(dev.
heating
.
window_open
< 0) {
19
// "Closed" must mean the heater said so: nothing read means no state.
20
this->invalidate_state();
21
return
;
22
}
23
this->publish_state(dev.
heating
.
window_open
!= 0);
24
});
25
}
26
27
void
IOHomeWindowBinarySensor::dump_config
() {
28
ESP_LOGCONFIG(
TAG_WINDOW
,
"IO-Homecontrol Window:"
);
29
ESP_LOGCONFIG(
TAG_WINDOW
,
" Device ID: %s"
, this->
device_id_
.c_str());
30
}
31
32
void
IOHomeOpenWindowDetectionSwitch::setup
() {
33
this->
register_companion_binding_
([
this
](
const
IoDevice
&dev) {
34
// Shown only from a reply; a switch with no reading yet keeps its unknown state.
35
if
(dev.
heating
.
open_window_detection
>= 0)
36
this->publish_state(dev.
heating
.
open_window_detection
!= 0);
37
});
38
}
39
40
void
IOHomeOpenWindowDetectionSwitch::write_state
(
bool
state) {
41
if
(this->
parent_
==
nullptr
)
42
return
;
43
if
(!this->
parent_
->
send_heating_command
(this->device_id_,
HeatingFunction::SET_OPEN_WINDOW_DETECTION
,
44
state ? 1.0F : 0.0F)) {
45
ESP_LOGW(
TAG_DETECTION
,
"Device %s: open-window detection %s was not acknowledged"
, this->
device_id_
.c_str(),
46
state ?
"on"
:
"off"
);
47
return
;
48
}
49
// The read-back updates IoDevice::heating, and the companion binding above publishes it.
50
this->
parent_
->
read_heating_register
(this->
device_id_
,
HeatingFunction::SET_OPEN_WINDOW_DETECTION
,
nullptr
,
51
EXCHANGE_RETRY_COUNT);
52
}
53
54
void
IOHomeOpenWindowDetectionSwitch::dump_config
() {
55
ESP_LOGCONFIG(
TAG_DETECTION
,
"IO-Homecontrol Open Window Detection:"
);
56
ESP_LOGCONFIG(
TAG_DETECTION
,
" Device ID: %s"
, this->
device_id_
.c_str());
57
}
58
59
}
// namespace home_io_control
60
}
// namespace esphome
esphome::home_io_control::DeviceBoundCompanion::device_id_
std::string device_id_
Definition
platform_entity_base.h:182
esphome::home_io_control::DeviceBoundCompanion::register_companion_binding_
void register_companion_binding_(const std::function< void(const IoDevice &)> &publish)
Shared setup() body: subscribe to this device's updates and publish the initial state.
Definition
platform_entity_base.h:168
esphome::home_io_control::DeviceBoundCompanion::parent_
IOHomeControlComponent * parent_
Definition
platform_entity_base.h:181
esphome::home_io_control::IOHomeControlComponent::send_heating_command
virtual bool send_heating_command(const std::string &device_id, HeatingFunction fn, float value)
Run one heating function on the heater's private register protocol (CMD_WRITE_PRIVATE 0x20): a write ...
Definition
hub_operations.cpp:714
esphome::home_io_control::IOHomeControlComponent::read_heating_register
virtual bool read_heating_register(const std::string &device_id, HeatingFunction fn, float *value_out, uint8_t max_tries)
Read one register of a heater and fold the decoded value into IoDevice::heating.
Definition
hub_operations.cpp:750
esphome::home_io_control::IOHomeOpenWindowDetectionSwitch::dump_config
void dump_config() override
Dump switch configuration to the log.
Definition
platform_climate_controls.cpp:54
esphome::home_io_control::IOHomeOpenWindowDetectionSwitch::write_state
void write_state(bool state) override
Write the detection setting and read it back.
Definition
platform_climate_controls.cpp:40
esphome::home_io_control::IOHomeOpenWindowDetectionSwitch::setup
void setup() override
Subscribe to the device's updates and publish what is already known.
Definition
platform_climate_controls.cpp:32
esphome::home_io_control::IOHomeWindowBinarySensor::dump_config
void dump_config() override
Dump sensor configuration to the log.
Definition
platform_climate_controls.cpp:27
esphome::home_io_control::IOHomeWindowBinarySensor::setup
void setup() override
Subscribe to the device's updates and publish what is already known.
Definition
platform_climate_controls.cpp:16
esphome::home_io_control
Definition
device_registry.cpp:15
esphome::home_io_control::HeatingFunction::SET_OPEN_WINDOW_DETECTION
@ SET_OPEN_WINDOW_DETECTION
Register 0x0106, read/write: open-window detection on (1) or off (0).
Definition
proto_heating.h:43
esphome::home_io_control::TAG_WINDOW
static const char *const TAG_WINDOW
Definition
platform_climate_controls.cpp:13
esphome::home_io_control::TAG_DETECTION
static const char *const TAG_DETECTION
Definition
platform_climate_controls.cpp:14
esphome
Definition
device_registry.cpp:14
platform_climate_controls.h
Generated per-heater auxiliary entities: the window binary sensor and the open-window detection switc...
esphome::home_io_control::HeatingReadings::window_open
int16_t window_open
0 closed / 1 open; -1 until read.
Definition
proto_heating.h:184
esphome::home_io_control::HeatingReadings::open_window_detection
int16_t open_window_detection
1 detection on / 0 off; -1 until read.
Definition
proto_heating.h:185
esphome::home_io_control::IoDevice
Runtime state of a paired IO‑Homecontrol device.
Definition
proto_device_model.h:413
esphome::home_io_control::IoDevice::heating
HeatingReadings heating
What the hub has read from a heater over the private register protocol (room temperature,...
Definition
proto_device_model.h:506
components
home_io_control
platform_climate_controls.cpp
Generated by
1.18.0