Skip to content

Commit

Permalink
Working on controller
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanBluefox committed Nov 13, 2023
1 parent bf619b9 commit 19de1d3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
8 changes: 7 additions & 1 deletion src/matter/clusters/Base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,14 @@ class Base {
clusterId: number,
currentValue: any | undefined = undefined,
): Promise<string> {
let _id;
// create onOff
const _id = `controller.${jsonNodeId.replace(/"/g, '')}.states.${id}`;
if (id.includes('.')) {
_id = `controller.${jsonNodeId.replace(/"/g, '')}.${id}`;
} else {
_id = `controller.${jsonNodeId.replace(/"/g, '')}.states.${id}`;
}

let stateObj = await this.adapter.getObjectAsync(id);
if (!stateObj) {
stateObj = {
Expand Down
28 changes: 16 additions & 12 deletions src/matter/clusters/LevelControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,22 @@ class LevelControl extends Base {
if (!state || state.ack) {
return;
}
await cluster.moveToLevel({
level: state.val as number,
transitionTime: 0,
optionsMask: {
executeIfOff: true,
coupleColorTempToLevel: false,
},
optionsOverride: {
executeIfOff: false,
coupleColorTempToLevel: false,
}
});
try {
await cluster.moveToLevel({
level: state.val as number,
transitionTime: 0,
optionsMask: {
executeIfOff: true,
coupleColorTempToLevel: false,
},
optionsOverride: {
executeIfOff: false,
coupleColorTempToLevel: false,
}
});
} catch (e) {
this.adapter.log.error(`Cannot set ${id}: ${e.message}, stack: ${e.stack}`);
}
};
await this.subscribe(id, levelHandler);
}
Expand Down
14 changes: 9 additions & 5 deletions src/matter/clusters/OnOff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class OnOff extends Base {
const features = await cluster.getFeatureMapAttribute();
// create onOff
const id = await this.createState(
'booleanState',
'onOff',
{
name: 'Boolean state',
type: 'boolean',
Expand All @@ -41,10 +41,14 @@ class OnOff extends Base {
if (!state || state.ack) {
return;
}
if (state.val) {
await cluster.on();
} else {
await cluster.off();
try {
if (state.val) {
await cluster.on();
} else {
await cluster.off();
}
} catch (e) {
this.adapter.log.error(`Cannot set ${id}: ${e.message}, stack: ${e.stack}`);
}
};
await this.subscribe(id, onOffHandler);
Expand Down

0 comments on commit 19de1d3

Please sign in to comment.