Skip to content

Commit

Permalink
Suppressed big data requests if there are no sensors that require tha…
Browse files Browse the repository at this point in the history
…t information
  • Loading branch information
paveldn committed Dec 25, 2023
1 parent 15a4586 commit c4fd5cd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
25 changes: 20 additions & 5 deletions components/haier/hon_climate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -689,8 +689,15 @@ void HonClimate::process_alarm_message_(const uint8_t *packet, uint8_t size, boo

#ifdef USE_SENSOR
void HonClimate::set_sub_sensor(SubSensorType type, sensor::Sensor *sens) {
if (type < SubSensorType::__SUB_SENSOR_TYPE_COUNT)
if (type < SubSensorType::__SUB_SENSOR_TYPE_COUNT) {
if (type >= SubSensorType::__BIG_DATA_FRAME_SUB_SENSORS) {
if ((this->sub_sensors_[(size_t)type] != nullptr) && (sens == nullptr))
this->big_data_sensors_--;
else if ((this->sub_sensors_[(size_t)type] == nullptr) && (sens != nullptr))
this->big_data_sensors_++;
}
this->sub_sensors_[(size_t)type] = sens;
}
}

void HonClimate::update_sub_sensor(SubSensorType type, float value) {
Expand All @@ -704,8 +711,13 @@ void HonClimate::update_sub_sensor(SubSensorType type, float value) {

#ifdef USE_BINARY_SENSOR
void HonClimate::set_sub_binary_sensor(SubBinarySensorType type, binary_sensor::BinarySensor *sens) {
if (type < SubBinarySensorType::__SUB_BINARY_SENSOR_TYPE_COUNT)
if (type < SubBinarySensorType::__SUB_BINARY_SENSOR_TYPE_COUNT) {
if ((this->sub_binary_sensors_[(size_t)type] != nullptr) && (sens == nullptr))
this->big_data_sensors_--;
else if ((this->sub_binary_sensors_[(size_t)type] == nullptr) && (sens != nullptr))
this->big_data_sensors_++;
this->sub_binary_sensors_[(size_t)type] = sens;
}
}

void HonClimate::update_sub_binary_sensor(SubBinarySensorType type, uint8_t value) {
Expand Down Expand Up @@ -1189,9 +1201,12 @@ void HonClimate::process_protocol_reset() {
}

bool HonClimate::should_get_big_data_() {
static uint8_t _counter = 0;
_counter = (_counter + 1) % 3;
return _counter == 1;
if (this->big_data_sensors_ > 0) {
static uint8_t _counter = 0;
_counter = (_counter + 1) % 3;
return _counter == 1;
}
return false;
}

} // namespace haier
Expand Down
8 changes: 6 additions & 2 deletions components/haier/hon_climate.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ class HonClimate : public HaierClimateBase {
#ifdef USE_SENSOR
public:
enum class SubSensorType {
INDOOR_COIL_TEMPERATURE = 0,
// Used data based sensors
OUTDOOR_TEMPERATURE = 0,
// Big data based sensors
INDOOR_COIL_TEMPERATURE,
OUTDOOR_COIL_TEMPERATURE,
OUTDOOR_DEFROST_TEMPERATURE,
OUTDOOR_IN_AIR_TEMPERATURE,
Expand All @@ -51,8 +54,8 @@ class HonClimate : public HaierClimateBase {
COMPRESSOR_FREQUENCY,
COMPRESSOR_CURRENT,
EXPANSION_VALVE_OPEN_DEGREE,
OUTDOOR_TEMPERATURE,
__SUB_SENSOR_TYPE_COUNT,
__BIG_DATA_FRAME_SUB_SENSORS = INDOOR_COIL_TEMPERATURE,
};
void set_sub_sensor(SubSensorType type, sensor::Sensor *sens);
protected:
Expand Down Expand Up @@ -152,6 +155,7 @@ class HonClimate : public HaierClimateBase {
CallbackManager<void(uint8_t, const char *)> alarm_end_callback_{};
float active_alarm_count_{NAN};
std::chrono::steady_clock::time_point last_alarm_request_;
int big_data_sensors_{0};
};

class HaierAlarmStartTrigger : public Trigger<uint8_t, const char *> {
Expand Down

0 comments on commit c4fd5cd

Please sign in to comment.