Skip to content

Commit

Permalink
#4 o2 switch state dump to verbose, use state for antifreeze
Browse files Browse the repository at this point in the history
  • Loading branch information
dentra committed Jan 29, 2024
1 parent 70d9df9 commit ab83965
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
5 changes: 3 additions & 2 deletions components/tion-api/tion-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ template<tion_dev_info_t::device_type_t DT> struct tion_state_counters_t {
// Airflow counter, m3=airflow_counter * 15.0 / 3600.0.
uint32_t airflow_counter;
// Calculated airflow in m3.
float airflow() const { return airflow_counter * (float(airflow_k()) / 3600.0f); }
float airflow() const { return this->airflow_counter * (float(this->airflow_k()) / 3600.0f); }
// Calculated filter days left
uint32_t filter_time_left() const { return filter_time / (24 * 3600); }
uint32_t filter_time_left() const { return this->filter_time / (24 * 3600); }
uint32_t work_time_days() const { return this->work_time / (24 * 3600); }

constexpr size_t airflow_k() const {
if constexpr (DT == tion_dev_info_t::device_type_t::BRLT) {
Expand Down
31 changes: 14 additions & 17 deletions components/tion_o2/climate/tion_o2_climate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ void TionO2Climate::update_state(const tiono2_state_t &state) {
this->target_temperature = state.target_temperature;
this->set_fan_speed_(state.fan_speed);
this->publish_state();

#ifdef USE_TION_PRODUCTIVITY
if (this->productivity_) {
this->productivity_->publish_state(state.productivity);
}
#endif
}

static char bits_str_buf[9]{};
Expand All @@ -65,19 +66,18 @@ const char *bits_str(uint8_t v) {

void TionO2Climate::dump_state(const tiono2_state_t &state) const {
ESP_LOGD(TAG, "flags : %s", bits_str(*reinterpret_cast<const uint8_t *>(&state.flags)));
ESP_LOGD(TAG, "outdoor_temp: %d", state.outdoor_temperature);
ESP_LOGD(TAG, "current_temp: %d", state.current_temperature);
ESP_LOGD(TAG, "target_temp : %d", state.current_temperature);
ESP_LOGD(TAG, "fan_speed : %d", state.fan_speed);
ESP_LOGD(TAG, "productivity: %d", state.productivity);
ESP_LOGV(TAG, "flags.power : %s", ONOFF(state.flags.power_state));
ESP_LOGV(TAG, "flags.heat : %s", ONOFF(state.flags.heater_state));
ESP_LOGV(TAG, "outdoor_temp: %d", state.outdoor_temperature);
ESP_LOGV(TAG, "current_temp: %d", state.current_temperature);
ESP_LOGV(TAG, "target_temp : %d", state.current_temperature);
ESP_LOGV(TAG, "fan_speed : %d", state.fan_speed);
ESP_LOGV(TAG, "productivity: %d", state.productivity);
DUMP_UNK(unknown7);
DUMP_UNK(unknown8);
DUMP_UNK(unknown9);
ESP_LOGD(TAG, "work_time : %" PRIu32, state.counters.work_time_days());
DUMP_UNK(unknown14);
DUMP_UNK(unknown15);
DUMP_UNK(unknown16);
DUMP_UNK(unknown17);
ESP_LOGV(TAG, "work_time : %" PRIu32, state.counters.work_time_days());
ESP_LOGV(TAG, "filter_time : %" PRIu32, state.counters.filter_time_left());
}

void TionO2Climate::control_climate_state(climate::ClimateMode mode, uint8_t fan_speed, float target_temperature,
Expand Down Expand Up @@ -132,12 +132,9 @@ void TionO2Climate::control_state_(const ControlState &state) {
}

#ifdef TION_ENABLE_ANTIFRIZE
if (st.flags.power_state && !st.flags.heater_state && this->outdoor_temperature_) {
auto outdoor_temperature = this->outdoor_temperature_->state;
if (!std::isnan(outdoor_temperature) && outdoor_temperature < 0.001) {
ESP_LOGW(TAG, "Antifrize protection has worked. Heater now enabled.");
st.flags.heater_state = true;
}
if (st.flags.power_state && !st.flags.heater_state && st.outdoor_temperature < 0) {
ESP_LOGW(TAG, "Antifrize protection has worked. Heater now enabled.");
st.flags.heater_state = true;
}
#endif

Expand Down
5 changes: 5 additions & 0 deletions tion.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ climate:
#airflow_counter:
# name: "Airflow counter"
{%- endif %}
{%- if type != "3s" %}
# Optional, Total work time counter, seconds.
#work_time:
# name: "Work Time"
{%- endif %}
{%- if type == "3s" %}
# Optional, Air Intake control.
air_intake:
Expand Down

0 comments on commit ab83965

Please sign in to comment.