fixup! fixup! adding ha addon support
This commit is contained in:
parent
e69e10de27
commit
04e4a08ac9
@ -8,7 +8,6 @@ export class HAMiddleware {
|
|||||||
private logger = new Logger('HAMiddleware');
|
private logger = new Logger('HAMiddleware');
|
||||||
private hassClient: HassApi;
|
private hassClient: HassApi;
|
||||||
private static instance: HAMiddleware;
|
private static instance: HAMiddleware;
|
||||||
private connectionOpen: boolean = false;
|
|
||||||
private requestFulfilled: boolean = true;
|
private requestFulfilled: boolean = true;
|
||||||
private entities: { [k: string]: HassEntity } = {};
|
private entities: { [k: string]: HassEntity } = {};
|
||||||
private functionsToCallOnChange: {
|
private functionsToCallOnChange: {
|
||||||
@ -96,12 +95,6 @@ export class HAMiddleware {
|
|||||||
if (!HAMiddleware.instance) {
|
if (!HAMiddleware.instance) {
|
||||||
const client = await hass(callerOptions);
|
const client = await hass(callerOptions);
|
||||||
HAMiddleware.instance = new HAMiddleware(client);
|
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;
|
return HAMiddleware.instance;
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ let HA_MIDDLEWARE: HAMiddleware;
|
|||||||
let BRIDGE: Bridge;
|
let BRIDGE: Bridge;
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
|
LOGGER.info('Startup ...');
|
||||||
const token = getParameter('SUPERVISOR_TOKEN');
|
const token = getParameter('SUPERVISOR_TOKEN');
|
||||||
if (!token) {
|
if (!token) {
|
||||||
throw new Error('Missing auth token cannot run without it');
|
throw new Error('Missing auth token cannot run without it');
|
||||||
@ -19,14 +20,18 @@ async function run() {
|
|||||||
path: '/core/websocket',
|
path: '/core/websocket',
|
||||||
token,
|
token,
|
||||||
});
|
});
|
||||||
|
LOGGER.info('Connected to home assistant');
|
||||||
BRIDGE = getBridge();
|
BRIDGE = getBridge();
|
||||||
|
LOGGER.info('Creating the bridge');
|
||||||
await addAllDevicesToBridge(HA_MIDDLEWARE, BRIDGE);
|
await addAllDevicesToBridge(HA_MIDDLEWARE, BRIDGE);
|
||||||
|
LOGGER.info('all devices added');
|
||||||
BRIDGE.start();
|
BRIDGE.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
run()
|
run()
|
||||||
.then()
|
.then()
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
|
console.error(error);
|
||||||
LOGGER.error(JSON.stringify(error));
|
LOGGER.error(JSON.stringify(error));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user