2023-02-24 17:42:16 +01:00

46 lines
1.7 KiB
C++

#include "TrumaSensor.h"
#include "esphome/core/log.h"
#include "esphome/components/truma_inetbox/helpers.h"
namespace esphome {
namespace truma_inetbox {
static const char *const TAG = "truma_inetbox.sensor";
void TrumaSensor::setup() {
this->parent_->register_listener([this](const StatusFrameHeater *status_heater) {
switch (this->type_) {
case TRUMA_SENSOR_TYPE::CURRENT_ROOM_TEMPERATURE:
this->publish_state(temp_code_to_decimal(status_heater->current_temp_room));
break;
case TRUMA_SENSOR_TYPE::CURRENT_WATER_TEMPERATURE:
this->publish_state(temp_code_to_decimal(status_heater->current_temp_water));
break;
case TRUMA_SENSOR_TYPE::TARGET_ROOM_TEMPERATURE:
this->publish_state(temp_code_to_decimal(status_heater->target_temp_room));
break;
case TRUMA_SENSOR_TYPE::TARGET_WATER_TEMPERATURE:
this->publish_state(temp_code_to_decimal(status_heater->target_temp_water));
break;
case TRUMA_SENSOR_TYPE::HEATING_MODE:
this->publish_state(static_cast<float>(status_heater->heating_mode));
break;
case TRUMA_SENSOR_TYPE::ELECTRIC_POWER_LEVEL:
this->publish_state(static_cast<float>(status_heater->el_power_level_a));
break;
case TRUMA_SENSOR_TYPE::ENERGY_MIX:
this->publish_state(static_cast<float>(status_heater->energy_mix_a));
break;
case TRUMA_SENSOR_TYPE::OPERATING_STATUS:
this->publish_state(static_cast<float>(status_heater->operating_status));
break;
}
});
}
void TrumaSensor::dump_config() {
LOG_SENSOR("", "Truma Sensor", this);
ESP_LOGCONFIG(TAG, "Type %u", (size_t) this->type_);
}
} // namespace truma_inetbox
} // namespace esphome