Coder Social home page Coder Social logo

Comments (2)

AlCalzone avatar AlCalzone commented on August 18, 2024

Here's a mock config file to test. This automatically sends random door state notifications every 5 seconds:

// @ts-check
const { NotificationCCReport } = require("@zwave-js/cc/NotificationCC");
const { CommandClasses } = require("@zwave-js/core");
const { ccCaps, createMockZWaveRequestFrame } = require("@zwave-js/testing");

let simulationTimer;
process.on("SIGINT", () => {
	if (simulationTimer) clearInterval(simulationTimer);
});

/** @type {import("zwave-js/Testing").MockServerOptions["config"]} */
module.exports.default = {
	nodes: [
		{
			id: 2,
			capabilities: {
				commandClasses: [
					CommandClasses.Version,
					ccCaps({
						ccId: CommandClasses.Notification,
						isSupported: true,
						version: 11,
						notificationTypesAndEvents: {
							// Access Control - Door state
							[0x06]: [0x16, 0x17],
						},
					}),
				],
			},
			behaviors: [
				{
					// Small hack - start the state simulation timer when the node
					// receives a command from the controller
					async onControllerFrame(controller, self, _frame) {
						if (!simulationTimer) {
							// Then send notifications regularly
							simulationTimer = setInterval(() => {
								// 75% of reports are open, 25% are closed
								const isOpen = Math.random() < 0.75;
								// 50% of reports include the tilt parameter
								const supportsTilt = Math.random() < 0.5;
								// 50% of those are tilted, 50% are not
								const isTilted = Math.random() < 0.5;

								const cc = new NotificationCCReport(self.host, {
									nodeId: controller.host.ownNodeId,
									notificationType: 0x06, // Access Control
									notificationEvent: isOpen ? 0x16 : 0x17,
									eventParameters: isOpen && supportsTilt
										? Buffer.from([
											isTilted ? 0x01 : 0x00,
										])
										: undefined,
								});

								self.sendToController(
									createMockZWaveRequestFrame(cc, {
										ackRequested: false,
									}),
								);
								// Tune this value according to how often you want to get notifications
							}, 5000).unref();
						}
						return false;
					},
				},
			],
		},
	],
};

from certification-backlog.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.