33 lines
917 B
TypeScript
33 lines
917 B
TypeScript
import {
|
|
getIntParameter,
|
|
getParameter,
|
|
} from '@project-chip/matter-node.js/util';
|
|
import { Bridge, getBridge } from './matter';
|
|
import { Logger } from '@project-chip/matter-node.js/log';
|
|
import { HAMiddleware } from './home-assistant/HAmiddleware';
|
|
import { addAllDevicesToBridge } from './mapper/Mapper';
|
|
|
|
const LOGGER = new Logger('Main');
|
|
let HA_MIDDLEWARE: HAMiddleware;
|
|
let BRIDGE: Bridge;
|
|
|
|
async function run() {
|
|
HA_MIDDLEWARE = await HAMiddleware.getInstance({
|
|
host: getParameter('HA_HOST'),
|
|
port: getIntParameter('HA_PORT'),
|
|
token: getParameter('HA_ACCESS_TOKEN'),
|
|
});
|
|
BRIDGE = getBridge();
|
|
await addAllDevicesToBridge(HA_MIDDLEWARE, BRIDGE);
|
|
BRIDGE.start();
|
|
}
|
|
|
|
run().then().catch(LOGGER.error);
|
|
|
|
process.on('SIGINT', () => {
|
|
HA_MIDDLEWARE.stop();
|
|
BRIDGE.stop()
|
|
.then(() => process.exit(0))
|
|
.catch((err) => LOGGER.error(err));
|
|
});
|