hillaliy / homebridge-midea-air

Homebridge plugin for Midea units
MIT License
72 stars 23 forks source link

Missing RotationSpeed in Dehumidifier Accesory #18

Closed CyberMrProper closed 3 years ago

CyberMrProper commented 3 years ago

I have a Midea dehumidifier, and it has a fan speed to be controlled, I'm attaching some code to ease the implementation:

This line: https://github.com/hillaliy/homebridge-midea-air/blob/7e5556b34aed9385578261a11073b0164e6f0371/src/MideaAccessory.ts#L237 Should be replaced by:

this.service.getCharacteristic(this.platform.Characteristic.RotationSpeed)
                        .on('get', this.handleDehumidifierRotationSpeedGet.bind(this))
                        .on('set', this.handleDehumidifierRotationSpeedSet.bind(this))
                        .setProps({
                            minStep: 20,
                            minValue: 20,
                            maxValue: 80,
                            validValues: [20, 40, 60, 80]
                        });;

And the handlers are:


    /**
    * Handle requests to get the current value of the "RotationSpeed" characteristic
    */
    handleDehumidifierRotationSpeedGet(callback) {
        this.platform.log.debug('Triggered GET RotationSpeed');
        // values from device are 20.0="Homekit off", 40.0="Silent",60.0="Medium",80.0="High"
        callback(null, this.fanSpeed);
    }
    /**
    * Handle requests to set the "RotationSpeed" characteristic for Dehumidifier
    */
    handleDehumidifierRotationSpeedSet(value, callback) {
      this.platform.log.debug('Triggered SET RotationSpeed:', value);
      if (this.fanSpeed != value) {
          // values from device are 20.0="Homekit off", 40.0="Silent",60.0="Medium",80.0="High"
          this.fanSpeed = value;
          this.platform.sendUpdateToDevice(this);
      }
      callback(null, value);
    }

sendUpdateToDevice command should be modified to send the fanSpeed to the device: https://github.com/hillaliy/homebridge-midea-air/blob/7e5556b34aed9385578261a11073b0164e6f0371/src/MideaPlatform.ts#L370

And last, this line should refresh fanSpeed HK property https://github.com/hillaliy/homebridge-midea-air/blob/7e5556b34aed9385578261a11073b0164e6f0371/src/MideaAccessory.ts#L254

hillaliy commented 3 years ago

It's nice of you to look at the code I wrote and tell me what to do. The lines of code are already ready and there is no need to fix them. You just had to ask. I publish version 1.3.4

CyberMrProper commented 3 years ago

Thank you so much!