mirror of
https://github.com/esphome/esphome.git
synced 2026-08-24 15:16:20 +00:00
[api][climate][water_heater][core] Add temperature unit support to climate and water heater c++ entities (#16477)
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
f0800336b8
commit
a210c27d14
@@ -794,6 +794,7 @@ uint16_t APIConnection::try_send_climate_info(EntityBase *entity, APIConnection
|
||||
msg.supports_action = traits.has_feature_flags(climate::CLIMATE_SUPPORTS_ACTION);
|
||||
// Current feature flags and other supported parameters
|
||||
msg.feature_flags = traits.get_feature_flags();
|
||||
msg.temperature_unit = static_cast<enums::TemperatureUnit>(traits.get_temperature_unit());
|
||||
msg.supported_modes = &traits.get_supported_modes();
|
||||
msg.visual_min_temperature = traits.get_visual_min_temperature();
|
||||
msg.visual_max_temperature = traits.get_visual_max_temperature();
|
||||
@@ -1468,6 +1469,7 @@ uint16_t APIConnection::try_send_water_heater_info(EntityBase *entity, APIConnec
|
||||
msg.target_temperature_step = traits.get_target_temperature_step();
|
||||
msg.supported_modes = &traits.get_supported_modes();
|
||||
msg.supported_features = traits.get_feature_flags();
|
||||
msg.temperature_unit = static_cast<enums::TemperatureUnit>(traits.get_temperature_unit());
|
||||
return fill_and_encode_entity_info(wh, msg, conn, remaining_size);
|
||||
}
|
||||
|
||||
|
||||
@@ -274,7 +274,7 @@ def climate_schema(
|
||||
|
||||
@setup_entity("climate")
|
||||
async def setup_climate_core_(var, config):
|
||||
visual = config[CONF_VISUAL]
|
||||
visual = config.get(CONF_VISUAL, {})
|
||||
if (min_temp := visual.get(CONF_MIN_TEMPERATURE)) is not None:
|
||||
cg.add_define("USE_CLIMATE_VISUAL_OVERRIDES")
|
||||
cg.add(var.set_visual_min_temperature_override(min_temp))
|
||||
|
||||
@@ -205,6 +205,9 @@ class ClimateTraits {
|
||||
float get_visual_max_humidity() const { return this->visual_max_humidity_; }
|
||||
void set_visual_max_humidity(float visual_max_humidity) { this->visual_max_humidity_ = visual_max_humidity; }
|
||||
|
||||
TemperatureUnit get_temperature_unit() const { return this->temperature_unit_; }
|
||||
void set_temperature_unit(TemperatureUnit unit) { this->temperature_unit_ = unit; }
|
||||
|
||||
protected:
|
||||
void set_mode_support_(climate::ClimateMode mode, bool supported) {
|
||||
if (supported) {
|
||||
@@ -274,6 +277,7 @@ class ClimateTraits {
|
||||
climate::ClimateFanModeMask supported_fan_modes_;
|
||||
climate::ClimateSwingModeMask supported_swing_modes_;
|
||||
climate::ClimatePresetMask supported_presets_;
|
||||
TemperatureUnit temperature_unit_{TemperatureUnit::CELSIUS};
|
||||
|
||||
/** Custom mode storage - pointers to vectors owned by the Climate base class.
|
||||
*
|
||||
|
||||
@@ -76,7 +76,7 @@ def water_heater_schema(
|
||||
@setup_entity("water_heater")
|
||||
async def setup_water_heater_core_(var: cg.Pvariable, config: ConfigType) -> None:
|
||||
"""Set up the core water heater properties in C++."""
|
||||
visual = config[CONF_VISUAL]
|
||||
visual = config.get(CONF_VISUAL, {})
|
||||
if (min_temp := visual.get(CONF_MIN_TEMPERATURE)) is not None:
|
||||
cg.add_define("USE_WATER_HEATER_VISUAL_OVERRIDES")
|
||||
cg.add(var.set_visual_min_temperature_override(min_temp))
|
||||
|
||||
@@ -183,6 +183,9 @@ class WaterHeaterTraits {
|
||||
const WaterHeaterModeMask &get_supported_modes() const { return this->supported_modes_; }
|
||||
bool supports_mode(WaterHeaterMode mode) const { return this->supported_modes_.count(mode); }
|
||||
|
||||
TemperatureUnit get_temperature_unit() const { return this->temperature_unit_; }
|
||||
void set_temperature_unit(TemperatureUnit unit) { this->temperature_unit_ = unit; }
|
||||
|
||||
protected:
|
||||
// Ordered to minimize padding: 4-byte members first
|
||||
uint32_t feature_flags_{0};
|
||||
@@ -190,6 +193,7 @@ class WaterHeaterTraits {
|
||||
float max_temperature_{0.0f};
|
||||
float target_temperature_step_{0.0f};
|
||||
WaterHeaterModeMask supported_modes_;
|
||||
TemperatureUnit temperature_unit_{TemperatureUnit::CELSIUS};
|
||||
};
|
||||
|
||||
class WaterHeater : public EntityBase {
|
||||
|
||||
@@ -1625,6 +1625,12 @@ constexpr float celsius_to_fahrenheit(float value) { return value * 1.8f + 32.0f
|
||||
/// Convert degrees Fahrenheit to degrees Celsius.
|
||||
constexpr float fahrenheit_to_celsius(float value) { return (value - 32.0f) / 1.8f; }
|
||||
|
||||
enum class TemperatureUnit : uint8_t {
|
||||
CELSIUS = 0,
|
||||
FAHRENHEIT = 1,
|
||||
KELVIN = 2,
|
||||
};
|
||||
|
||||
///@}
|
||||
|
||||
/// @name Utilities
|
||||
|
||||
Reference in New Issue
Block a user