Skip to content

Commit

Permalink
Ignore fanSpeed key when looking for fan speeds (#593)
Browse files Browse the repository at this point in the history
* Ignore fanSpeed key when looking for fan speeds

---------

Co-authored-by: Cameron <32912464+kiwi-cam@users.noreply.github.com>
Co-authored-by: banboobee <98196664+banboobee@users.noreply.github.com>
  • Loading branch information
3 people committed Jun 12, 2023
1 parent 5824bc0 commit bc50468
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions accessories/fan.js
Expand Up @@ -115,16 +115,13 @@ class FanAccessory extends SwitchAccessory {
this.reset();

// Create an array of speeds specified in the data config
const foundSpeeds = [];
const allHexKeys = Object.keys(data || {});

allHexKeys.forEach((key) => {
const parts = key.split('fanSpeed');

if (parts.length !== 2) {return;}

foundSpeeds.push(parts[1])
})
const foundSpeeds = Object.keys(data || {}).reduce((accu, key) => {
const match = key.match(/fanSpeed(\d+)/);
if (match && match[1]) {
accu.push(match[1]);
}
return accu;
}, []);

if (config.speedCycle && config.speedSteps) {
for (let i = 1; i <= config.speedSteps; i++) {
Expand Down

0 comments on commit bc50468

Please sign in to comment.