minor fixes
This commit is contained in:
parent
9a3f622941
commit
28ade3260b
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
name: 'HA Matter Bridge'
|
name: 'HA Matter Bridge'
|
||||||
version: '0.0.1-alpha'
|
version: '0.0.2-alpha'
|
||||||
slug: ha-matter-bridge
|
slug: ha-matter-bridge
|
||||||
description: This project serves as a proof of concept to connect HomeAssistant devices to Voice Assistants through the Matter Protocol.
|
description: This project serves as a proof of concept to connect HomeAssistant devices to Voice Assistants through the Matter Protocol.
|
||||||
init: false
|
init: false
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
version: '3'
|
|
||||||
services:
|
|
||||||
ha-bridge:
|
|
||||||
build: .
|
|
||||||
environment:
|
|
||||||
- HA_HOST=${HA_HOST}
|
|
||||||
- HA_PORT=${HA_PORT}
|
|
||||||
- HA_ACCESS_TOKEN=${HA_ACCESS_TOKEN}
|
|
||||||
volumes:
|
|
||||||
- ./deviceData:/app/deviceData:rw
|
|
||||||
network_mode: host
|
|
@ -1,12 +0,0 @@
|
|||||||
FROM node:18.19.0-alpine
|
|
||||||
WORKDIR /app
|
|
||||||
COPY ./package.json ./
|
|
||||||
COPY ./package-lock.json ./
|
|
||||||
COPY ./src ./src
|
|
||||||
COPY ./tsconfig.json ./
|
|
||||||
|
|
||||||
|
|
||||||
RUN npm install
|
|
||||||
RUN npm install ts-node
|
|
||||||
|
|
||||||
CMD [ "npm", "run", "start" ]
|
|
@ -2,8 +2,6 @@ import { Logger } from '@project-chip/matter-node.js/log';
|
|||||||
import { HassEntity, StateChangedEvent } from './HAssTypes';
|
import { HassEntity, StateChangedEvent } from './HAssTypes';
|
||||||
import hass, { HassApi, HassWsOptions } from 'homeassistant-ws';
|
import hass, { HassApi, HassWsOptions } from 'homeassistant-ws';
|
||||||
|
|
||||||
const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
|
|
||||||
|
|
||||||
export class HAMiddleware {
|
export class HAMiddleware {
|
||||||
private logger = new Logger('HAMiddleware');
|
private logger = new Logger('HAMiddleware');
|
||||||
private hassClient: HassApi;
|
private hassClient: HassApi;
|
||||||
@ -15,22 +13,13 @@ export class HAMiddleware {
|
|||||||
[k: string]: ((data: StateChangedEvent) => void) | undefined;
|
[k: string]: ((data: StateChangedEvent) => void) | undefined;
|
||||||
} = {};
|
} = {};
|
||||||
|
|
||||||
async waitCompletition(): Promise<void> {
|
|
||||||
let waited = 0;
|
|
||||||
const timeOut = 5000;
|
|
||||||
while (!this.requestFulfilled && waited < timeOut) {
|
|
||||||
await sleep(1000);
|
|
||||||
waited += 1000;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stop(): void {
|
stop(): void {
|
||||||
this.hassClient.rawClient.ws.close();
|
this.hassClient.rawClient.ws.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
async callAService(domain: string, service: string, extraArgs?: unknown) {
|
async callAService(domain: string, service: string, extraArgs?: unknown) {
|
||||||
this.requestFulfilled = false;
|
this.requestFulfilled = false;
|
||||||
this.hassClient.callService(domain, service, extraArgs);
|
await this.hassClient.callService(domain, service, extraArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
subscribe() {
|
subscribe() {
|
||||||
@ -43,7 +32,10 @@ export class HAMiddleware {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
subscrieToDevice(deviceId: string, fn: (event: StateChangedEvent) => void) {
|
subscribeToDevice(
|
||||||
|
deviceId: string,
|
||||||
|
fn: (event: StateChangedEvent) => void
|
||||||
|
) {
|
||||||
this.functionsToCallOnChange[deviceId] = fn;
|
this.functionsToCallOnChange[deviceId] = fn;
|
||||||
this.logger.debug(this.functionsToCallOnChange);
|
this.logger.debug(this.functionsToCallOnChange);
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ export const addDimmerableLightDevice: AddHaDeviceToBridge = (
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
haMiddleware.subscrieToDevice(
|
haMiddleware.subscribeToDevice(
|
||||||
haEntity.entity_id,
|
haEntity.entity_id,
|
||||||
(event: StateChangedEvent) => {
|
(event: StateChangedEvent) => {
|
||||||
LOGGER.debug(`Event for device ${haEntity.entity_id}`);
|
LOGGER.debug(`Event for device ${haEntity.entity_id}`);
|
||||||
|
@ -42,7 +42,7 @@ export const addOnOffLightDevice: AddHaDeviceToBridge = (
|
|||||||
`Identify called for OnOffDevice ${haEntity.attributes['friendly_name']} with id: ${serialFromId} and identifyTime: ${identifyTime}`
|
`Identify called for OnOffDevice ${haEntity.attributes['friendly_name']} with id: ${serialFromId} and identifyTime: ${identifyTime}`
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
haMiddleware.subscrieToDevice(
|
haMiddleware.subscribeToDevice(
|
||||||
haEntity.entity_id,
|
haEntity.entity_id,
|
||||||
(event: StateChangedEvent) => {
|
(event: StateChangedEvent) => {
|
||||||
LOGGER.debug(`Event for device ${haEntity.entity_id}`);
|
LOGGER.debug(`Event for device ${haEntity.entity_id}`);
|
||||||
|
@ -1 +1,3 @@
|
|||||||
name: ha-matter-bridge
|
name: ha-matter-bridge
|
||||||
|
maintainer: Jatus93
|
||||||
|
url: https://github.com/Jatus93/ha-matter-bridge
|
Loading…
Reference in New Issue
Block a user