nitaybz / homebridge-tado-ac

Homebridge plugin to support Tado Smart AC Control devices.
MIT License
40 stars 12 forks source link

Don't reverse the stored fan levels every time fanLevelToHK() is called. #104

Closed nicsuzor closed 3 years ago

nicsuzor commented 3 years ago

The fanspeed capabilities from Tado come back in order: Auto, High, Middle, Low. Current code already reversed the array from Tado in unified.capabilities, but was also reversing in unified.acState. This meant that in translating the percentage-based value from HomeKit, the code applied .reverse() each time -- which mutates the array in place.

This PR simply removes the call to fanSpeeds.reverse() that was happening each time acState() was called.

This extract of the log shows the problem this PR fixes. Rotation Speed 16% should translate to 'LOW', but instead sends 'HIGH' every second time:

[07/02/2021, 2:50:22 pm] [TadoAC] Air Conditioning AC -> Setting AC state Active: true
[07/02/2021, 2:50:22 pm] [TadoAC] Air Conditioning AC -> Setting Mode to COOL
[07/02/2021, 2:50:22 pm] [TadoAC] Air Conditioning AC -> Setting AC Rotation Speed: 16%
[07/02/2021, 2:50:22 pm] [TadoAC] Air Conditioning AC -> Setting Mode to COOL
[07/02/2021, 2:50:22 pm] [TadoAC] Air Conditioning AC  -> Setting New State:
[07/02/2021, 2:50:22 pm] [TadoAC] {
"termination": {
"type": "TADO_MODE"
},
"setting": {
"type": "AIR_CONDITIONING",
"power": "ON",
"mode": "COOL",
"temperature": {
"fahrenheit": 68,
"celsius": 20
},
"swing": "OFF",
"fanSpeed": "HIGH"
}
}
[07/02/2021, 2:50:22 pm] [TadoAC] Creating PUT request to tado° API --->
[07/02/2021, 2:50:22 pm] [TadoAC] https://my.tado.com/api/v2/homes/652045/zones/1/overlay
[07/02/2021, 2:50:22 pm] [TadoAC] data: {"termination":{"type":"TADO_MODE"},"setting":{"type":"AIR_CONDITIONING","power":"ON","mode":"COOL","temperature":{"fahrenheit":68,"celsius":20},"swing":"OFF","fanSpeed":"HIGH"}}