mirror of
https://github.com/esphome/esphome.git
synced 2025-10-29 06:04:01 +00:00
migrate
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "climate_mode.h"
|
#include "climate_mode.h"
|
||||||
#include "esphome/core/enum_bitmask.h"
|
#include "esphome/core/finite_set_mask.h"
|
||||||
#include "esphome/core/helpers.h"
|
#include "esphome/core/helpers.h"
|
||||||
|
|
||||||
// Forward declare climate enums and bitmask sizes
|
// Forward declare climate enums and bitmask sizes
|
||||||
@@ -14,19 +14,19 @@ constexpr int CLIMATE_SWING_MODE_BITMASK_SIZE = 8; // 4 values (OFF, BOTH, VERT
|
|||||||
constexpr int CLIMATE_PRESET_BITMASK_SIZE = 8; // 8 values (NONE, HOME, AWAY, BOOST, COMFORT, ECO, SLEEP, ACTIVITY)
|
constexpr int CLIMATE_PRESET_BITMASK_SIZE = 8; // 8 values (NONE, HOME, AWAY, BOOST, COMFORT, ECO, SLEEP, ACTIVITY)
|
||||||
} // namespace esphome::climate
|
} // namespace esphome::climate
|
||||||
|
|
||||||
// Template specializations for enum-to-bit conversions
|
// Template specializations for value-to-bit conversions
|
||||||
// MUST be declared before any instantiation of EnumBitmask<ClimateMode>, etc.
|
// MUST be declared before any instantiation of FiniteSetMask<ClimateMode>, etc.
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
|
|
||||||
// ClimateMode specialization (7 values: 0-6)
|
// ClimateMode specialization (7 values: 0-6)
|
||||||
template<>
|
template<>
|
||||||
constexpr int EnumBitmask<climate::ClimateMode, climate::CLIMATE_MODE_BITMASK_SIZE>::enum_to_bit(
|
constexpr int FiniteSetMask<climate::ClimateMode, climate::CLIMATE_MODE_BITMASK_SIZE>::value_to_bit(
|
||||||
climate::ClimateMode mode) {
|
climate::ClimateMode mode) {
|
||||||
return static_cast<int>(mode); // Direct mapping: enum value = bit position
|
return static_cast<int>(mode); // Direct mapping: enum value = bit position
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
inline climate::ClimateMode EnumBitmask<climate::ClimateMode, climate::CLIMATE_MODE_BITMASK_SIZE>::bit_to_enum(
|
inline climate::ClimateMode FiniteSetMask<climate::ClimateMode, climate::CLIMATE_MODE_BITMASK_SIZE>::bit_to_value(
|
||||||
int bit) {
|
int bit) {
|
||||||
// Lookup array mapping bit positions to enum values
|
// Lookup array mapping bit positions to enum values
|
||||||
static constexpr climate::ClimateMode MODES[] = {
|
static constexpr climate::ClimateMode MODES[] = {
|
||||||
@@ -44,14 +44,14 @@ inline climate::ClimateMode EnumBitmask<climate::ClimateMode, climate::CLIMATE_M
|
|||||||
|
|
||||||
// ClimateFanMode specialization (10 values: 0-9)
|
// ClimateFanMode specialization (10 values: 0-9)
|
||||||
template<>
|
template<>
|
||||||
constexpr int EnumBitmask<climate::ClimateFanMode, climate::CLIMATE_FAN_MODE_BITMASK_SIZE>::enum_to_bit(
|
constexpr int FiniteSetMask<climate::ClimateFanMode, climate::CLIMATE_FAN_MODE_BITMASK_SIZE>::value_to_bit(
|
||||||
climate::ClimateFanMode mode) {
|
climate::ClimateFanMode mode) {
|
||||||
return static_cast<int>(mode); // Direct mapping: enum value = bit position
|
return static_cast<int>(mode); // Direct mapping: enum value = bit position
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
inline climate::ClimateFanMode EnumBitmask<climate::ClimateFanMode,
|
inline climate::ClimateFanMode FiniteSetMask<climate::ClimateFanMode,
|
||||||
climate::CLIMATE_FAN_MODE_BITMASK_SIZE>::bit_to_enum(int bit) {
|
climate::CLIMATE_FAN_MODE_BITMASK_SIZE>::bit_to_value(int bit) {
|
||||||
static constexpr climate::ClimateFanMode MODES[] = {
|
static constexpr climate::ClimateFanMode MODES[] = {
|
||||||
climate::CLIMATE_FAN_ON, // bit 0
|
climate::CLIMATE_FAN_ON, // bit 0
|
||||||
climate::CLIMATE_FAN_OFF, // bit 1
|
climate::CLIMATE_FAN_OFF, // bit 1
|
||||||
@@ -70,14 +70,14 @@ inline climate::ClimateFanMode EnumBitmask<climate::ClimateFanMode,
|
|||||||
|
|
||||||
// ClimateSwingMode specialization (4 values: 0-3)
|
// ClimateSwingMode specialization (4 values: 0-3)
|
||||||
template<>
|
template<>
|
||||||
constexpr int EnumBitmask<climate::ClimateSwingMode, climate::CLIMATE_SWING_MODE_BITMASK_SIZE>::enum_to_bit(
|
constexpr int FiniteSetMask<climate::ClimateSwingMode, climate::CLIMATE_SWING_MODE_BITMASK_SIZE>::value_to_bit(
|
||||||
climate::ClimateSwingMode mode) {
|
climate::ClimateSwingMode mode) {
|
||||||
return static_cast<int>(mode); // Direct mapping: enum value = bit position
|
return static_cast<int>(mode); // Direct mapping: enum value = bit position
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
inline climate::ClimateSwingMode EnumBitmask<climate::ClimateSwingMode,
|
inline climate::ClimateSwingMode FiniteSetMask<climate::ClimateSwingMode,
|
||||||
climate::CLIMATE_SWING_MODE_BITMASK_SIZE>::bit_to_enum(int bit) {
|
climate::CLIMATE_SWING_MODE_BITMASK_SIZE>::bit_to_value(int bit) {
|
||||||
static constexpr climate::ClimateSwingMode MODES[] = {
|
static constexpr climate::ClimateSwingMode MODES[] = {
|
||||||
climate::CLIMATE_SWING_OFF, // bit 0
|
climate::CLIMATE_SWING_OFF, // bit 0
|
||||||
climate::CLIMATE_SWING_BOTH, // bit 1
|
climate::CLIMATE_SWING_BOTH, // bit 1
|
||||||
@@ -90,13 +90,13 @@ inline climate::ClimateSwingMode EnumBitmask<climate::ClimateSwingMode,
|
|||||||
|
|
||||||
// ClimatePreset specialization (8 values: 0-7)
|
// ClimatePreset specialization (8 values: 0-7)
|
||||||
template<>
|
template<>
|
||||||
constexpr int EnumBitmask<climate::ClimatePreset, climate::CLIMATE_PRESET_BITMASK_SIZE>::enum_to_bit(
|
constexpr int FiniteSetMask<climate::ClimatePreset, climate::CLIMATE_PRESET_BITMASK_SIZE>::value_to_bit(
|
||||||
climate::ClimatePreset preset) {
|
climate::ClimatePreset preset) {
|
||||||
return static_cast<int>(preset); // Direct mapping: enum value = bit position
|
return static_cast<int>(preset); // Direct mapping: enum value = bit position
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
inline climate::ClimatePreset EnumBitmask<climate::ClimatePreset, climate::CLIMATE_PRESET_BITMASK_SIZE>::bit_to_enum(
|
inline climate::ClimatePreset FiniteSetMask<climate::ClimatePreset, climate::CLIMATE_PRESET_BITMASK_SIZE>::bit_to_value(
|
||||||
int bit) {
|
int bit) {
|
||||||
static constexpr climate::ClimatePreset PRESETS[] = {
|
static constexpr climate::ClimatePreset PRESETS[] = {
|
||||||
climate::CLIMATE_PRESET_NONE, // bit 0
|
climate::CLIMATE_PRESET_NONE, // bit 0
|
||||||
@@ -119,10 +119,10 @@ namespace esphome::climate {
|
|||||||
|
|
||||||
// Type aliases for climate enum bitmasks
|
// Type aliases for climate enum bitmasks
|
||||||
// These replace std::set<EnumType> to eliminate red-black tree overhead
|
// These replace std::set<EnumType> to eliminate red-black tree overhead
|
||||||
using ClimateModeMask = EnumBitmask<ClimateMode, CLIMATE_MODE_BITMASK_SIZE>;
|
using ClimateModeMask = FiniteSetMask<ClimateMode, CLIMATE_MODE_BITMASK_SIZE>;
|
||||||
using ClimateFanModeMask = EnumBitmask<ClimateFanMode, CLIMATE_FAN_MODE_BITMASK_SIZE>;
|
using ClimateFanModeMask = FiniteSetMask<ClimateFanMode, CLIMATE_FAN_MODE_BITMASK_SIZE>;
|
||||||
using ClimateSwingModeMask = EnumBitmask<ClimateSwingMode, CLIMATE_SWING_MODE_BITMASK_SIZE>;
|
using ClimateSwingModeMask = FiniteSetMask<ClimateSwingMode, CLIMATE_SWING_MODE_BITMASK_SIZE>;
|
||||||
using ClimatePresetMask = EnumBitmask<ClimatePreset, CLIMATE_PRESET_BITMASK_SIZE>;
|
using ClimatePresetMask = FiniteSetMask<ClimatePreset, CLIMATE_PRESET_BITMASK_SIZE>;
|
||||||
|
|
||||||
// Lightweight linear search for small vectors (1-20 items)
|
// Lightweight linear search for small vectors (1-20 items)
|
||||||
// Avoids std::find template overhead
|
// Avoids std::find template overhead
|
||||||
|
|||||||
Reference in New Issue
Block a user