1
0
mirror of https://github.com/esphome/esphome.git synced 2025-03-01 00:08:15 +00:00

Refactoring improves variables names

This commit is contained in:
Georgi Filipov 2025-01-16 22:57:55 +02:00
parent dc9e4638dc
commit 68f0c06780
2 changed files with 67 additions and 67 deletions

View File

@ -7,27 +7,27 @@ namespace samsung {
void SamsungClimate::transmit_state() { void SamsungClimate::transmit_state() {
if (current_climate_mode_ != climate::ClimateMode::CLIMATE_MODE_OFF && if (current_climate_mode_ != climate::ClimateMode::CLIMATE_MODE_OFF &&
this->mode == climate::ClimateMode::CLIMATE_MODE_OFF) { this->mode == climate::ClimateMode::CLIMATE_MODE_OFF) {
send_power_state_(false); this->send_power_state_(false);
return; return;
} }
if (current_climate_mode_ == climate::ClimateMode::CLIMATE_MODE_OFF && if (current_climate_mode_ == climate::ClimateMode::CLIMATE_MODE_OFF &&
this->mode != climate::ClimateMode::CLIMATE_MODE_OFF) { this->mode != climate::ClimateMode::CLIMATE_MODE_OFF) {
send_power_state_(true); this->send_power_state_(true);
} }
current_climate_mode_ = this->mode; current_climate_mode_ = this->mode;
set_mode_(this->mode); this->set_mode_(this->mode);
set_temp_(this->target_temperature); this->set_temp_(this->target_temperature);
set_swing_(this->swing_mode); this->set_swing_(this->swing_mode);
set_fan_(this->fan_mode.has_value() ? this->fan_mode.value() : climate::CLIMATE_FAN_AUTO); this->set_fan_(this->fan_mode.has_value() ? this->fan_mode.value() : climate::CLIMATE_FAN_AUTO);
send_(); this->send_();
} }
void SamsungClimate::send_() { void SamsungClimate::send_() {
checksum_(); this->checksum_();
auto transmit = this->transmitter_->transmit(); auto transmit = this->transmitter_->transmit();
auto *data = transmit.get_data(); auto *data = transmit.get_data();
@ -66,17 +66,17 @@ void SamsungClimate::send_() {
void SamsungClimate::set_swing_(const climate::ClimateSwingMode swing_mode) { void SamsungClimate::set_swing_(const climate::ClimateSwingMode swing_mode) {
switch (swing_mode) { switch (swing_mode) {
case climate::ClimateSwingMode::CLIMATE_SWING_BOTH: case climate::ClimateSwingMode::CLIMATE_SWING_BOTH:
protocol_.Swing = K_SAMSUNG_AC_SWING_BOTH; protocol_.swing = K_SAMSUNG_AC_SWING_BOTH;
break; break;
case climate::ClimateSwingMode::CLIMATE_SWING_HORIZONTAL: case climate::ClimateSwingMode::CLIMATE_SWING_HORIZONTAL:
protocol_.Swing = K_SAMSUNG_AC_SWING_H; protocol_.swing = K_SAMSUNG_AC_SWING_H;
break; break;
case climate::ClimateSwingMode::CLIMATE_SWING_VERTICAL: case climate::ClimateSwingMode::CLIMATE_SWING_VERTICAL:
protocol_.Swing = K_SAMSUNG_AC_SWING_V; protocol_.swing = K_SAMSUNG_AC_SWING_V;
break; break;
case climate::ClimateSwingMode::CLIMATE_SWING_OFF: case climate::ClimateSwingMode::CLIMATE_SWING_OFF:
default: default:
protocol_.Swing = K_SAMSUNG_AC_SWING_OFF; protocol_.swing = K_SAMSUNG_AC_SWING_OFF;
break; break;
} }
} }
@ -84,27 +84,27 @@ void SamsungClimate::set_swing_(const climate::ClimateSwingMode swing_mode) {
void SamsungClimate::set_mode_(const climate::ClimateMode climate_mode) { void SamsungClimate::set_mode_(const climate::ClimateMode climate_mode) {
switch (climate_mode) { switch (climate_mode) {
case climate::ClimateMode::CLIMATE_MODE_HEAT: case climate::ClimateMode::CLIMATE_MODE_HEAT:
protocol_.Mode = K_SAMSUNG_AC_HEAT; protocol_.mode = K_SAMSUNG_AC_HEAT;
break; break;
case climate::ClimateMode::CLIMATE_MODE_DRY: case climate::ClimateMode::CLIMATE_MODE_DRY:
protocol_.Mode = K_SAMSUNG_AC_DRY; protocol_.mode = K_SAMSUNG_AC_DRY;
break; break;
case climate::ClimateMode::CLIMATE_MODE_COOL: case climate::ClimateMode::CLIMATE_MODE_COOL:
protocol_.Mode = K_SAMSUNG_AC_COOL; protocol_.mode = K_SAMSUNG_AC_COOL;
break; break;
case climate::ClimateMode::CLIMATE_MODE_FAN_ONLY: case climate::ClimateMode::CLIMATE_MODE_FAN_ONLY:
protocol_.Mode = K_SAMSUNG_AC_FAN; protocol_.mode = K_SAMSUNG_AC_FAN;
break; break;
case climate::ClimateMode::CLIMATE_MODE_HEAT_COOL: case climate::ClimateMode::CLIMATE_MODE_HEAT_COOL:
case climate::ClimateMode::CLIMATE_MODE_AUTO: case climate::ClimateMode::CLIMATE_MODE_AUTO:
default: default:
protocol_.Mode = K_SAMSUNG_AC_AUTO; protocol_.mode = K_SAMSUNG_AC_AUTO;
break; break;
} }
} }
void SamsungClimate::set_temp_(const uint8_t temp) { void SamsungClimate::set_temp_(const uint8_t temp) {
protocol_.Temp = esphome::clamp<uint8_t>(temp, K_SAMSUNG_AC_MIN_TEMP, K_SAMSUNG_AC_MAX_TEMP); protocol_.temp = esphome::clamp<uint8_t>(temp, K_SAMSUNG_AC_MIN_TEMP, K_SAMSUNG_AC_MAX_TEMP);
} }
void SamsungClimate::send_power_state_(const bool on) { void SamsungClimate::send_power_state_(const bool on) {
@ -118,7 +118,7 @@ void SamsungClimate::send_power_state_(const bool on) {
std::memcpy(protocol_.raw, on ? K_ON : K_OFF, K_SAMSUNG_AC_EXTENDED_STATE_LENGTH); std::memcpy(protocol_.raw, on ? K_ON : K_OFF, K_SAMSUNG_AC_EXTENDED_STATE_LENGTH);
send_(); this->send_();
std::memcpy(protocol_.raw, K_RESET, K_SAMSUNG_AC_EXTENDED_STATE_LENGTH); std::memcpy(protocol_.raw, K_RESET, K_SAMSUNG_AC_EXTENDED_STATE_LENGTH);
} }
@ -126,17 +126,17 @@ void SamsungClimate::send_power_state_(const bool on) {
void SamsungClimate::set_fan_(const climate::ClimateFanMode fan_mode) { void SamsungClimate::set_fan_(const climate::ClimateFanMode fan_mode) {
switch (fan_mode) { switch (fan_mode) {
case climate::ClimateFanMode::CLIMATE_FAN_LOW: case climate::ClimateFanMode::CLIMATE_FAN_LOW:
protocol_.Fan = K_SAMSUNG_AC_FAN_LOW; protocol_.fan = K_SAMSUNG_AC_FAN_LOW;
break; break;
case climate::ClimateFanMode::CLIMATE_FAN_MEDIUM: case climate::ClimateFanMode::CLIMATE_FAN_MEDIUM:
protocol_.Fan = K_SAMSUNG_AC_FAN_MED; protocol_.fan = K_SAMSUNG_AC_FAN_MED;
break; break;
case climate::ClimateFanMode::CLIMATE_FAN_HIGH: case climate::ClimateFanMode::CLIMATE_FAN_HIGH:
protocol_.Fan = K_SAMSUNG_AC_FAN_HIGH; protocol_.fan = K_SAMSUNG_AC_FAN_HIGH;
break; break;
case climate::ClimateFanMode::CLIMATE_FAN_AUTO: case climate::ClimateFanMode::CLIMATE_FAN_AUTO:
default: default:
protocol_.Fan = K_SAMSUNG_AC_FAN_AUTO; protocol_.fan = K_SAMSUNG_AC_FAN_AUTO;
break; break;
} }
} }
@ -156,15 +156,15 @@ uint8_t SamsungClimate::calc_section_checksum(const uint8_t *section) {
} }
void SamsungClimate::checksum_() { void SamsungClimate::checksum_() {
uint8_t sectionsum = calc_section_checksum(protocol_.raw); uint8_t sectionsum = this->calc_section_checksum(protocol_.raw);
protocol_.Sum1Upper = GETBITS8(sectionsum, K_HIGH_NIBBLE, K_NIBBLE_SIZE); protocol_.sum_1_upper = GETBITS8(sectionsum, K_HIGH_NIBBLE, K_NIBBLE_SIZE);
protocol_.Sum1Lower = GETBITS8(sectionsum, K_LOW_NIBBLE, K_NIBBLE_SIZE); protocol_.sum_1_lower = GETBITS8(sectionsum, K_LOW_NIBBLE, K_NIBBLE_SIZE);
sectionsum = calc_section_checksum(protocol_.raw + K_SAMSUNG_AC_SECTION_LENGTH); sectionsum = this->calc_section_checksum(protocol_.raw + K_SAMSUNG_AC_SECTION_LENGTH);
protocol_.Sum2Upper = GETBITS8(sectionsum, K_HIGH_NIBBLE, K_NIBBLE_SIZE); protocol_.sum_2_upper = GETBITS8(sectionsum, K_HIGH_NIBBLE, K_NIBBLE_SIZE);
protocol_.Sum2Lower = GETBITS8(sectionsum, K_LOW_NIBBLE, K_NIBBLE_SIZE); protocol_.sum_2_lower = GETBITS8(sectionsum, K_LOW_NIBBLE, K_NIBBLE_SIZE);
sectionsum = calc_section_checksum(protocol_.raw + K_SAMSUNG_AC_SECTION_LENGTH * 2); sectionsum = this->calc_section_checksum(protocol_.raw + K_SAMSUNG_AC_SECTION_LENGTH * 2);
protocol_.Sum3Upper = GETBITS8(sectionsum, K_HIGH_NIBBLE, K_NIBBLE_SIZE); protocol_.sum_3_upper = GETBITS8(sectionsum, K_HIGH_NIBBLE, K_NIBBLE_SIZE);
protocol_.Sum3Lower = GETBITS8(sectionsum, K_LOW_NIBBLE, K_NIBBLE_SIZE); protocol_.sum_3_lower = GETBITS8(sectionsum, K_LOW_NIBBLE, K_NIBBLE_SIZE);
} }
uint16_t SamsungClimate::count_bits(const uint8_t *const start, const uint16_t length, const bool ones, uint16_t SamsungClimate::count_bits(const uint8_t *const start, const uint16_t length, const bool ones,

View File

@ -58,9 +58,9 @@ union SamsungProtocol {
uint8_t : 8; uint8_t : 8;
// Byte 1 // Byte 1
uint8_t : 4; uint8_t : 4;
uint8_t : 4; // Sum1Lower uint8_t : 4; // sum_1_lower
// Byte 2 // Byte 2
uint8_t : 4; // Sum1Upper uint8_t : 4; // sum_1_upper
uint8_t : 4; uint8_t : 4;
// Byte 3 // Byte 3
uint8_t : 8; uint8_t : 8;
@ -68,43 +68,43 @@ union SamsungProtocol {
uint8_t : 8; uint8_t : 8;
// Byte 5 // Byte 5
uint8_t : 4; uint8_t : 4;
uint8_t Sleep5 : 1; uint8_t sleep_5 : 1;
uint8_t Quiet : 1; uint8_t quiet : 1;
uint8_t : 2; uint8_t : 2;
// Byte 6 // Byte 6
uint8_t : 4; uint8_t : 4;
uint8_t Power1 : 2; uint8_t power_1 : 2;
uint8_t : 2; uint8_t : 2;
// Byte 7 // Byte 7
uint8_t : 8; uint8_t : 8;
// Byte 8 // Byte 8
uint8_t : 4; uint8_t : 4;
uint8_t : 4; // Sum2Lower uint8_t : 4; // sum_2_lower
// Byte 9 // Byte 9
uint8_t : 4; // Sum1Upper uint8_t : 4; // sum_1_upper
uint8_t Swing : 3; uint8_t swing : 3;
uint8_t : 1; uint8_t : 1;
// Byte 10 // Byte 10
uint8_t : 1; uint8_t : 1;
uint8_t FanSpecial : 3; // Powerful, Breeze/WindFree, Econo uint8_t fan_special : 3; // Powerful, Breeze/WindFree, Econo
uint8_t Display : 1; uint8_t display : 1;
uint8_t : 2; uint8_t : 2;
uint8_t CleanToggle10 : 1; uint8_t clean_toggle_10 : 1;
// Byte 11 // Byte 11
uint8_t Ion : 1; uint8_t ion : 1;
uint8_t CleanToggle11 : 1; uint8_t clean_toggle_11 : 1;
uint8_t : 2; uint8_t : 2;
uint8_t Temp : 4; uint8_t temp : 4;
// Byte 12 // Byte 12
uint8_t : 1; uint8_t : 1;
uint8_t Fan : 3; uint8_t fan : 3;
uint8_t Mode : 3; uint8_t mode : 3;
uint8_t : 1; uint8_t : 1;
// Byte 13 // Byte 13
uint8_t : 2; uint8_t : 2;
uint8_t BeepToggle : 1; uint8_t beep_toggle : 1;
uint8_t : 1; uint8_t : 1;
uint8_t Power2 : 2; uint8_t power_2 : 2;
uint8_t : 2; uint8_t : 2;
}; };
struct { // Extended message map struct { // Extended message map
@ -113,9 +113,9 @@ union SamsungProtocol {
uint8_t : 8; uint8_t : 8;
// Byte 1 // Byte 1
uint8_t : 4; uint8_t : 4;
uint8_t Sum1Lower : 4; uint8_t sum_1_lower : 4;
// Byte 2 // Byte 2
uint8_t Sum1Upper : 4; uint8_t sum_1_upper : 4;
uint8_t : 4; uint8_t : 4;
// Byte 3 // Byte 3
uint8_t : 8; uint8_t : 8;
@ -130,24 +130,24 @@ union SamsungProtocol {
uint8_t : 8; uint8_t : 8;
// Byte 8 // Byte 8
uint8_t : 4; uint8_t : 4;
uint8_t Sum2Lower : 4; uint8_t sum_2_lower : 4;
// Byte 9 // Byte 9
uint8_t Sum2Upper : 4; uint8_t sum_2_upper : 4;
uint8_t OffTimeMins : 3; // In units of 10's of mins uint8_t off_time_mins : 3; // In units of 10's of mins
uint8_t OffTimeHrs1 : 1; // LSB of the number of hours. uint8_t off_time_hrs_1 : 1; // LSB of the number of hours.
// Byte 10 // Byte 10
uint8_t OffTimeHrs2 : 4; // MSBs of the number of hours. uint8_t off_time_hrs_2 : 4; // MSBs of the number of hours.
uint8_t OnTimeMins : 3; // In units of 10's of mins uint8_t on_time_mins : 3; // In units of 10's of mins
uint8_t OnTimeHrs1 : 1; // LSB of the number of hours. uint8_t on_time_hrs_1 : 1; // LSB of the number of hours.
// Byte 11 // Byte 11
uint8_t OnTimeHrs2 : 4; // MSBs of the number of hours. uint8_t on_time_hrs_2 : 4; // MSBs of the number of hours.
uint8_t : 4; uint8_t : 4;
// Byte 12 // Byte 12
uint8_t OffTimeDay : 1; uint8_t off_time_day : 1;
uint8_t OnTimerEnable : 1; uint8_t on_timer_enable : 1;
uint8_t OffTimerEnable : 1; uint8_t off_timer_enable : 1;
uint8_t Sleep12 : 1; uint8_t sleep_12 : 1;
uint8_t OnTimeDay : 1; uint8_t on_time_day : 1;
uint8_t : 3; uint8_t : 3;
// Byte 13 // Byte 13
uint8_t : 8; uint8_t : 8;
@ -156,9 +156,9 @@ union SamsungProtocol {
uint8_t : 8; uint8_t : 8;
// Byte 15 // Byte 15
uint8_t : 4; uint8_t : 4;
uint8_t Sum3Lower : 4; uint8_t sum_3_lower : 4;
// Byte 16 // Byte 16
uint8_t Sum3Upper : 4; uint8_t sum_3_upper : 4;
uint8_t : 4; uint8_t : 4;
// Byte 17 // Byte 17
uint8_t : 8; uint8_t : 8;