initial commit.

This commit is contained in:
Your Name
2023-02-11 21:10:30 +01:00
parent cbb9131ec8
commit ced79a4af9
63 changed files with 6470 additions and 2 deletions

View File

@@ -0,0 +1,105 @@
#include "TrumaRoomClimate.h"
#include "esphome/components/truma_inetbox/helpers.h"
namespace esphome {
namespace truma_inetbox {
static const char *const TAG = "truma_inetbox.truma_room_climate";
void TrumaRoomClimate::setup() {
this->parent_->register_listener([this](const StatusFrameHeater *status_heater) {
// Publish updated state
this->target_temperature = temp_code_to_decimal(status_heater->target_temp_room);
this->current_temperature = temp_code_to_decimal(status_heater->current_temp_room);
this->mode = (status_heater->operating_status >= OperatingStatus::OPERATING_STATUS_START_OR_COOL_DOWN)
? climate::CLIMATE_MODE_HEAT
: climate::CLIMATE_MODE_OFF;
switch (status_heater->heating_mode) {
case HeatingMode::HEATING_MODE_ECO:
this->preset = climate::CLIMATE_PRESET_ECO;
break;
case HeatingMode::HEATING_MODE_HIGH:
this->preset = climate::CLIMATE_PRESET_COMFORT;
break;
case HeatingMode::HEATING_MODE_BOOST:
this->preset = climate::CLIMATE_PRESET_BOOST;
break;
default:
this->preset = climate::CLIMATE_PRESET_NONE;
break;
}
this->publish_state();
});
}
void TrumaRoomClimate::dump_config() { ESP_LOGCONFIG(TAG, "Truma Room Climate"); }
void TrumaRoomClimate::control(const climate::ClimateCall &call) {
if (call.get_target_temperature().has_value()) {
float temp = *call.get_target_temperature();
this->parent_->action_heater_room(static_cast<u_int8_t>(temp));
}
if (call.get_mode().has_value()) {
// User requested mode change
climate::ClimateMode mode = *call.get_mode();
auto status_heater = this->parent_->get_status_heater();
switch (mode) {
case climate::CLIMATE_MODE_HEAT:
if (status_heater->target_temp_room == TargetTemp::TARGET_TEMP_OFF) {
this->parent_->action_heater_room(5);
}
break;
default:
this->parent_->action_heater_room(0);
break;
}
}
if (call.get_preset().has_value()) {
climate::ClimatePreset pres = *call.get_preset();
auto status_heater = this->parent_->get_status_heater();
auto current_target_temp = temp_code_to_decimal(status_heater->target_temp_room);
if (call.get_target_temperature().has_value()) {
current_target_temp = *call.get_target_temperature();
}
switch (pres) {
case climate::CLIMATE_PRESET_ECO:
this->parent_->action_heater_room(current_target_temp, HeatingMode::HEATING_MODE_ECO);
break;
case climate::CLIMATE_PRESET_COMFORT:
this->parent_->action_heater_room(current_target_temp, HeatingMode::HEATING_MODE_HIGH);
break;
case climate::CLIMATE_PRESET_BOOST:
this->parent_->action_heater_room(current_target_temp, HeatingMode::HEATING_MODE_BOOST);
break;
default:
this->parent_->action_heater_room(0);
break;
}
}
}
climate::ClimateTraits TrumaRoomClimate::traits() {
// The capabilities of the climate device
auto traits = climate::ClimateTraits();
traits.set_supports_current_temperature(true);
traits.set_supported_modes({climate::CLIMATE_MODE_OFF, climate::CLIMATE_MODE_HEAT});
// traits.set_supported_fan_modes({{
// climate::CLIMATE_FAN_LOW,
// climate::CLIMATE_FAN_MEDIUM,
// climate::CLIMATE_FAN_HIGH,
// }});
traits.set_supported_presets({{
climate::CLIMATE_PRESET_NONE,
climate::CLIMATE_PRESET_ECO,
climate::CLIMATE_PRESET_COMFORT,
climate::CLIMATE_PRESET_BOOST,
}});
traits.set_visual_min_temperature(5);
traits.set_visual_max_temperature(30);
traits.set_visual_temperature_step(1);
return traits;
}
} // namespace truma_inetbox
} // namespace esphome

View File

@@ -0,0 +1,22 @@
#pragma once
#include "esphome/components/climate/climate.h"
#include "esphome/components/truma_inetbox/TrumaiNetBoxApp.h"
namespace esphome {
namespace truma_inetbox {
class TrumaRoomClimate : public Component, public climate::Climate, public Parented<TrumaiNetBoxApp> {
public:
void setup() override;
void dump_config() override;
void control(const climate::ClimateCall &call) override;
climate::ClimateTraits traits() override;
protected:
private:
};
} // namespace truma_inetbox
} // namespace esphome

View File

@@ -0,0 +1,54 @@
#include "TrumaWaterClimate.h"
#include "esphome/components/truma_inetbox/helpers.h"
namespace esphome {
namespace truma_inetbox {
static const char *const TAG = "truma_inetbox.truma_water_climate";
void TrumaWaterClimate::setup() {
this->parent_->register_listener([this](const StatusFrameHeater *status_heater) {
// Publish updated state
this->target_temperature = temp_code_to_decimal(status_heater->target_temp_water);
this->current_temperature = temp_code_to_decimal(status_heater->current_temp_water);
this->mode = (status_heater->target_temp_water == TargetTemp::TARGET_TEMP_OFF) ? climate::CLIMATE_MODE_OFF
: climate::CLIMATE_MODE_HEAT;
this->publish_state();
});
}
void TrumaWaterClimate::dump_config() { ESP_LOGCONFIG(TAG, "Truma Climate"); }
void TrumaWaterClimate::control(const climate::ClimateCall &call) {
if (call.get_target_temperature().has_value()) {
float temp = *call.get_target_temperature();
this->parent_->action_heater_water(static_cast<u_int8_t>(temp));
}
if (call.get_mode().has_value()) {
climate::ClimateMode mode = *call.get_mode();
auto status_heater = this->parent_->get_status_heater();
switch (mode) {
case climate::CLIMATE_MODE_HEAT:
if (status_heater->target_temp_water == TargetTemp::TARGET_TEMP_OFF) {
this->parent_->action_heater_water(40);
}
break;
default:
this->parent_->action_heater_water(0);
break;
}
}
}
climate::ClimateTraits TrumaWaterClimate::traits() {
// The capabilities of the climate device
auto traits = climate::ClimateTraits();
traits.set_supports_current_temperature(true);
traits.set_supported_modes({climate::CLIMATE_MODE_OFF, climate::CLIMATE_MODE_HEAT});
traits.set_visual_min_temperature(40);
traits.set_visual_max_temperature(80);
traits.set_visual_temperature_step(20);
return traits;
}
} // namespace truma_inetbox
} // namespace esphome

View File

@@ -0,0 +1,22 @@
#pragma once
#include "esphome/components/climate/climate.h"
#include "esphome/components/truma_inetbox/TrumaiNetBoxApp.h"
namespace esphome {
namespace truma_inetbox {
class TrumaWaterClimate : public Component, public climate::Climate, public Parented<TrumaiNetBoxApp> {
public:
void setup() override;
void dump_config() override;
void control(const climate::ClimateCall &call) override;
climate::ClimateTraits traits() override;
protected:
private:
};
} // namespace truma_inetbox
} // namespace esphome

View File

@@ -0,0 +1,45 @@
from esphome.components import climate
import esphome.config_validation as cv
import esphome.codegen as cg
from esphome.const import (
CONF_ID,
CONF_TYPE,
)
from .. import truma_inetbox_ns, CONF_TRUMA_INETBOX_ID, TrumaINetBoxApp
DEPENDENCIES = ["truma_inetbox"]
CODEOWNERS = ["@Fabian-Schmidt"]
TrumaClimate = truma_inetbox_ns.class_(
"TrumaClimate", climate.Climate, cg.Component)
CONF_SUPPORTED_TYPE = {
"ROOM": truma_inetbox_ns.class_("TrumaRoomClimate", climate.Climate, cg.Component),
"WATER": truma_inetbox_ns.class_("TrumaWaterClimate", climate.Climate, cg.Component),
}
def set_default_based_on_type():
def set_defaults_(config):
# update the class
config[CONF_ID].type = CONF_SUPPORTED_TYPE[config[CONF_TYPE]]
return config
return set_defaults_
CONFIG_SCHEMA = climate.CLIMATE_SCHEMA.extend(
{
cv.GenerateID(): cv.declare_id(TrumaClimate),
cv.GenerateID(CONF_TRUMA_INETBOX_ID): cv.use_id(TrumaINetBoxApp),
cv.Required(CONF_TYPE): cv.enum(CONF_SUPPORTED_TYPE, upper=True),
}
).extend(cv.COMPONENT_SCHEMA)
FINAL_VALIDATE_SCHEMA = set_default_based_on_type()
async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
await cg.register_component(var, config)
await climate.register_climate(var, config)
await cg.register_parented(var, config[CONF_TRUMA_INETBOX_ID])