karlg100 / homebridge-frigidaire

homebridge Platform plugin for Frigidaire connected appliances
29 stars 10 forks source link

Fix clean air switch errors & simplify its logic #42

Open beefcheeks opened 2 years ago

beefcheeks commented 2 years ago

Hey, thanks for creating this plugin - it is great being able to operate my AC inside of the Home app.

This PR fixes a warning and stacktrace caused by a combination of cyclical logic and incorrect function return values involving the getCleanAir and setCleanAir functions. Sample warning and stacktrace below:

[6/8/2022, 3:47:54 PM] [homebridge-frigidaire] Characteristic 'On': SET handler returned write response value, though the characteristic doesn't support write response. See https://homebridge.io/w/JtMGR for more info.

[6/8/2022, 3:47:54 PM] [homebridge-frigidaire] Error: 
    at On.Characteristic.characteristicWarning (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Characteristic.ts:2142:105)
    at /usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/Characteristic.ts:1756:22
    at /usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/util/once.ts:10:18
    at /homebridge/node_modules/homebridge-frigidaire/index.js:201:7
    at Request.postResponseCallback [as _callback] (/homebridge/node_modules/homebridge-frigidaire/node_modules/frigidaire/lib/frigidaire.js:418:25)
    at Request.self.callback (/homebridge/node_modules/homebridge-frigidaire/node_modules/request/request.js:185:22)
    at Request.emit (node:events:527:28)
    at Request.<anonymous> (/homebridge/node_modules/homebridge-frigidaire/node_modules/request/request.js:1154:10)
    at Request.emit (node:events:527:28)
    at IncomingMessage.<anonymous> (/homebridge/node_modules/homebridge-frigidaire/node_modules/request/request.js:1076:12)
    at Object.onceWrapper (node:events:641:28)
    at IncomingMessage.emit (node:events:539:35)
    at endReadableNT (node:internal/streams/readable:1345:12)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)

These changes fix the stacktraces and enable expected behavior for the clean air switch (my AC model supports this switch). In conjunction with #41, I believe this fixes all known issues I've seen with this plugin. I'd also like to note that while the set command updating the clean air switch works well, the get command shortly after a set temporarily sets the switch back to its previous state for a few seconds. This is likely because the AC itself isn't returning the updated state when a get request is made. Without introducing a caching layer, I think this is actually expected behavior.

evanpierre commented 2 years ago

Thanks for getting this together @beefcheeks. Hopefully @karlg100 has a chance to review and pull this in sometime soon.

nskrotzki commented 2 years ago

@beefcheeks any chance you can post your fixes in it's own branch and npm? Not sure the original dev is still monitoring or updating his plugin.

pman193 commented 1 year ago

Hey all. This is what I'm getting even after applying every fix I've found on these threads. Not a coder. Just copying and pasting. I've also noticed that since the release of the new Frigidaire app, not only is the plugin not working, but, I'm unable to control my unit it with my google home. Don't know if it's related.

[6/6/2023, 3:38:31 PM] [homebridge-frigidaire] Child bridge process ended [6/6/2023, 3:38:31 PM] [homebridge-frigidaire] Process Ended. Code: 1, Signal: null [6/6/2023, 3:38:38 PM] [homebridge-frigidaire] Restarting Process... [6/6/2023, 3:38:39 PM] [homebridge-frigidaire] Launched child bridge with PID 28541 [6/6/2023, 3:38:40 PM] Registering platform 'homebridge-frigidaire.Frigidaire' [6/6/2023, 3:38:40 PM] [homebridge-frigidaire] Loaded homebridge-frigidaire v2.1.3 child bridge successfully failed to parse auth result json: '[object Object]'

/usr/lib/node_modules/homebridge-frigidaire/node_modules/frigidaire/lib/frigidaire.js:539 var sessionKey = body.data.sessionKey ^ TypeError: Cannot read properties of undefined (reading 'sessionKey') at Request.authPostCallback [as _callback] (/usr/lib/node_modules/homebridge-frigidaire/node_modules/frigidaire/lib/frigidaire.js:539:37) at Request.self.callback (/usr/lib/node_modules/homebridge-frigidaire/node_modules/request/request.js:185:22) at Request.emit (node:events:513:28) at Request. (/usr/lib/node_modules/homebridge-frigidaire/node_modules/request/request.js:1154:10) at Request.emit (node:events:513:28) at IncomingMessage. (/usr/lib/node_modules/homebridge-frigidaire/node_modules/request/request.js:1076:12) at Object.onceWrapper (node:events:627:28) at IncomingMessage.emit (node:events:525:35) at endReadableNT (node:internal/streams/readable:1359:12) at processTicksAndRejections (node:internal/process/task_queues:82:21)