diff --git a/matter-bridge/config.yml b/matter-bridge/config.yml index acd229e..87de988 100644 --- a/matter-bridge/config.yml +++ b/matter-bridge/config.yml @@ -1,6 +1,6 @@ --- name: 'HA Matter Bridge' -version: '0.0.1-alpha' +version: '0.0.2-alpha' slug: ha-matter-bridge description: This project serves as a proof of concept to connect HomeAssistant devices to Voice Assistants through the Matter Protocol. init: false diff --git a/matter-bridge/docker-compose.yml b/matter-bridge/docker-compose.yml deleted file mode 100644 index fab69ae..0000000 --- a/matter-bridge/docker-compose.yml +++ /dev/null @@ -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 \ No newline at end of file diff --git a/matter-bridge/dockerfile.standalone b/matter-bridge/dockerfile.standalone deleted file mode 100644 index 86a6b18..0000000 --- a/matter-bridge/dockerfile.standalone +++ /dev/null @@ -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" ] \ No newline at end of file diff --git a/matter-bridge/src/home-assistant/HAmiddleware.ts b/matter-bridge/src/home-assistant/HAmiddleware.ts index d7f1d85..3d83093 100644 --- a/matter-bridge/src/home-assistant/HAmiddleware.ts +++ b/matter-bridge/src/home-assistant/HAmiddleware.ts @@ -2,35 +2,21 @@ import { Logger } from '@project-chip/matter-node.js/log'; import { HassEntity, StateChangedEvent } from './HAssTypes'; import hass, { HassApi, HassWsOptions } from 'homeassistant-ws'; -const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms)); - export class HAMiddleware { private logger = new Logger('HAMiddleware'); private hassClient: HassApi; private static instance: HAMiddleware; - private static callerOptions: Partial | undefined; - private requestFulfilled: boolean = true; private entities: { [k: string]: HassEntity } = {}; private functionsToCallOnChange: { [k: string]: ((data: StateChangedEvent) => void) | undefined; } = {}; - async waitCompletition(): Promise { - let waited = 0; - const timeOut = 5000; - while (!this.requestFulfilled && waited < timeOut) { - await sleep(1000); - waited += 1000; - } - } - stop(): void { this.hassClient.rawClient.ws.close(); } async callAService(domain: string, service: string, extraArgs?: unknown) { - this.requestFulfilled = false; - this.hassClient.callService(domain, service, extraArgs); + await this.hassClient.callService(domain, service, extraArgs); } subscribe() { @@ -43,13 +29,15 @@ export class HAMiddleware { }); } - subscrieToDevice(deviceId: string, fn: (event: StateChangedEvent) => void) { + subscribeToDevice( + deviceId: string, + fn: (event: StateChangedEvent) => void + ) { this.functionsToCallOnChange[deviceId] = fn; this.logger.debug(this.functionsToCallOnChange); } async getStates(): Promise<{ [k: string]: HassEntity }> { - this.requestFulfilled = false; const states = await this.hassClient.getStates(); const sorted = states.reduceRight<{ [k: string]: HassEntity }>( (last, current) => { @@ -82,9 +70,7 @@ export class HAMiddleware { } async getServices() { - this.requestFulfilled = false; const states = await this.hassClient.getServices(); - return states; } @@ -96,7 +82,6 @@ export class HAMiddleware { callerOptions?: Partial | undefined ): Promise { if (!HAMiddleware.instance) { - HAMiddleware.callerOptions = callerOptions; const client = await hass(callerOptions); HAMiddleware.instance = new HAMiddleware(client); } diff --git a/matter-bridge/src/mapper/Mapper.ts b/matter-bridge/src/mapper/Mapper.ts index 2b695e7..f743e11 100644 --- a/matter-bridge/src/mapper/Mapper.ts +++ b/matter-bridge/src/mapper/Mapper.ts @@ -6,7 +6,7 @@ import { HAMiddleware } from '../home-assistant/HAmiddleware'; const LOGGER = new Logger('Mapper'); -async function setHasEnties( +async function setHasEntities( haMiddleware: HAMiddleware, bridge: Bridge ): Promise { @@ -22,6 +22,6 @@ export async function addAllDevicesToBridge( haMiddleware: HAMiddleware, bridge: Bridge ): Promise { - await setHasEnties(haMiddleware, bridge); + await setHasEntities(haMiddleware, bridge); haMiddleware.subscribe(); } diff --git a/matter-bridge/src/mapper/devices/lights/DimmerableLightDevice.ts b/matter-bridge/src/mapper/devices/lights/DimmableLightDevice.ts similarity index 96% rename from matter-bridge/src/mapper/devices/lights/DimmerableLightDevice.ts rename to matter-bridge/src/mapper/devices/lights/DimmableLightDevice.ts index 74da1b2..1412828 100644 --- a/matter-bridge/src/mapper/devices/lights/DimmerableLightDevice.ts +++ b/matter-bridge/src/mapper/devices/lights/DimmableLightDevice.ts @@ -11,7 +11,7 @@ import { AddHaDeviceToBridge, Bridge, HAMiddleware } from '../MapperType'; import { Logger } from '@project-chip/matter-node.js/log'; const LOGGER = new Logger('DimmableLight'); -export const addDimmerableLightDevice: AddHaDeviceToBridge = ( +export const addDimmableLightDevice: AddHaDeviceToBridge = ( haEntity: HassEntity, haMiddleware: HAMiddleware, bridge: Bridge @@ -63,7 +63,7 @@ export const addDimmerableLightDevice: AddHaDeviceToBridge = ( ); }); - haMiddleware.subscrieToDevice( + haMiddleware.subscribeToDevice( haEntity.entity_id, (event: StateChangedEvent) => { LOGGER.debug(`Event for device ${haEntity.entity_id}`); diff --git a/matter-bridge/src/mapper/devices/lights/OnOffLightDevice.ts b/matter-bridge/src/mapper/devices/lights/OnOffLightDevice.ts index c31e05a..a8bd57e 100644 --- a/matter-bridge/src/mapper/devices/lights/OnOffLightDevice.ts +++ b/matter-bridge/src/mapper/devices/lights/OnOffLightDevice.ts @@ -8,7 +8,7 @@ import { import { AddHaDeviceToBridge, Bridge, HAMiddleware } from '../MapperType'; import { Logger } from '@project-chip/matter-node.js/log'; -const LOGGER = new Logger('OnOfflIght'); +const LOGGER = new Logger('OnOffLight'); export const addOnOffLightDevice: AddHaDeviceToBridge = ( haEntity: HassEntity, haMiddleware: HAMiddleware, @@ -42,7 +42,7 @@ export const addOnOffLightDevice: AddHaDeviceToBridge = ( `Identify called for OnOffDevice ${haEntity.attributes['friendly_name']} with id: ${serialFromId} and identifyTime: ${identifyTime}` ) ); - haMiddleware.subscrieToDevice( + haMiddleware.subscribeToDevice( haEntity.entity_id, (event: StateChangedEvent) => { LOGGER.debug(`Event for device ${haEntity.entity_id}`); diff --git a/matter-bridge/src/mapper/devices/lights/index.ts b/matter-bridge/src/mapper/devices/lights/index.ts index 8224fe6..4a2555d 100644 --- a/matter-bridge/src/mapper/devices/lights/index.ts +++ b/matter-bridge/src/mapper/devices/lights/index.ts @@ -2,11 +2,11 @@ import { Logger } from '@project-chip/matter-node.js/log'; import { HAMiddleware } from '../../../home-assistant/HAmiddleware'; import { HassEntity } from '../../../home-assistant/HAssTypes'; import { AddHaDeviceToBridge, Bridge } from '../MapperType'; -import { addDimmerableLightDevice } from './DimmerableLightDevice'; +import { addDimmableLightDevice } from './DimmableLightDevice'; import { addOnOffLightDevice } from './OnOffLightDevice'; import { Device } from '@project-chip/matter-node.js/device'; -export * from './DimmerableLightDevice'; +export * from './DimmableLightDevice'; export * from './OnOffLightDevice'; const LOGGER = new Logger('Lights'); @@ -16,8 +16,8 @@ const LIGHTS_MAP_FUNCTIONS: Map = new Map< AddHaDeviceToBridge >([ ['onoff', addOnOffLightDevice], - ['rgb', addDimmerableLightDevice], - ['brightness', addDimmerableLightDevice], + ['rgb', addDimmableLightDevice], + ['brightness', addDimmableLightDevice], ]); const LIGHTS_MAP: Map = new Map(); diff --git a/repository.yml b/repository.yml index 7cf72e7..fc29bf1 100644 --- a/repository.yml +++ b/repository.yml @@ -1 +1,3 @@ name: ha-matter-bridge +maintainer: Jatus93 +url: https://github.com/Jatus93/ha-matter-bridge \ No newline at end of file