diff --git a/accessories/fan.js b/accessories/fan.js index b776af8a..879a131a 100644 --- a/accessories/fan.js +++ b/accessories/fan.js @@ -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++) {