Fix off-by-one bedjet fan speed (#3873) (#4292)

fixes https://github.com/esphome/issues/issues/3873
This commit is contained in:
Joe 2023-01-15 19:27:34 -05:00 committed by GitHub
parent ed4a7210d3
commit a9b7d98194
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -37,9 +37,13 @@ void BedJetFan::control(const fan::FanCall &call) {
// ignore speed changes if not on or turning on // ignore speed changes if not on or turning on
if (this->state && call.get_speed().has_value()) { if (this->state && call.get_speed().has_value()) {
this->speed = *call.get_speed(); auto speed = *call.get_speed();
this->parent_->set_fan_index(this->speed); if (speed >= 1) {
did_change = true; this->speed = speed;
// Fan.speed is 1-20, but Bedjet expects 0-19, so subtract 1
this->parent_->set_fan_index(this->speed - 1);
did_change = true;
}
} }
if (did_change) { if (did_change) {
@ -57,8 +61,9 @@ void BedJetFan::on_status(const BedjetStatusPacket *data) {
did_change = true; did_change = true;
} }
if (data->fan_step != this->speed) { // BedjetStatusPacket.fan_step is in range 0-19, but Fan.speed wants 1-20.
this->speed = data->fan_step; if (data->fan_step + 1 != this->speed) {
this->speed = data->fan_step + 1;
did_change = true; did_change = true;
} }