ESPHome  2024.10.2
vbus_binary_sensor.cpp
Go to the documentation of this file.
1 #include "vbus_binary_sensor.h"
2 #include "esphome/core/helpers.h"
3 #include "esphome/core/log.h"
4 
5 namespace esphome {
6 namespace vbus {
7 
8 static const char *const TAG = "vbus.binary_sensor";
9 
11  ESP_LOGCONFIG(TAG, "Deltasol BS Plus:");
12  LOG_BINARY_SENSOR(" ", "Relay 1 On", this->relay1_bsensor_);
13  LOG_BINARY_SENSOR(" ", "Relay 2 On", this->relay2_bsensor_);
14  LOG_BINARY_SENSOR(" ", "Sensor 1 Error", this->s1_error_bsensor_);
15  LOG_BINARY_SENSOR(" ", "Sensor 2 Error", this->s2_error_bsensor_);
16  LOG_BINARY_SENSOR(" ", "Sensor 3 Error", this->s3_error_bsensor_);
17  LOG_BINARY_SENSOR(" ", "Sensor 4 Error", this->s4_error_bsensor_);
18  LOG_BINARY_SENSOR(" ", "Option Collector Max", this->collector_max_bsensor_);
19  LOG_BINARY_SENSOR(" ", "Option Collector Min", this->collector_min_bsensor_);
20  LOG_BINARY_SENSOR(" ", "Option Collector Frost", this->collector_frost_bsensor_);
21  LOG_BINARY_SENSOR(" ", "Option Tube Collector", this->tube_collector_bsensor_);
22  LOG_BINARY_SENSOR(" ", "Option Recooling", this->recooling_bsensor_);
23  LOG_BINARY_SENSOR(" ", "Option Heat Quantity Measurement", this->hqm_bsensor_);
24 }
25 
26 void DeltaSolBSPlusBSensor::handle_message(std::vector<uint8_t> &message) {
27  if (this->relay1_bsensor_ != nullptr)
28  this->relay1_bsensor_->publish_state(message[10] & 1);
29  if (this->relay2_bsensor_ != nullptr)
30  this->relay2_bsensor_->publish_state(message[10] & 2);
31  if (this->s1_error_bsensor_ != nullptr)
32  this->s1_error_bsensor_->publish_state(message[11] & 1);
33  if (this->s2_error_bsensor_ != nullptr)
34  this->s2_error_bsensor_->publish_state(message[11] & 2);
35  if (this->s3_error_bsensor_ != nullptr)
36  this->s3_error_bsensor_->publish_state(message[11] & 4);
37  if (this->s4_error_bsensor_ != nullptr)
38  this->s4_error_bsensor_->publish_state(message[11] & 8);
39  if (this->collector_max_bsensor_ != nullptr)
40  this->collector_max_bsensor_->publish_state(message[15] & 1);
41  if (this->collector_min_bsensor_ != nullptr)
42  this->collector_min_bsensor_->publish_state(message[15] & 2);
43  if (this->collector_frost_bsensor_ != nullptr)
44  this->collector_frost_bsensor_->publish_state(message[15] & 4);
45  if (this->tube_collector_bsensor_ != nullptr)
46  this->tube_collector_bsensor_->publish_state(message[15] & 8);
47  if (this->recooling_bsensor_ != nullptr)
48  this->recooling_bsensor_->publish_state(message[15] & 0x10);
49  if (this->hqm_bsensor_ != nullptr)
50  this->hqm_bsensor_->publish_state(message[15] & 0x20);
51 }
52 
54  ESP_LOGCONFIG(TAG, "Deltasol BS 2009:");
55  LOG_BINARY_SENSOR(" ", "Sensor 1 Error", this->s1_error_bsensor_);
56  LOG_BINARY_SENSOR(" ", "Sensor 2 Error", this->s2_error_bsensor_);
57  LOG_BINARY_SENSOR(" ", "Sensor 3 Error", this->s3_error_bsensor_);
58  LOG_BINARY_SENSOR(" ", "Sensor 4 Error", this->s4_error_bsensor_);
59  LOG_BINARY_SENSOR(" ", "Frost Protection Active", this->frost_protection_active_bsensor_);
60 }
61 
62 void DeltaSolBS2009BSensor::handle_message(std::vector<uint8_t> &message) {
63  if (this->s1_error_bsensor_ != nullptr)
64  this->s1_error_bsensor_->publish_state(message[20] & 1);
65  if (this->s2_error_bsensor_ != nullptr)
66  this->s2_error_bsensor_->publish_state(message[20] & 2);
67  if (this->s3_error_bsensor_ != nullptr)
68  this->s3_error_bsensor_->publish_state(message[20] & 4);
69  if (this->s4_error_bsensor_ != nullptr)
70  this->s4_error_bsensor_->publish_state(message[20] & 8);
71  if (this->frost_protection_active_bsensor_ != nullptr)
72  this->frost_protection_active_bsensor_->publish_state(message[25] & 1);
73 }
74 
76  ESP_LOGCONFIG(TAG, "Deltasol C:");
77  LOG_BINARY_SENSOR(" ", "Sensor 1 Error", this->s1_error_bsensor_);
78  LOG_BINARY_SENSOR(" ", "Sensor 2 Error", this->s2_error_bsensor_);
79  LOG_BINARY_SENSOR(" ", "Sensor 3 Error", this->s3_error_bsensor_);
80  LOG_BINARY_SENSOR(" ", "Sensor 4 Error", this->s4_error_bsensor_);
81 }
82 
83 void DeltaSolCBSensor::handle_message(std::vector<uint8_t> &message) {
84  if (this->s1_error_bsensor_ != nullptr)
85  this->s1_error_bsensor_->publish_state(message[10] & 1);
86  if (this->s2_error_bsensor_ != nullptr)
87  this->s2_error_bsensor_->publish_state(message[10] & 2);
88  if (this->s3_error_bsensor_ != nullptr)
89  this->s3_error_bsensor_->publish_state(message[10] & 4);
90  if (this->s4_error_bsensor_ != nullptr)
91  this->s4_error_bsensor_->publish_state(message[10] & 8);
92 }
93 
95  ESP_LOGCONFIG(TAG, "Deltasol CS2:");
96  LOG_BINARY_SENSOR(" ", "Sensor 1 Error", this->s1_error_bsensor_);
97  LOG_BINARY_SENSOR(" ", "Sensor 2 Error", this->s2_error_bsensor_);
98  LOG_BINARY_SENSOR(" ", "Sensor 3 Error", this->s3_error_bsensor_);
99  LOG_BINARY_SENSOR(" ", "Sensor 4 Error", this->s4_error_bsensor_);
100 }
101 
102 void DeltaSolCS2BSensor::handle_message(std::vector<uint8_t> &message) {
103  if (this->s1_error_bsensor_ != nullptr)
104  this->s1_error_bsensor_->publish_state(message[18] & 1);
105  if (this->s2_error_bsensor_ != nullptr)
106  this->s2_error_bsensor_->publish_state(message[18] & 2);
107  if (this->s3_error_bsensor_ != nullptr)
108  this->s3_error_bsensor_->publish_state(message[18] & 4);
109  if (this->s4_error_bsensor_ != nullptr)
110  this->s4_error_bsensor_->publish_state(message[18] & 8);
111 }
112 
114  ESP_LOGCONFIG(TAG, "Deltasol CS Plus:");
115  LOG_BINARY_SENSOR(" ", "Sensor 1 Error", this->s1_error_bsensor_);
116  LOG_BINARY_SENSOR(" ", "Sensor 2 Error", this->s2_error_bsensor_);
117  LOG_BINARY_SENSOR(" ", "Sensor 3 Error", this->s3_error_bsensor_);
118  LOG_BINARY_SENSOR(" ", "Sensor 4 Error", this->s4_error_bsensor_);
119 }
120 
121 void DeltaSolCSPlusBSensor::handle_message(std::vector<uint8_t> &message) {
122  if (this->s1_error_bsensor_ != nullptr)
123  this->s1_error_bsensor_->publish_state(message[20] & 1);
124  if (this->s2_error_bsensor_ != nullptr)
125  this->s2_error_bsensor_->publish_state(message[20] & 2);
126  if (this->s3_error_bsensor_ != nullptr)
127  this->s3_error_bsensor_->publish_state(message[20] & 4);
128  if (this->s4_error_bsensor_ != nullptr)
129  this->s4_error_bsensor_->publish_state(message[20] & 8);
130 }
131 
133  ESP_LOGCONFIG(TAG, "VBus Custom Binary Sensor:");
134  if (this->source_ == 0xffff) {
135  ESP_LOGCONFIG(TAG, " Source address: ANY");
136  } else {
137  ESP_LOGCONFIG(TAG, " Source address: 0x%04x", this->source_);
138  }
139  if (this->dest_ == 0xffff) {
140  ESP_LOGCONFIG(TAG, " Dest address: ANY");
141  } else {
142  ESP_LOGCONFIG(TAG, " Dest address: 0x%04x", this->dest_);
143  }
144  if (this->command_ == 0xffff) {
145  ESP_LOGCONFIG(TAG, " Command: ANY");
146  } else {
147  ESP_LOGCONFIG(TAG, " Command: 0x%04x", this->command_);
148  }
149  ESP_LOGCONFIG(TAG, " Binary Sensors:");
150  for (VBusCustomSubBSensor *bsensor : this->bsensors_) {
151  LOG_BINARY_SENSOR(" ", "-", bsensor);
152  }
153 }
154 
155 void VBusCustomBSensor::handle_message(std::vector<uint8_t> &message) {
156  for (VBusCustomSubBSensor *bsensor : this->bsensors_)
157  bsensor->parse_message(message);
158 }
159 
160 void VBusCustomSubBSensor::parse_message(std::vector<uint8_t> &message) {
161  this->publish_state(this->message_parser_(message));
162 }
163 
164 } // namespace vbus
165 } // namespace esphome
binary_sensor::BinarySensor * s2_error_bsensor_
void parse_message(std::vector< uint8_t > &message)
binary_sensor::BinarySensor * s3_error_bsensor_
void handle_message(std::vector< uint8_t > &message) override
void handle_message(std::vector< uint8_t > &message) override
void handle_message(std::vector< uint8_t > &message) override
binary_sensor::BinarySensor * s4_error_bsensor_
void handle_message(std::vector< uint8_t > &message) override
void handle_message(std::vector< uint8_t > &message) override
void handle_message(std::vector< uint8_t > &message) override
void publish_state(bool state)
Publish a new state to the front-end.
binary_sensor::BinarySensor * tube_collector_bsensor_
binary_sensor::BinarySensor * relay2_bsensor_
binary_sensor::BinarySensor * s1_error_bsensor_
binary_sensor::BinarySensor * collector_frost_bsensor_
binary_sensor::BinarySensor * collector_min_bsensor_
binary_sensor::BinarySensor * recooling_bsensor_
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
binary_sensor::BinarySensor * hqm_bsensor_
binary_sensor::BinarySensor * relay1_bsensor_
binary_sensor::BinarySensor * collector_max_bsensor_