Skip to content

Commit

Permalink
Merge pull request #1 from mouth4war/patch-1
Browse files Browse the repository at this point in the history
Add support for favorite level and fix speed change
  • Loading branch information
kingkong123 authored Dec 17, 2019
2 parents 6ca9749 + 6269de5 commit a9e8c59
Showing 1 changed file with 53 additions and 8 deletions.
61 changes: 53 additions & 8 deletions lib/devices/air-purifier-3.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,36 @@ module.exports = class extends AirPurifier.with(
}
}
);

// Favorite Fan Level
this.defineProperty(
{ did: `${id}`, siid: 10, piid: 10 },
{
name: 'favorite_level',
mapper: v => {
const { siid, piid } = v;

if (siid === 10 && piid === 10) {
return v.value;
}
}
}
);

// Motor Speed
this.defineProperty(
{ did: `${id}`, siid: 10, piid: 8 },
{
name: 'motor_speed',
mapper: v => {
const { siid, piid } = v;

if (siid === 10 && piid === 8) {
return v.value;
}
}
}
);
}

changePower(value) {
Expand Down Expand Up @@ -241,22 +271,20 @@ module.exports = class extends AirPurifier.with(
]);
}

changeFavorite(speed) {
changeFavoriteSpeed(speed) {
const { id } = this.handle.api;
let value = parseInt(speed);

if (value < 390) {
value = 390;
if (value < 300) {
value = 300;
}

if (value > 2150) {
value = 2150;
if (value > 2300) {
value = 2300
}

return this.call('set_properties', [
{ did: `${id}`, siid: 10, piid: 7, value },
{ did: `${id}`, siid: 10, piid: 8, value },
{ did: `${id}`, siid: 10, piid: 9, value }
{ did: `${id}`, siid: 10, piid: 7, value }
]);
}

Expand Down Expand Up @@ -301,4 +329,21 @@ module.exports = class extends AirPurifier.with(
{ did: `${id}`, siid: 5, piid: 1, value: !!value }
]).then(() => null);
}

changeFavoriteLevel(level) {
const { id } = this.handle.api;
let value = parseInt(level);

if (value < 0) {
value = 0;
}

if (value > 14) {
value = 14;
}

return this.call('set_properties', [
{ did: `${id}`, siid: 10, piid: 10, value }
]);
}
};

0 comments on commit a9e8c59

Please sign in to comment.