Skip to content
This repository was archived by the owner on Jul 1, 2024. It is now read-only.

Commit d90aae5

Browse files
committed
Fri Apr 19 23:39:50 PDT 2024
1 parent a420ad1 commit d90aae5

1 file changed

Lines changed: 23 additions & 9 deletions

File tree

skills/homeassistant/provider.ts

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
1-
import { Auth, createConnection } from "home-assistant-js-websocket";
1+
import { Auth, createConnection, createLongLivedTokenAuth } from "home-assistant-js-websocket";
22
import { HOMEASSISTANT } from "./config";
33

4+
const auth = createLongLivedTokenAuth(
5+
HOMEASSISTANT.url,
6+
HOMEASSISTANT.token
7+
);
8+
49
export const hass = await createConnection({
5-
auth: new Auth({
6-
access_token: HOMEASSISTANT.token,
7-
hassUrl: HOMEASSISTANT.url,
8-
clientId: '',
9-
expires: Infinity,
10-
expires_in: Infinity,
11-
refresh_token: '',
12-
})
10+
auth,
11+
createSocket(options) {
12+
if (options.auth && new URL(HOMEASSISTANT.url).hostname === "supervisor") {
13+
options.auth = {
14+
data: {
15+
...options.auth.data,
16+
hassUrl: "http://supervisor/core"
17+
},
18+
wsUrl: "ws://supervisor/core/websocket",
19+
accessToken: HOMEASSISTANT.token,
20+
async refreshAccessToken() {},
21+
expired: false,
22+
async revoke() {}
23+
}
24+
}
25+
return options.createSocket(options)
26+
},
1327
});

0 commit comments

Comments
 (0)