-
Hey there! I'm currently playing around with this library and wanted to implement a light bulb with colors. Unfortunately I cant get it to run, as this error keeps occurring:
After hours of searching I haven't found anything helpful, that's why I post this question here! My example looks like the following: import "@project-chip/matter-node.js";
import {
MoveColorTemperatureRequest,
MoveToColorTemperatureRequest,
StepColorTemperatureRequest,
StopMoveStepRequest,
} from "@project-chip/matter.js/behaviors/color-control";
import {
MoveRequest,
MoveToLevelRequest,
MoveToLevelWithOnOffRequest,
MoveWithOnOffRequest,
StepRequest,
StopRequest,
} from "@project-chip/matter.js/behaviors/level-control";
import {
ColorTemperatureLightDevice,
ColorTemperatureLightRequirements,
} from "@project-chip/matter.js/devices/ColorTemperatureLightDevice";
import { ServerNode } from "@project-chip/matter.js/node";
import { randomBytes } from "crypto";
class ReportingLevelServer extends ColorTemperatureLightRequirements.LevelControlServer {
override initialize() {
this.events.onLevel$Change.on((value) => {
console.log(`Current level changed to ${value}`);
});
}
override async move(req: MoveRequest) {
console.log(`Moving to level ${req.rate}`);
}
override async moveToLevel(req: MoveToLevelRequest) {
console.log(`Moving to level ${req.level}`);
}
override async step(req: StepRequest) {
console.log(`Stepping to level ${req.stepSize}`);
}
override async stop(req: StopRequest) {
console.log("Stopping");
}
override async moveToLevelWithOnOff(req: MoveToLevelWithOnOffRequest) {
console.log(`Moving to level ${req.level} with on/off ${req.level}`);
}
override async moveWithOnOff(req: MoveWithOnOffRequest) {
console.log(`Moving to level ${req.rate} with on/off ${req.rate}`);
}
override async stepWithOnOff(req: StepRequest) {
console.log(
`Stepping to level ${req.stepSize} with on/off ${req.stepSize}`
);
}
override async stopWithOnOff(req: StopRequest) {
console.log("Stopping with on/off");
}
}
class ReportingColorServer extends ColorTemperatureLightRequirements.ColorControlServer {
override async moveColorTemperature(req: MoveColorTemperatureRequest) {
console.log(`Moving color temperature to ${req.rate}`);
}
override async moveToColorTemperature(req: MoveToColorTemperatureRequest) {
console.log(`Moving color temperature to ${req.colorTemperatureMireds}`);
}
override async stepColorTemperature(req: StepColorTemperatureRequest) {
console.log(`Stepping color temperature to ${req.stepSize}`);
}
override async stopMoveStep(req: StopMoveStepRequest) {
console.log("Stopping move step");
}
}
// Create device
const ExampleLight = ColorTemperatureLightDevice.with(
ReportingLevelServer,
ReportingColorServer
);
// Create and run node
const node = await ServerNode.create(undefined, {
id: randomBytes(8).toString("hex"),
basicInformation: {
productName: "Light Proxy",
},
});
await node.add(ExampleLight, {
id: "asd",
});
await node.run(); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Hi @bene, it just so happens that @Apollon77 fleshed out the default implementation of If you haven't already, could you please take a look at the new |
Beta Was this translation helpful? Give feedback.
Hi @bene, it just so happens that @Apollon77 fleshed out the default implementation of
ColorControlServer
in a PR we merged yesterday. The error you describe looks like a bad "conformance" rule extracted from the specifications, but Ingo probably fixed that when he was in there. He also added docs and a default implementation for much of the logic.If you haven't already, could you please take a look at the new
ColorControlServer.ts
? I'm not sure if it merged before or after the nightly build ran... If it's not there you can git clone or wait for our next nightly.