Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

homebridge-sensibo-sky crashes Homebridge #33

Open
zork17 opened this issue Feb 25, 2019 · 4 comments
Open

homebridge-sensibo-sky crashes Homebridge #33

zork17 opened this issue Feb 25, 2019 · 4 comments

Comments

@zork17
Copy link

zork17 commented Feb 25, 2019

I tried this plugin a year ago and it didn't work.
I tried it now (after installing the latest versions of everything) and I get the same error.
This is the config file:

{
			"platform": "SensiboSky",
			"name": "Sensibo",
			"apiKey": "XXX"
}

This is the error I get:

Feb 25 10:29:42 RSBPI homebridge[9573]: /usr/lib/node_modules/homebridge-sensibo-sky/lib/sensiboapi.js:117
Feb 25 10:29:42 RSBPI homebridge[9573]: callback(data.result[i].acState);
Feb 25 10:29:42 RSBPI homebridge[9573]: ^
Feb 25 10:29:42 RSBPI homebridge[9573]: TypeError: Cannot read property 'acState' of undefined
Feb 25 10:29:42 RSBPI homebridge[9573]: at /usr/lib/node_modules/homebridge-sensibo-sky/lib/sensiboapi.js:117:28
Feb 25 10:29:42 RSBPI homebridge[9573]: at IncomingMessage.<anonymous> (/usr/lib/node_modules/homebridge-sensibo-sky/lib/sensiboapi.js:50:21)
Feb 25 10:29:42 RSBPI homebridge[9573]: at emitNone (events.js:91:20)
Feb 25 10:29:42 RSBPI homebridge[9573]: at IncomingMessage.emit (events.js:185:7)
Feb 25 10:29:42 RSBPI homebridge[9573]: at endReadableNT (_stream_readable.js:974:12)
Feb 25 10:29:42 RSBPI homebridge[9573]: at _combinedTickCallback (internal/process/next_tick.js:74:11)
Feb 25 10:29:42 RSBPI homebridge[9573]: at process._tickCallback (internal/process/next_tick.js:98:9)
Feb 25 10:29:42 RSBPI systemd[1]: homebridge.service: main process exited, code=exited, status=1/FAILURE
Feb 25 10:29:42 RSBPI systemd[1]: Unit homebridge.service entered failed state.

The only difference I can think of from a simple homebridge system is that I have 2 homebridge services since in total I have more than 100 devices.
I tried putting the sensibo-sky platform in each of them and it crashes at the same line.

Is there a way to debug or fix this?

@zork17
Copy link
Author

zork17 commented Mar 3, 2019

Any help?

@zork17
Copy link
Author

zork17 commented Mar 14, 2019

I can see in the lines just above the crash:

		//We get the last 10 items in case the first one failed.
		if (debug) {
					console.log("**[Sensibo API Debug] DeviceID :\n", deviceID.trim());
		}
		GET({ path: 'pods/'+deviceID+'/acStates?fields=status,reason,acState&limit=10&apiKey='+this.apiKey },function(data){

that the number 10 is mentioned.
I have 10 Sensibo devices - maybe this causes the problem?

@zork17
Copy link
Author

zork17 commented Mar 17, 2019

I managed to fix it with the following change in getState:
Old:

getState: function(deviceID, callback) {
		//We get the last 10 items in case the first one failed.
		GET({ path: 'pods/'+deviceID+'/acStates?fields=status,reason,acState&limit=10&apiKey='+this.apiKey },function(data){
			if (data && data.status && data.status == 'success' && data.result && data.result instanceof Array) {
				var i=0;
				for (i=0; i<data.result.length; i++) {
					if (data.result[i].status=="Success") break;
				}
				if (i==data.result.length) i=0;
				callback(data.result[i].acState);
			} else {
				callback();
			}
		})		
	},

New

getState: function(deviceID, callback) {
		GET({ path: 'pods/'+deviceID+'/acStates?fields=status,reason,acState&limit=20&apiKey='+this.apiKey },function(data){
			if (data && data.status && data.status == 'success' && data.result && data.result instanceof Array) {
				var i=0;
				for (i=0; i<data.result.length; i++) {
					if (data.result[i].status=="Success") break;
				}
				if (i==0 && data.result.length==0)
					callback();
				else
				{
					if (i==data.result.length) i=0;
					callback(data.result[i].acState);
				}
			} else {
				callback();
			}
		})		
	},

So basically adding:

if (i==0 && data.result.length==0)
	callback();

I do not know what is the effecting of this, but it works.
I found out that in many cases in my system both i and data.result.length are 0 after the loop.
Any chance of adding this to the code?

@HFi6QhEqLVxy2V
Copy link

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants