Skip to content

Commit

Permalink
Use signed integer for result and payload
Browse files Browse the repository at this point in the history
  • Loading branch information
dala318 committed Aug 26, 2024
1 parent dfcc06b commit 8ce24db
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 18 deletions.
6 changes: 3 additions & 3 deletions components/rego600/.climate/rego_climate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace rego {
static const char *TAG = "rego.climate";

void RegoClimate::setup() {
uint16_t result = 0;
int16_t result = 0;
if (this->hub_->read_value(this->rego_variable_, &result)) {
this->target_temperature = result * this->value_factor_;
this->publish_state();
Expand All @@ -22,7 +22,7 @@ void RegoClimate::dump_config() {
}

void RegoClimate::update() {
uint16_t result = 0;
int16_t result = 0;
if (this->hub_->read_value(this->rego_variable_, &result)) {
this->target_temperature = result * this->value_factor_;
this->publish_state();
Expand All @@ -36,7 +36,7 @@ void RegoClimate::control(const climate::ClimateCall &call) {
if (call.get_target_temperature().has_value()) {
float target_temperature = *call.get_target_temperature();
uint16_t result = 0;
if (this->hub_->write_value(this->rego_variable_, (uint16_t)(target_temperature / this->value_factor_), &result)) {
if (this->hub_->write_value(this->rego_variable_, (int16_t)(target_temperature / this->value_factor_), &result)) {
this->target_temperature = target_temperature;
this->publish_state();
}
Expand Down
2 changes: 1 addition & 1 deletion components/rego600/binary_sensor/rego_binary_sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void RegoBinarySensor::dump_config() {
}

void RegoBinarySensor::update() {
uint16_t result = 0;
int16_t result = 0;
if (this->hub_->read_value(this->rego_variable_, &result)) {
this->publish_state(result == this->payload_true_);
}
Expand Down
2 changes: 1 addition & 1 deletion components/rego600/button/rego_button.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class RegoButton: public button::Button, public RegoBase {
void set_retry_write(uint8_t retry) { this->max_retry_attempts_ = retry; }
void set_action_payload(uint8_t payload) { this->action_payload_ = payload; }
protected:
uint16_t action_payload_ = 0;
int16_t action_payload_ = 0;
uint8_t max_retry_attempts_ = 0;
uint8_t attempt_ = 0;
};
Expand Down
6 changes: 3 additions & 3 deletions components/rego600/number/rego_number.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ static const char *TAG = "rego.number";

void RegoNumber::setup() {
ESP_LOGD(TAG, "Restoring number %s", this->get_name().c_str());
uint16_t result = 0;
int16_t result = 0;
if (this->hub_->read_value(this->rego_variable_, &result)) {
this->publish_state(result * this->value_factor_);
}
Expand Down Expand Up @@ -37,7 +37,7 @@ void RegoNumber::dump_config() {
}

void RegoNumber::update() {
uint16_t result = 0;
int16_t result = 0;
if (this->hub_->read_value(this->rego_variable_, &result)) {
this->publish_state(result * this->value_factor_);
}
Expand All @@ -48,7 +48,7 @@ void RegoNumber::update() {

void RegoNumber::control(float value) {
uint16_t result = 0;
if (this->hub_->write_value(this->rego_variable_, (uint16_t)(value / this->value_factor_), &result)) {
if (this->hub_->write_value(this->rego_variable_, (int16_t)(value / this->value_factor_), &result)) {
this->publish_state(value);
this->attempt_ = 0;
}
Expand Down
4 changes: 2 additions & 2 deletions components/rego600/rego.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void RegoInterfaceComponent::loop() {
}
}

bool RegoInterfaceComponent::read_value(int16_t reg, uint16_t *result)
bool RegoInterfaceComponent::read_value(int16_t reg, int16_t *result)
{
// ESP_LOGD(TAG, "Processing read of register %s (%u)", this->data_to_hexstr, this->data_to_hexstr(reg, sizeof(reg)).c_str(), reg);
size_t available = 0;
Expand Down Expand Up @@ -124,7 +124,7 @@ bool RegoInterfaceComponent::read_text(int16_t reg, std::string *result)
return true;
}

bool RegoInterfaceComponent::write_value(int16_t reg, uint16_t value, uint16_t *result)
bool RegoInterfaceComponent::write_value(int16_t reg, int16_t value, uint16_t *result)
{
// ESP_LOGD(TAG, "Processing write value %u to register %s (%u)", value, this->data_to_hexstr, data_to_hexstr(reg, sizeof(reg)).c_str(), reg);
size_t available = 0;
Expand Down
4 changes: 2 additions & 2 deletions components/rego600/rego.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ class RegoInterfaceComponent : public Component {
// Function override definitions

// Function declaration component
bool read_value(int16_t reg, uint16_t *result);
bool read_value(int16_t reg, int16_t *result);
bool read_text(int16_t reg, std::string *result);
bool write_value(int16_t reg, uint16_t value, uint16_t *result);
bool write_value(int16_t reg, int16_t value, uint16_t *result);

// Function definitions component
void set_model(std::string model){ this->model_ = model; }
Expand Down
2 changes: 1 addition & 1 deletion components/rego600/sensor/rego_sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void RegoSensor::dump_config() {
}

void RegoSensor::update() {
uint16_t result = 0;
int16_t result = 0;
if (this->hub_->read_value(this->rego_variable_, &result)) {
this->publish_state(result * this->value_factor_);
}
Expand Down
6 changes: 3 additions & 3 deletions components/rego600/switch/rego_switch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ static const char *TAG = "rego.switch";

void RegoSwitch::setup() {
ESP_LOGD(TAG, "Restoring switch %s", this->get_name().c_str());
uint16_t result = 0;
int16_t result = 0;
if (this->hub_->read_value(this->rego_variable_, &result)) {
this->publish_state(result == this->action_payload_true_);
}
Expand Down Expand Up @@ -38,7 +38,7 @@ void RegoSwitch::dump_config() {
}

void RegoSwitch::update() {
uint16_t result = 0;
int16_t result = 0;
if (this->hub_->read_value(this->rego_variable_, &result)) {
this->publish_state(result == this->action_payload_true_);
}
Expand All @@ -50,7 +50,7 @@ void RegoSwitch::update() {
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_);
int16_t value = (state ? this->action_payload_true_ : this->action_payload_false_);
if (this->hub_->write_value(this->rego_variable_, value, &result)) {
this->publish_state(state);
this->attempt_ = 0;
Expand Down
4 changes: 2 additions & 2 deletions components/rego600/switch/rego_switch.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class RegoSwitch: public switch_::Switch, public RegoBase {
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;
int16_t action_payload_true_ = 1;
int16_t action_payload_false_ = 0;
uint8_t attempt_ = 0;
bool retry_value_;
};
Expand Down

0 comments on commit 8ce24db

Please sign in to comment.