lprhodes / homebridge-broadlink-rm

Broadlink RM Mini and Pro plugin for homebridge: https://github.com/nfarina/homebridge
Apache License 2.0
570 stars 285 forks source link

default-TV switch state file getting corrupted #361

Open pax0707 opened 6 years ago

pax0707 commented 6 years ago

I've noticed that if homebridge crashes the file can get corrupted and homebridge fails to start, till I fix this manually.

Any way you can add a check if the file is valid and if it's not create a new one?

[2018-4-18 07:22:30] [Broadlink RM] Initializing BroadlinkRM platform...

C:\Users\pax07\AppData\Roaming\npm\node_modules\homebridge-broadlink-rm\node_modules\node-persist\src\local-storage.js:666
            throw Error('[PARSE-ERROR] ' + file + ' does not look like a valid storage file!');
                  ^
Error: [PARSE-ERROR] C:\Users\pax07\.homebridge\plugin-persist\homebridge-broadlink-rm\407914695a1dc129bbf2ef7dc9e2450a does not look like a valid storage file!
    at LocalStorage.parseFileSync (C:\Users\pax07\AppData\Roaming\npm\node_modules\homebridge-broadlink-rm\node_modules\node-persist\src\local-storage.js:666:19)
    at LocalStorage.parseStorageDirSync (C:\Users\pax07\AppData\Roaming\npm\node_modules\homebridge-broadlink-rm\node_modules\node-persist\src\local-storage.js:615:26)
    at LocalStorage.initSync (C:\Users\pax07\AppData\Roaming\npm\node_modules\homebridge-broadlink-rm\node_modules\node-persist\src\local-storage.js:142:14)
    at Object.nodePersist.initSync (C:\Users\pax07\AppData\Roaming\npm\node_modules\homebridge-broadlink-rm\node_modules\node-persist\src\node-persist.js:37:32)
    at Object.init (C:\Users\pax07\AppData\Roaming\npm\node_modules\homebridge-broadlink-rm\node_modules\homebridge-platform-helper\helpers\persistentState.js:9:15)
    at new HomebridgePlatform (C:\Users\pax07\AppData\Roaming\npm\node_modules\homebridge-broadlink-rm\node_modules\homebridge-platform-helper\platform.js:15:21)
    at new BroadlinkRMPlatform (C:\Users\pax07\AppData\Roaming\npm\node_modules\homebridge-broadlink-rm\platform.js:31:5)
    at Server._loadPlatforms (C:\Users\pax07\AppData\Roaming\npm\node_modules\homebridge\lib\server.js:304:32)
    at Server.run (C:\Users\pax07\AppData\Roaming\npm\node_modules\homebridge\lib\server.js:85:36)
    at module.exports (C:\Users\pax07\AppData\Roaming\npm\node_modules\homebridge\lib\cli.js:40:10)
    at Object.<anonymous> (C:\Users\pax07\AppData\Roaming\npm\node_modules\homebridge\bin\homebridge:17:22)
    at Module._compile (module.js:662:30)
    at Object.Module._extensions..js (module.js:673:10)
    at Module.load (module.js:575:32)
    at tryModuleLoad (module.js:515:12)
    at Function.Module._load (module.js:507:3)
    at Function.Module.runMain (module.js:703:10)
    at startup (bootstrap_node.js:193:16)
    at bootstrap_node.js:660:3
skop1986 commented 6 years ago

I have the same problem. how can it be solved? please give any solution

pax0707 commented 6 years ago

As a workaround you can copy contents from one of the other files in the folder

skop1986 commented 6 years ago

please describe more

jamievleeshouwer commented 4 years ago

I am also having the same problem. On my TV config I have also tried setting the parameter persistState: false however it still appears to be writing the switchState value to disk. The file seems to get corrupted when I disconnect the power to my PI running Homebridge and then reconnect power. The state file then appears to be empty after reboot and must be trying to be read, which is causing the ‘not a valid storage file’ error mentioned above. This error prevents Homebridge from loading.

It would be nice if my home could return to normal state again after a power brown out or such. At the moment this issue will take all my Homebridge connected devices offline, since Homebridge won’t restart. To get Homebridge to restart I then have to terminal into my PI and delete the file which is painful.