mirror of
https://github.com/esphome/esphome.git
synced 2025-10-29 22:24:26 +00:00
reduce
This commit is contained in:
@@ -7,6 +7,7 @@ namespace esphome {
|
||||
namespace climate {
|
||||
|
||||
/// Enum for all modes a climate device can be in.
|
||||
/// NOTE: If adding values, update ClimateModeMask in climate_traits.h to use the new last value
|
||||
enum ClimateMode : uint8_t {
|
||||
/// The climate device is off
|
||||
CLIMATE_MODE_OFF = 0,
|
||||
@@ -24,7 +25,7 @@ enum ClimateMode : uint8_t {
|
||||
* For example, the target temperature can be adjusted based on a schedule, or learned behavior.
|
||||
* The target temperature can't be adjusted when in this mode.
|
||||
*/
|
||||
CLIMATE_MODE_AUTO = 6
|
||||
CLIMATE_MODE_AUTO = 6 // Update ClimateModeMask in climate_traits.h if adding values after this
|
||||
};
|
||||
|
||||
/// Enum for the current action of the climate device. Values match those of ClimateMode.
|
||||
@@ -43,6 +44,7 @@ enum ClimateAction : uint8_t {
|
||||
CLIMATE_ACTION_FAN = 6,
|
||||
};
|
||||
|
||||
/// NOTE: If adding values, update ClimateFanModeMask in climate_traits.h to use the new last value
|
||||
enum ClimateFanMode : uint8_t {
|
||||
/// The fan mode is set to On
|
||||
CLIMATE_FAN_ON = 0,
|
||||
@@ -63,10 +65,11 @@ enum ClimateFanMode : uint8_t {
|
||||
/// The fan mode is set to Diffuse
|
||||
CLIMATE_FAN_DIFFUSE = 8,
|
||||
/// The fan mode is set to Quiet
|
||||
CLIMATE_FAN_QUIET = 9,
|
||||
CLIMATE_FAN_QUIET = 9, // Update ClimateFanModeMask in climate_traits.h if adding values after this
|
||||
};
|
||||
|
||||
/// Enum for all modes a climate swing can be in
|
||||
/// NOTE: If adding values, update ClimateSwingModeMask in climate_traits.h to use the new last value
|
||||
enum ClimateSwingMode : uint8_t {
|
||||
/// The swing mode is set to Off
|
||||
CLIMATE_SWING_OFF = 0,
|
||||
@@ -75,10 +78,11 @@ enum ClimateSwingMode : uint8_t {
|
||||
/// The fan mode is set to Vertical
|
||||
CLIMATE_SWING_VERTICAL = 2,
|
||||
/// The fan mode is set to Horizontal
|
||||
CLIMATE_SWING_HORIZONTAL = 3,
|
||||
CLIMATE_SWING_HORIZONTAL = 3, // Update ClimateSwingModeMask in climate_traits.h if adding values after this
|
||||
};
|
||||
|
||||
/// Enum for all preset modes
|
||||
/// NOTE: If adding values, update ClimatePresetMask in climate_traits.h to use the new last value
|
||||
enum ClimatePreset : uint8_t {
|
||||
/// No preset is active
|
||||
CLIMATE_PRESET_NONE = 0,
|
||||
@@ -95,7 +99,7 @@ enum ClimatePreset : uint8_t {
|
||||
/// Device is prepared for sleep
|
||||
CLIMATE_PRESET_SLEEP = 6,
|
||||
/// Device is reacting to activity (e.g., movement sensors)
|
||||
CLIMATE_PRESET_ACTIVITY = 7,
|
||||
CLIMATE_PRESET_ACTIVITY = 7, // Update ClimatePresetMask in climate_traits.h if adding values after this
|
||||
};
|
||||
|
||||
enum ClimateFeature : uint32_t {
|
||||
|
||||
@@ -15,22 +15,13 @@ class APIConnection;
|
||||
|
||||
namespace climate {
|
||||
|
||||
// Bitmask sizes for climate enums
|
||||
constexpr int CLIMATE_MODE_BITMASK_SIZE = 8; // 7 values (OFF, HEAT_COOL, COOL, HEAT, FAN_ONLY, DRY, AUTO)
|
||||
constexpr int CLIMATE_FAN_MODE_BITMASK_SIZE =
|
||||
16; // 10 values (ON, OFF, AUTO, LOW, MEDIUM, HIGH, MIDDLE, FOCUS, DIFFUSE, QUIET)
|
||||
constexpr int CLIMATE_SWING_MODE_BITMASK_SIZE = 8; // 4 values (OFF, BOTH, VERTICAL, HORIZONTAL)
|
||||
constexpr int CLIMATE_PRESET_BITMASK_SIZE = 8; // 8 values (NONE, HOME, AWAY, BOOST, COMFORT, ECO, SLEEP, ACTIVITY)
|
||||
|
||||
// No template specializations needed - all climate enums use 1:1 mapping (enum value = bit position)
|
||||
// FiniteSetMask's default implementations handle this automatically.
|
||||
|
||||
// Type aliases for climate enum bitmasks
|
||||
// These replace std::set<EnumType> to eliminate red-black tree overhead
|
||||
using ClimateModeMask = FiniteSetMask<ClimateMode, CLIMATE_MODE_BITMASK_SIZE>;
|
||||
using ClimateFanModeMask = FiniteSetMask<ClimateFanMode, CLIMATE_FAN_MODE_BITMASK_SIZE>;
|
||||
using ClimateSwingModeMask = FiniteSetMask<ClimateSwingMode, CLIMATE_SWING_MODE_BITMASK_SIZE>;
|
||||
using ClimatePresetMask = FiniteSetMask<ClimatePreset, CLIMATE_PRESET_BITMASK_SIZE>;
|
||||
// For contiguous enums starting at 0, bitmask size is automatically calculated from the last enum value
|
||||
using ClimateModeMask = FiniteSetMask<ClimateMode, CLIMATE_MODE_AUTO + 1>;
|
||||
using ClimateFanModeMask = FiniteSetMask<ClimateFanMode, CLIMATE_FAN_QUIET + 1>;
|
||||
using ClimateSwingModeMask = FiniteSetMask<ClimateSwingMode, CLIMATE_SWING_HORIZONTAL + 1>;
|
||||
using ClimatePresetMask = FiniteSetMask<ClimatePreset, CLIMATE_PRESET_ACTIVITY + 1>;
|
||||
|
||||
// Lightweight linear search for small vectors (1-20 items)
|
||||
// Avoids std::find template overhead
|
||||
|
||||
Reference in New Issue
Block a user