Compare commits

...
13 changed files with 28 additions and 81 deletions

No files matched your search

@@ -1,5 +1,6 @@
#include "ds248x_one_wire_bus.h"
#include "ds248x.h"
#include "esphome/core/helpers.h"
#include "esphome/core/log.h"
namespace esphome::ds248x {
@@ -151,11 +152,7 @@ uint64_t DS248xOneWireBus::search_int() {
}
// Update address based on direction taken
if (dir_taken) {
address |= bit_mask;
} else {
address &= ~bit_mask;
}
assign_bits(address, bit_mask, dir_taken);
}
// Search successful
+3 -6
View File
@@ -1,6 +1,7 @@
#include "htu21d.h"
#include "esphome/core/log.h"
#include "esphome/core/hal.h"
#include "esphome/core/helpers.h"
#include "esphome/core/log.h"
namespace esphome::htu21d {
@@ -112,11 +113,7 @@ void HTU21DComponent::set_heater(bool status) {
this->status_set_warning();
return;
}
if (status) {
raw_heater |= (1 << HTU21D_REG_HTRE_BIT);
} else {
raw_heater &= ~(1 << HTU21D_REG_HTRE_BIT);
}
assign_bits(raw_heater, 1 << HTU21D_REG_HTRE_BIT, status);
if (this->write_register(HTU21D_WRITERHT_REG_CMD, &raw_heater, 1) != i2c::ERROR_OK) {
this->status_set_warning();
return;
+2 -7
View File
@@ -1,6 +1,7 @@
#pragma once
#include "light_color_values.h"
#include "esphome/core/helpers.h"
#include "esphome/core/string_ref.h"
namespace esphome {
@@ -229,13 +230,7 @@ class LightCall {
inline bool get_save_() { return (this->flags_ & FLAG_SAVE) != 0; }
// Helper to set flag - defaults to true for common case
void set_flag_(FieldFlags flag, bool value = true) ESPHOME_ALWAYS_INLINE {
if (value) {
this->flags_ |= flag;
} else {
this->flags_ &= ~flag;
}
}
void set_flag_(FieldFlags flag, bool value = true) ESPHOME_ALWAYS_INLINE { assign_bits(this->flags_, flag, value); }
// Helper to clear flag - reduces code size for common case
void clear_flag_(FieldFlags flag) ESPHOME_ALWAYS_INLINE { this->flags_ &= ~flag; }
@@ -1,6 +1,7 @@
#include "media_player.h"
#include "esphome/core/defines.h"
#include "esphome/core/controller_registry.h"
#include "esphome/core/defines.h"
#include "esphome/core/helpers.h"
#include "esphome/core/log.h"
#include "esphome/core/progmem.h"
@@ -77,19 +78,12 @@ const char *media_player_command_to_string(MediaPlayerCommand command) {
}
void MediaPlayerTraits::set_supports_pause(bool supports_pause) {
if (supports_pause) {
this->feature_flags_ |= MediaPlayerEntityFeature::PAUSE | MediaPlayerEntityFeature::PLAY;
} else {
this->feature_flags_ &= ~(MediaPlayerEntityFeature::PAUSE | MediaPlayerEntityFeature::PLAY);
}
assign_bits(this->feature_flags_, MediaPlayerEntityFeature::PAUSE | MediaPlayerEntityFeature::PLAY, supports_pause);
}
void MediaPlayerTraits::set_supports_turn_off_on(bool supports_turn_off_on) {
if (supports_turn_off_on) {
this->feature_flags_ |= MediaPlayerEntityFeature::TURN_OFF | MediaPlayerEntityFeature::TURN_ON;
} else {
this->feature_flags_ &= ~(MediaPlayerEntityFeature::TURN_OFF | MediaPlayerEntityFeature::TURN_ON);
}
assign_bits(this->feature_flags_, MediaPlayerEntityFeature::TURN_OFF | MediaPlayerEntityFeature::TURN_ON,
supports_turn_off_on);
}
void MediaPlayerCall::validate_() {
+2 -5
View File
@@ -3,6 +3,7 @@
#include <cstdint>
#include "esphome/core/hal.h"
#include "esphome/core/helpers.h"
#include "esphome/core/log.h"
namespace esphome::mpr121 {
@@ -84,11 +85,7 @@ bool MPR121Component::digital_read(uint8_t pin) { return (this->gpio_input_ & (1
void MPR121Component::digital_write(uint8_t pin, bool value) {
const uint8_t ionum = pin - 4;
if (value) {
this->gpio_output_ |= (1 << ionum);
} else {
this->gpio_output_ &= ~(1 << ionum);
}
assign_bits(this->gpio_output_, 1 << ionum, value);
this->flush_gpio_();
}
@@ -46,11 +46,7 @@ class ProvisioningManager : public Component {
void set_source_provisioned(uint8_t source, bool provisioned) {
if (source >= MAX_SOURCES)
return;
if (provisioned) {
this->provisioned_mask_ |= (1UL << source);
} else {
this->provisioned_mask_ &= ~(1UL << source);
}
assign_bits(this->provisioned_mask_, 1UL << source, provisioned);
}
// True once every registered source is provisioned. Config validation guarantees
@@ -62,11 +62,7 @@ int BSDSocketImpl::setblocking(bool blocking) {
if (fl < 0) {
return fl;
}
if (blocking) {
fl &= ~O_NONBLOCK;
} else {
fl |= O_NONBLOCK;
}
assign_bits(fl, O_NONBLOCK, !blocking);
return ::fcntl(this->fd_, F_SETFL, fl);
}
@@ -52,11 +52,7 @@ int LwIPSocketImpl::setblocking(bool blocking) {
if (fl < 0) {
return fl;
}
if (blocking) {
fl &= ~O_NONBLOCK;
} else {
fl |= O_NONBLOCK;
}
assign_bits(fl, O_NONBLOCK, !blocking);
return lwip_fcntl(this->fd_, F_SETFL, fl);
}
@@ -162,11 +162,7 @@ void HostUartComponent::setup() {
break;
};
// Set stop bits
if (this->stop_bits_ == 2) {
options.c_cflag |= CSTOPB;
} else {
options.c_cflag &= ~CSTOPB;
}
assign_bits(options.c_cflag, CSTOPB, this->stop_bits_ == 2);
cfsetispeed(&options, baud);
cfsetospeed(&options, baud);
tcsetattr(this->file_descriptor_, TCSANOW, &options);
+3 -5
View File
@@ -1,3 +1,4 @@
#include "esphome/core/helpers.h"
#include "esphome/core/log.h"
#include "ufire_ec.h"
#include <cmath>
@@ -19,11 +20,8 @@ void UFireECComponent::setup() {
// Write option for temperature adjustments
uint8_t config;
this->read_byte(REGISTER_CONFIG, &config);
if (this->temperature_sensor_ == nullptr && this->temperature_sensor_external_ == nullptr) {
config &= ~CONFIG_TEMP_COMPENSATION;
} else {
config |= CONFIG_TEMP_COMPENSATION;
}
assign_bits(config, CONFIG_TEMP_COMPENSATION,
this->temperature_sensor_ != nullptr || this->temperature_sensor_external_ != nullptr);
this->write_byte(REGISTER_CONFIG, config);
// Update temperature compensation
+3 -5
View File
@@ -1,3 +1,4 @@
#include "esphome/core/helpers.h"
#include "esphome/core/log.h"
#include "ufire_ise.h"
@@ -20,11 +21,8 @@ void UFireISEComponent::setup() {
// Write option for temperature adjustments
uint8_t config;
this->read_byte(REGISTER_CONFIG, &config);
if (this->temperature_sensor_ == nullptr && this->temperature_sensor_external_ == nullptr) {
config &= ~CONFIG_TEMP_COMPENSATION;
} else {
config |= CONFIG_TEMP_COMPENSATION;
}
assign_bits(config, CONFIG_TEMP_COMPENSATION,
this->temperature_sensor_ != nullptr || this->temperature_sensor_external_ != nullptr);
this->write_byte(REGISTER_CONFIG, config);
}
@@ -5,6 +5,7 @@
#include "esphome/core/application.h"
#include "esphome/core/controller_registry.h"
#include "esphome/core/progmem.h"
#include "esphome/core/helpers.h"
#include <cmath>
#include <cstring>
@@ -59,21 +60,13 @@ WaterHeaterCall &WaterHeaterCall::set_target_temperature_high(float temperature)
}
WaterHeaterCall &WaterHeaterCall::set_away(bool away) {
if (away) {
this->state_ |= WATER_HEATER_STATE_AWAY;
} else {
this->state_ &= ~WATER_HEATER_STATE_AWAY;
}
assign_bits(this->state_, WATER_HEATER_STATE_AWAY, away);
this->state_mask_ |= WATER_HEATER_STATE_AWAY;
return *this;
}
WaterHeaterCall &WaterHeaterCall::set_on(bool on) {
if (on) {
this->state_ |= WATER_HEATER_STATE_ON;
} else {
this->state_ &= ~WATER_HEATER_STATE_ON;
}
assign_bits(this->state_, WATER_HEATER_STATE_ON, on);
this->state_mask_ |= WATER_HEATER_STATE_ON;
return *this;
}
@@ -252,13 +252,7 @@ class WaterHeater : public EntityBase {
/// Set the state flags. Should only be called from control().
void set_state_(uint32_t state) { this->state_ = state; }
/// Set or clear a state flag. Should only be called from control().
void set_state_flag_(uint32_t flag, bool value) {
if (value) {
this->state_ |= flag;
} else {
this->state_ &= ~flag;
}
}
void set_state_flag_(uint32_t flag, bool value) { assign_bits(this->state_, flag, value); }
WaterHeaterMode mode_{WATER_HEATER_MODE_OFF};
float current_temperature_{NAN};