new pipeline version handling
This commit is contained in:
@@ -35,10 +35,10 @@ export class HAMiddleware {
|
||||
|
||||
subscribe() {
|
||||
this.hassClient.on('state_changed', (event) => {
|
||||
this.logger.debug(event);
|
||||
this.logger.debug(JSON.stringify(event));
|
||||
const toDo = this.functionsToCallOnChange[event.data.entity_id];
|
||||
if (toDo) {
|
||||
toDo(event.data);
|
||||
toDo(event);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -58,7 +58,7 @@ export class HAMiddleware {
|
||||
},
|
||||
{}
|
||||
);
|
||||
this.logger.debug({ getStates: sorted });
|
||||
this.logger.debug(JSON.stringify({ getStates: sorted }));
|
||||
this.entities = sorted;
|
||||
return this.entities;
|
||||
}
|
||||
@@ -75,7 +75,9 @@ export class HAMiddleware {
|
||||
prev[key].push(states[current]);
|
||||
return prev;
|
||||
}, {});
|
||||
this.logger.debug({ getStatesPartitionedByType: toReturn });
|
||||
this.logger.debug(
|
||||
JSON.stringify({ getStatesPartitionedByType: toReturn })
|
||||
);
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,16 +16,28 @@ export const addDimmerableLightDevice: AddHaDeviceToBridge = (
|
||||
haMiddleware: HAMiddleware,
|
||||
bridge: Bridge
|
||||
): Device => {
|
||||
LOGGER.debug(
|
||||
`Building device ${haEntity.entity_id} \n ${JSON.stringify({
|
||||
haEntity,
|
||||
})}`
|
||||
);
|
||||
const device = new DimmableLightDevice(
|
||||
{ onOff: haEntity.state === 'on' },
|
||||
{
|
||||
currentLevel: Number(haEntity.attributes['brightness']) || null,
|
||||
currentLevel:
|
||||
Number(haEntity.attributes['brightness']) / 255 || null,
|
||||
onLevel: 0.1,
|
||||
options: { coupleColorTempToLevel: false, executeIfOff: false },
|
||||
}
|
||||
);
|
||||
const serialFromId = MD5(haEntity.entity_id).toString();
|
||||
device.addOnOffListener((value, oldValue) => {
|
||||
LOGGER.debug(
|
||||
`OnOff Event for device ${haEntity.entity_id}, ${JSON.stringify({
|
||||
value,
|
||||
oldValue,
|
||||
})}`
|
||||
);
|
||||
if (value !== oldValue) {
|
||||
haMiddleware.callAService('light', value ? 'turn_on' : 'turn_off', {
|
||||
entity_id: haEntity.entity_id,
|
||||
@@ -41,15 +53,21 @@ export const addDimmerableLightDevice: AddHaDeviceToBridge = (
|
||||
);
|
||||
|
||||
device.addCurrentLevelListener((value) => {
|
||||
LOGGER.debug(
|
||||
`CurrentLevel Event for device ${haEntity.entity_id} value: ${value}`
|
||||
);
|
||||
haMiddleware.callAService(
|
||||
'light',
|
||||
Number(value) > 0 ? 'turn_on' : 'turn_off',
|
||||
{ entity_id: haEntity.entity_id, brightness: Number(value) }
|
||||
);
|
||||
});
|
||||
|
||||
haMiddleware.subscrieToDevice(
|
||||
haEntity.entity_id,
|
||||
(event: StateChangedEvent) => {
|
||||
LOGGER.debug(`Event for device ${haEntity.entity_id}`);
|
||||
LOGGER.debug(JSON.stringify(event));
|
||||
device.setOnOff(event.data.new_state?.state === 'on');
|
||||
device.setCurrentLevel(
|
||||
(event.data.new_state?.attributes as never)['brightness']
|
||||
|
||||
@@ -14,9 +14,21 @@ export const addOnOffLightDevice: AddHaDeviceToBridge = (
|
||||
haMiddleware: HAMiddleware,
|
||||
bridge: Bridge
|
||||
): Device => {
|
||||
LOGGER.debug(
|
||||
`Building device ${haEntity.entity_id} \n ${JSON.stringify({
|
||||
haEntity,
|
||||
})}`
|
||||
);
|
||||
const device = new OnOffLightDevice();
|
||||
const serialFromId = MD5(haEntity.entity_id).toString();
|
||||
device.addOnOffListener((value, oldValue) => {
|
||||
LOGGER.debug(
|
||||
`OnOff Event for device ${haEntity.entity_id}, ${JSON.stringify({
|
||||
value,
|
||||
oldValue,
|
||||
})}`
|
||||
);
|
||||
|
||||
if (value !== oldValue) {
|
||||
haMiddleware.callAService('light', value ? 'turn_on' : 'turn_off', {
|
||||
entity_id: haEntity.entity_id,
|
||||
@@ -33,6 +45,8 @@ export const addOnOffLightDevice: AddHaDeviceToBridge = (
|
||||
haMiddleware.subscrieToDevice(
|
||||
haEntity.entity_id,
|
||||
(event: StateChangedEvent) => {
|
||||
LOGGER.debug(`Event for device ${haEntity.entity_id}`);
|
||||
LOGGER.debug(JSON.stringify(event));
|
||||
device.setOnOff(event.data.new_state?.state === 'on');
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user