You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am doing the authentication myself with a long lived access token (also used as bearer token for the REST API).
functioncreateSocket(): Promise<HaWebSocket>{returnnewPromise((resolve,reject)=>{constws=newWebSocket(this.host.replace(/^http/,"ws")+"/api/websocket");ws.on('error',(buffer)=>{console.error(`Error connecting to Home Assistant: ${buffer.toString()}`);reject()});ws.on('message',(buffer)=>{constdata=JSON.parse(buffer);if(data.type==="auth_ok"){ws.haVersion=data.ha_version;resolve(ws);}elseif(data.type==="auth_required"){ws.send(JSON.stringify({type: "auth",access_token: this.token}));}elseif(data.type==="auth_invalid"){console.error(`Error authenticating to Home Assistant: ${data.message}`);reject()}});})}this.wsConnection=awaitcreateConnection({createSocket: createSocket.bind(this)});
The line ws.haVersion = data.ha_version; is very important before resolving the promise, otherwise there will be bugs down the line.
You should mention in your docs that you createSocket needs to return Promise < HaWebSocket >, i.e. an object with interface WebSocket extended by the haVersion field as described in HaWebSocket
The text was updated successfully, but these errors were encountered:
I am doing the authentication myself with a long lived access token (also used as bearer token for the REST API).
The line
ws.haVersion = data.ha_version;
is very important before resolving the promise, otherwise there will be bugs down the line.You should mention in your docs that you createSocket needs to return
Promise < HaWebSocket >
, i.e. an object with interfaceWebSocket
extended by thehaVersion
field as described inHaWebSocket
The text was updated successfully, but these errors were encountered: