Skip to content

Commit

Permalink
Add update-call for outout entities
Browse files Browse the repository at this point in the history
  • Loading branch information
dala318 committed Oct 11, 2023
1 parent dbae4de commit dfcc06b
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 15 deletions.
2 changes: 0 additions & 2 deletions components/rego600/binary_sensor/rego_binary_sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@ void RegoBinarySensor::dump_config() {
LOG_BINARY_SENSOR(" ", "BinarySensor", this);
ESP_LOGCONFIG(TAG, " Rego variable: 0x%s", this->int_to_hex(this->rego_variable_).c_str());
ESP_LOGCONFIG(TAG, " Payload true: %s", this->int_to_hex(this->payload_true_).c_str());
// ESP_LOGCONFIG(TAG, " Payload false: %s", this->int_to_hex(this->action_payload_false).c_str());
ESP_LOGCONFIG(TAG, " Hub: %s", this->hub_->to_str().c_str());
}

void RegoBinarySensor::update() {
uint16_t result = 0;
if (this->hub_->read_value(this->rego_variable_, &result)) {
// this->publish_state(result != 0);
this->publish_state(result == this->payload_true_);
}
else {
Expand Down
2 changes: 0 additions & 2 deletions components/rego600/binary_sensor/rego_binary_sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ class RegoBinarySensor : public binary_sensor::BinarySensor, public RegoBase {
void dump_config() override;
void update() override;
void set_payload_true(uint8_t payload) { this->payload_true_ = payload; }
// void set_action_payload_false(uint8_t payload) { this->action_payload_false_ = payload; }
protected:
uint16_t payload_true_ = 1;
// uint16_t action_payload_false = 0;
};

} // namespace rego
Expand Down
10 changes: 10 additions & 0 deletions components/rego600/number/rego_number.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ void RegoNumber::dump_config() {
ESP_LOGCONFIG(TAG, " Hub: %s", this->hub_->to_str().c_str());
}

void RegoNumber::update() {
uint16_t result = 0;
if (this->hub_->read_value(this->rego_variable_, &result)) {
this->publish_state(result * this->value_factor_);
}
else {
ESP_LOGE(TAG, "Could not update number \"%s\"", this->get_name().c_str());
}
}

void RegoNumber::control(float value) {
uint16_t result = 0;
if (this->hub_->write_value(this->rego_variable_, (uint16_t)(value / this->value_factor_), &result)) {
Expand Down
1 change: 1 addition & 0 deletions components/rego600/number/rego_number.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class RegoNumber : public number::Number, public RegoBase {
void setup() override;
void loop() override;
void dump_config() override;
void update() override;
void control(float value) override;
void set_value_factor(float value_factor) { this->value_factor_ = value_factor; }
void set_retry_write(uint8_t retry) { this->max_retry_attempts_ = retry; }
Expand Down
23 changes: 15 additions & 8 deletions components/rego600/switch/rego_switch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ void RegoSwitch::setup() {
ESP_LOGD(TAG, "Restoring switch %s", this->get_name().c_str());
uint16_t result = 0;
if (this->hub_->read_value(this->rego_variable_, &result)) {
// this->publish_state(result != 0);
this->publish_state(result == this->action_payload_true);
this->publish_state(result == this->action_payload_true_);
}
}

Expand All @@ -33,19 +32,27 @@ void RegoSwitch::dump_config() {
ESP_LOGCONFIG(TAG, "Rego Switch:");
LOG_SWITCH(" ", "Switch", this);
ESP_LOGCONFIG(TAG, " Rego variable: 0x%s", this->int_to_hex(this->rego_variable_).c_str());
ESP_LOGCONFIG(TAG, " Payload true: %s", this->int_to_hex(this->action_payload_true).c_str());
ESP_LOGCONFIG(TAG, " Payload false: %s", this->int_to_hex(this->action_payload_false).c_str());
ESP_LOGCONFIG(TAG, " Payload true: %s", this->int_to_hex(this->action_payload_true_).c_str());
ESP_LOGCONFIG(TAG, " Payload false: %s", this->int_to_hex(this->action_payload_false_).c_str());
ESP_LOGCONFIG(TAG, " Hub: %s", this->hub_);
}

void RegoSwitch::update() {
uint16_t result = 0;
if (this->hub_->read_value(this->rego_variable_, &result)) {
this->publish_state(result == this->action_payload_true_);
}
else {
ESP_LOGE(TAG, "Could not update switch \"%s\"", this->get_name().c_str());
}
}

void RegoSwitch::write_state(bool state) {
uint16_t result = 0;
// uint16_t value = (uint16_t)state;
uint16_t value = (state ? this->action_payload_true : this->action_payload_false);
uint16_t value = (state ? this->action_payload_true_ : this->action_payload_false_);
if (this->hub_->write_value(this->rego_variable_, value, &result)) {
// this->publish_state(result != 0);
// this->publish_state(result == this->action_payload_true);
this->publish_state(result == state);
this->publish_state(state);
this->attempt_ = 0;
}
else {
Expand Down
7 changes: 4 additions & 3 deletions components/rego600/switch/rego_switch.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ class RegoSwitch: public switch_::Switch, public RegoBase {
public:
void setup() override;
void loop() override;
void dump_config() override ;
void dump_config() override;
void update() override;
void write_state(bool state) override;
void set_retry_write(uint8_t retry) { this->max_retry_attempts_ = retry; }
void set_action_payload_true(uint8_t payload) { this->action_payload_true_ = payload; }
void set_action_payload_false(uint8_t payload) { this->action_payload_false_ = payload; }
protected:
uint8_t max_retry_attempts_ = 0;
uint16_t action_payload_true = 1;
uint16_t action_payload_false = 0;
uint16_t action_payload_true_ = 1;
uint16_t action_payload_false_ = 0;
uint8_t attempt_ = 0;
bool retry_value_;
};
Expand Down

0 comments on commit dfcc06b

Please sign in to comment.