mirror of
https://github.com/esphome/esphome.git
synced 2024-12-03 12:14:13 +01:00
Remove global variable and use get/set pattern, fix const arg.
This commit is contained in:
parent
2450a8d12c
commit
3d01315c84
2 changed files with 14 additions and 7 deletions
|
@ -5,7 +5,10 @@ namespace esphome {
|
||||||
namespace airton {
|
namespace airton {
|
||||||
|
|
||||||
static const char *const TAG = "airton.climate";
|
static const char *const TAG = "airton.climate";
|
||||||
uint8_t previous_mode_ = 0;
|
|
||||||
|
uint8_t AirtonClimate::get_previous_mode_() { return previous_mode_; }
|
||||||
|
|
||||||
|
void AirtonClimate::set_previous_mode_(uint8_t mode) { previous_mode_ = mode; }
|
||||||
|
|
||||||
void AirtonClimate::transmit_state() {
|
void AirtonClimate::transmit_state() {
|
||||||
// Sampled valid state
|
// Sampled valid state
|
||||||
|
@ -81,9 +84,9 @@ uint8_t AirtonClimate::operation_mode_() {
|
||||||
break;
|
break;
|
||||||
case climate::CLIMATE_MODE_OFF:
|
case climate::CLIMATE_MODE_OFF:
|
||||||
default:
|
default:
|
||||||
operating_mode = 0b0111 & this->previous_mode_; // Set previous mode with power state bit off
|
operating_mode = 0b0111 & this->get_previous_mode_(); // Set previous mode with power state bit off
|
||||||
}
|
}
|
||||||
this->previous_mode_ = operating_mode;
|
this->set_previous_mode_(operating_mode);
|
||||||
return operating_mode;
|
return operating_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,7 +164,7 @@ uint8_t AirtonClimate::checksum_(const uint8_t *r_state) {
|
||||||
return checksum;
|
return checksum;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AirtonClimate::parse_state_frame_(uint8_t frame[]) {
|
bool AirtonClimate::parse_state_frame_(uint8_t const frame[]) {
|
||||||
uint8_t mode = frame[2];
|
uint8_t mode = frame[2];
|
||||||
if (mode & 0b00001000) { // Check if power state bit is set
|
if (mode & 0b00001000) { // Check if power state bit is set
|
||||||
switch (mode & 0b00000111) { // Mask anything but the least significant 3 bits
|
switch (mode & 0b00000111) { // Mask anything but the least significant 3 bits
|
||||||
|
|
|
@ -45,10 +45,14 @@ class AirtonClimate : public climate_ir::ClimateIR {
|
||||||
climate::CLIMATE_FAN_HIGH},
|
climate::CLIMATE_FAN_HIGH},
|
||||||
{climate::CLIMATE_SWING_OFF, climate::CLIMATE_SWING_VERTICAL}) {}
|
{climate::CLIMATE_SWING_OFF, climate::CLIMATE_SWING_VERTICAL}) {}
|
||||||
|
|
||||||
protected:
|
private:
|
||||||
// Save the previous operation mode globally
|
// Save the previous operation mode inside instance
|
||||||
uint8_t previous_mode_;
|
uint8_t previous_mode_;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
uint8_t get_previous_mode_();
|
||||||
|
void set_previous_mode_(uint8_t mode);
|
||||||
|
|
||||||
// IR transmission payload builder
|
// IR transmission payload builder
|
||||||
void transmit_state() override;
|
void transmit_state() override;
|
||||||
|
|
||||||
|
@ -64,7 +68,7 @@ class AirtonClimate : public climate_ir::ClimateIR {
|
||||||
|
|
||||||
// IR receiver buffer
|
// IR receiver buffer
|
||||||
bool on_receive(remote_base::RemoteReceiveData data) override;
|
bool on_receive(remote_base::RemoteReceiveData data) override;
|
||||||
bool parse_state_frame_(uint8_t frame[]);
|
bool parse_state_frame_(uint8_t const frame[]);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace airton
|
} // namespace airton
|
||||||
|
|
Loading…
Reference in a new issue