update device handling and version

This commit is contained in:
2024-01-30 11:11:37 +01:00
parent b0b764be10
commit cfc0d14fc3
5 changed files with 54 additions and 36 deletions

View File

@@ -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