jiecang_desk_controller: update height sensor only when height changed and removed unused unit sensor
This commit is contained in:
@@ -54,18 +54,16 @@ namespace esphome {
|
|||||||
switch (message[0]) {
|
switch (message[0]) {
|
||||||
case 0x01:
|
case 0x01:
|
||||||
ESP_LOGV("jiecang_desk_controller", "height 0x%0X%0X", message[2], message[3]);
|
ESP_LOGV("jiecang_desk_controller", "height 0x%0X%0X", message[2], message[3]);
|
||||||
current_height = byte2float(message[2], message[3]);
|
float new_height;
|
||||||
|
new_height = byte2float(message[2], message[3]);
|
||||||
|
if (new_height == current_height) return;
|
||||||
|
current_height = new_height;
|
||||||
if (height != nullptr) height->publish_state(current_height);
|
if (height != nullptr) height->publish_state(current_height);
|
||||||
|
|
||||||
if (height_pct != nullptr && limit_max != 0)
|
if (height_pct != nullptr && limit_max != 0)
|
||||||
height_pct->publish_state((current_height - limit_min) / (limit_max - limit_min) * 100);
|
height_pct->publish_state((current_height - limit_min) / (limit_max - limit_min) * 100);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x0e:
|
|
||||||
ESP_LOGV("jiecang_desk_controller", "unit 0x%0X", message[2]);
|
|
||||||
if (unit != nullptr) unit->publish_state(message[2]);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 0x20:
|
case 0x20:
|
||||||
ESP_LOGV("jiecang_desk_controller", "limits 0x%0X max %i min %i", message[2], (message[2] & 1), (message[2]>>4));
|
ESP_LOGV("jiecang_desk_controller", "limits 0x%0X max %i min %i", message[2], (message[2] & 1), (message[2]>>4));
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ namespace esphome {
|
|||||||
void update() override;
|
void update() override;
|
||||||
|
|
||||||
void set_sensor_height(sensor::Sensor *sensor) { this->height = sensor; }
|
void set_sensor_height(sensor::Sensor *sensor) { this->height = sensor; }
|
||||||
void set_sensor_unit(sensor::Sensor *sensor) { this->unit = sensor; }
|
|
||||||
void set_sensor_height_min(sensor::Sensor *sensor) { this->height_min = sensor; }
|
void set_sensor_height_min(sensor::Sensor *sensor) { this->height_min = sensor; }
|
||||||
void set_sensor_height_max(sensor::Sensor *sensor) { this->height_max = sensor; }
|
void set_sensor_height_max(sensor::Sensor *sensor) { this->height_max = sensor; }
|
||||||
void set_sensor_height_pct(sensor::Sensor *sensor) { this->height_pct = sensor; }
|
void set_sensor_height_pct(sensor::Sensor *sensor) { this->height_pct = sensor; }
|
||||||
@@ -57,7 +56,6 @@ namespace esphome {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
Sensor *height{nullptr};
|
Sensor *height{nullptr};
|
||||||
Sensor *unit{nullptr};
|
|
||||||
Sensor *height_min{nullptr};
|
Sensor *height_min{nullptr};
|
||||||
Sensor *height_max{nullptr};
|
Sensor *height_max{nullptr};
|
||||||
Sensor *height_pct{nullptr};
|
Sensor *height_pct{nullptr};
|
||||||
|
|||||||
Reference in New Issue
Block a user