joe-ng / homebridge-dyson-link

MIT License
206 stars 40 forks source link

DysonPlatform Crash when turning off my fan #36

Closed benjamin87 closed 6 years ago

benjamin87 commented 6 years ago

First of all, it's really a awesome job. Good thanks to you guys!

The problem I came across was that Dyson platform threw the following exception when I turned off my fan, which led to my homebridge crash.

[2018-5-6 15:03:55] [DysonPlatform] Dyson - Set State:{"fmod":"OFF"} [2018-5-6 15:03:55] [DysonPlatform] Request for current state update [2018-5-6 15:03:55] [DysonPlatform] {"msg":"CURRENT-STATE","time":"2018-05-06T15:03:54.000Z","mode-reason":"state-reason","MODE":"dial","OFF":"product-state","fmod":"OFF","fnst":"OFF","fnsp":"0004","qtar":"0003","oson":"OFF","rhtm":"ON","filf":"4298","ercd":"NONE","nmod":"OFF","wacd":"NONE","scheduler":{"srsc":"2c67","dstv":"0000","tzid":"0001"}} [2018-5-6 15:03:55] [DysonPlatform] Update fan data from CURRENT-STATE - Dyson

/homebridge/node_modules/homebridge-dyson-link/DysonFanState.js:9 this._fan = newState["product-state"]["fmod"] === "FAN" || ^ TypeError: Cannot read property 'fmod' of undefined at DysonFanState.updateState (/homebridge/node_modules/homebridge-dyson-link/DysonFanState.js:9:46) at MqttClient.DysonLinkDevice.mqttClient.on (/homebridge/node_modules/homebridge-dyson-link/DysonLinkDevice.js:74:39) at emitThree (events.js:136:13) at MqttClient.emit (events.js:217:7) at MqttClient._handlePublish (/homebridge/node_modules/mqtt/lib/client.js:940:12) at MqttClient._handlePacket (/homebridge/node_modules/mqtt/lib/client.js:305:12) at work (/homebridge/node_modules/mqtt/lib/client.js:261:12) at Writable.writable._write (/homebridge/node_modules/mqtt/lib/client.js:271:5) at doWrite (/homebridge/node_modules/readable-stream/lib/_stream_writable.js:428:64) at writeOrBuffer (/homebridge/node_modules/readable-stream/lib/_stream_writable.js:417:5)

Not sure whether any configuration mistake or wrong operation I had made. Any ideas? Your help is appreciated!

joe-ng commented 6 years ago

can i know which model of dyson device you used? from your log, it seemed that below message was malformed. the product-state should be an array of state.

[DysonPlatform] {"msg":"CURRENT-STATE","time":"2018-05-06T15:03:54.000Z","mode-reason":"state-reason","MODE":"dial","OFF":"product-state","fmod":"OFF","fnst":"OFF","fnsp":"0004","qtar":"0003","oson":"OFF","rhtm":"ON","filf":"4298","ercd":"NONE","nmod":"OFF","wacd":"NONE","scheduler":{"srsc":"2c67","dstv":"0000","tzid":"0001"}}

benjamin87 commented 6 years ago

Dyson pure coollink (tp02)

benjamin87 commented 6 years ago

It is strange that the periodical state update logs were showed as you said,

[2018-5-6 15:24:39] [DysonPlatform] {"msg":"CURRENT-STATE","time":"2018-05-06T15:24:38.000Z","mode-reason":"PRC","state-reason":"MODE","dial":"OFF","product-state":{"fmod":"FAN","fnst":"FAN","fnsp":"0004","qtar":"0003","oson":"ON","rhtm":"ON","filf":"4298","ercd":"NONE","nmod":"OFF","wacd":"NONE"},"scheduler":{"srsc":"2c67","dstv":"0000","tzid":"0001"}} [2018-5-6 15:24:39] [DysonPlatform] Update fan data from CURRENT-STATE - Dyson [2018-5-6 15:24:39] [DysonPlatform] Dyson - Fan On: true [2018-5-6 15:24:39] [DysonPlatform] Dyson - Fan Auto: false [2018-5-6 15:24:39] [DysonPlatform] Dyson - Night Mode: false [2018-5-6 15:24:39] [DysonPlatform] {"msg":"ENVIRONMENTAL-CURRENT-SENSOR-DATA","time":"2018-05-06T15:24:38.001Z","data":{"tact":"2973","hact":"0079","pact":"0004","vact":"0000","sltm":"OFF"}} [2018-5-6 15:24:39] [DysonPlatform] Update sensor data from ENVIRONMENTAL-CURRENT-SENSOR-DATA - Dyson

It seems the wrong formed json data only showed up when turning off my fan.

benjamin87 commented 6 years ago

@joe-ng Updates: After checking code https://github.com/CharlesBlonde/libpurecoollink/blob/master/libpurecoollink/dyson_pure_state.py

The method _get_field_value shows as followed,

def _get_field_value(state, field): """Get field value.""" return state[field][1] if isinstance(state[field], list) else state[field]

In order to parse Dyson Status/Environment data, we also need to handle two different formatted Jsons....

Since I am not a JS guy, it may takes some time for me to dig into this problem. Plz keep me posted if you guys have any updates. Thx!

benjamin87 commented 6 years ago

Hi @joe-ng I have created a pull request to fix this issue. https://github.com/joe-ng/homebridge-dyson-link/pull/37

Plz help to check it. Any idea is appreciated! Thx!

joe-ng commented 6 years ago

Thanks a lot for working on this! I have released v.2.1.4 for this