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