fixup! fixup! adding ha addon support

This commit is contained in:
Gianmarco Pettinato 2024-01-29 14:32:54 +01:00
parent e69e10de27
commit 04e4a08ac9
2 changed files with 5 additions and 7 deletions

View File

@ -8,7 +8,6 @@ export class HAMiddleware {
private logger = new Logger('HAMiddleware');
private hassClient: HassApi;
private static instance: HAMiddleware;
private connectionOpen: boolean = false;
private requestFulfilled: boolean = true;
private entities: { [k: string]: HassEntity } = {};
private functionsToCallOnChange: {
@ -96,12 +95,6 @@ export class HAMiddleware {
if (!HAMiddleware.instance) {
const client = await hass(callerOptions);
HAMiddleware.instance = new HAMiddleware(client);
let waited = 0;
const timeOut = 5000;
while (!HAMiddleware.instance.connectionOpen && waited < timeOut) {
await sleep(1000);
waited += 1000;
}
}
return HAMiddleware.instance;
}

View File

@ -9,6 +9,7 @@ let HA_MIDDLEWARE: HAMiddleware;
let BRIDGE: Bridge;
async function run() {
LOGGER.info('Startup ...');
const token = getParameter('SUPERVISOR_TOKEN');
if (!token) {
throw new Error('Missing auth token cannot run without it');
@ -19,14 +20,18 @@ async function run() {
path: '/core/websocket',
token,
});
LOGGER.info('Connected to home assistant');
BRIDGE = getBridge();
LOGGER.info('Creating the bridge');
await addAllDevicesToBridge(HA_MIDDLEWARE, BRIDGE);
LOGGER.info('all devices added');
BRIDGE.start();
}
run()
.then()
.catch((error) => {
console.error(error);
LOGGER.error(JSON.stringify(error));
});