update device handling and version
This commit is contained in:
parent
b0b764be10
commit
c1ef4cd59f
@ -1,6 +1,6 @@
|
||||
---
|
||||
name: 'HA Matter Bridge'
|
||||
version: '1.0.0'
|
||||
version: '0.0.1-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
|
||||
@ -16,3 +16,4 @@ homeassistant_api: true
|
||||
auth_api: true
|
||||
map:
|
||||
- addon_config:rw
|
||||
image: ghcr.io/jatus93/ha-matter-bridge:main
|
||||
|
@ -8,6 +8,7 @@ export class HAMiddleware {
|
||||
private logger = new Logger('HAMiddleware');
|
||||
private hassClient: HassApi;
|
||||
private static instance: HAMiddleware;
|
||||
private static callerOptions: Partial<HassWsOptions> | undefined;
|
||||
private requestFulfilled: boolean = true;
|
||||
private entities: { [k: string]: HassEntity } = {};
|
||||
private functionsToCallOnChange: {
|
||||
@ -93,6 +94,7 @@ export class HAMiddleware {
|
||||
callerOptions?: Partial<HassWsOptions> | undefined
|
||||
): Promise<HAMiddleware> {
|
||||
if (!HAMiddleware.instance) {
|
||||
HAMiddleware.callerOptions = callerOptions;
|
||||
const client = await hass(callerOptions);
|
||||
HAMiddleware.instance = new HAMiddleware(client);
|
||||
}
|
||||
|
@ -1,44 +1,11 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import {
|
||||
addDimmerableLightDevice,
|
||||
addOnOffLightDevice,
|
||||
} from './devices/lights';
|
||||
import { HassEntity } from '../home-assistant/HAssTypes';
|
||||
import { setLights } from './devices/lights';
|
||||
import { Bridge } from '../matter';
|
||||
import { Logger } from '@project-chip/matter-node.js/log';
|
||||
import { HAMiddleware } from '../home-assistant/HAmiddleware';
|
||||
|
||||
const LOGGER = new Logger('Mapper');
|
||||
|
||||
const lightsMap: Map<
|
||||
string,
|
||||
(haEntity: HassEntity, haMiddleware: HAMiddleware, bridge: Bridge) => void
|
||||
> = new Map<
|
||||
string,
|
||||
(haEntity: HassEntity, haMiddleware: HAMiddleware, bridge: Bridge) => void
|
||||
>([
|
||||
['onoff', addOnOffLightDevice],
|
||||
['rgb', addDimmerableLightDevice],
|
||||
['brightness', addDimmerableLightDevice],
|
||||
]);
|
||||
|
||||
function setLights(
|
||||
lights: HassEntity[],
|
||||
haMiddleware: HAMiddleware,
|
||||
bridge: Bridge
|
||||
) {
|
||||
lights.forEach((entity) => {
|
||||
LOGGER.info({ colormodes: entity.attributes['supported_color_modes'] });
|
||||
const key = (entity.attributes['supported_color_modes'] as string[])[0];
|
||||
LOGGER.info({ key });
|
||||
const lightBuildFunction = lightsMap.get(key);
|
||||
if (!lightBuildFunction) {
|
||||
throw new Error('Missing ' + key);
|
||||
}
|
||||
return lightBuildFunction(entity, haMiddleware, bridge);
|
||||
});
|
||||
}
|
||||
|
||||
async function setHasEnties(
|
||||
haMiddleware: HAMiddleware,
|
||||
bridge: Bridge
|
||||
|
@ -16,7 +16,14 @@ export const addDimmerableLightDevice: AddHaDeviceToBridge = (
|
||||
haMiddleware: HAMiddleware,
|
||||
bridge: Bridge
|
||||
): Device => {
|
||||
const device = new DimmableLightDevice();
|
||||
const device = new DimmableLightDevice(
|
||||
{ onOff: haEntity.state === 'on' },
|
||||
{
|
||||
currentLevel: Number(haEntity.attributes['brightness']) || null,
|
||||
onLevel: 0.1,
|
||||
options: { coupleColorTempToLevel: false, executeIfOff: false },
|
||||
}
|
||||
);
|
||||
const serialFromId = MD5(haEntity.entity_id).toString();
|
||||
device.addOnOffListener((value, oldValue) => {
|
||||
if (value !== oldValue) {
|
||||
|
@ -1,2 +1,43 @@
|
||||
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 { addOnOffLightDevice } from './OnOffLightDevice';
|
||||
import { Device } from '@project-chip/matter-node.js/device';
|
||||
|
||||
export * from './DimmerableLightDevice';
|
||||
export * from './OnOffLightDevice';
|
||||
|
||||
const LOGGER = new Logger('Lights');
|
||||
|
||||
const LIGHTS_MAP_FUNCTIONS: Map<string, AddHaDeviceToBridge> = new Map<
|
||||
string,
|
||||
AddHaDeviceToBridge
|
||||
>([
|
||||
['onoff', addOnOffLightDevice],
|
||||
['rgb', addDimmerableLightDevice],
|
||||
['brightness', addDimmerableLightDevice],
|
||||
]);
|
||||
|
||||
const LIGHTS_MAP: Map<string, Device> = new Map<string, Device>();
|
||||
|
||||
export function setLights(
|
||||
lights: HassEntity[],
|
||||
haMiddleware: HAMiddleware,
|
||||
bridge: Bridge
|
||||
) {
|
||||
lights.forEach((entity) => {
|
||||
LOGGER.info({ colormodes: entity.attributes['supported_color_modes'] });
|
||||
const key = (entity.attributes['supported_color_modes'] as string[])[0];
|
||||
LOGGER.info({ key });
|
||||
const lightBuildFunction = LIGHTS_MAP_FUNCTIONS.get(key);
|
||||
if (!lightBuildFunction) {
|
||||
throw new Error('Missing ' + key);
|
||||
}
|
||||
LIGHTS_MAP.set(
|
||||
entity.entity_id,
|
||||
lightBuildFunction(entity, haMiddleware, bridge)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user