zwave-js
Version:
Z-Wave driver written entirely in JavaScript/TypeScript
59 lines (58 loc) • 2.52 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var SoundSwitchCC_exports = {};
__export(SoundSwitchCC_exports, {
getDefaultSoundSwitchHandlerStore: () => getDefaultSoundSwitchHandlerStore,
handleSoundSwitchSetValue: () => handleSoundSwitchSetValue
});
module.exports = __toCommonJS(SoundSwitchCC_exports);
var import_cc = require("@zwave-js/cc");
var import_shared = require("@zwave-js/shared");
function getDefaultSoundSwitchHandlerStore() {
return {
autoResetTimers: /* @__PURE__ */ new Map()
};
}
__name(getDefaultSoundSwitchHandlerStore, "getDefaultSoundSwitchHandlerStore");
function handleSoundSwitchSetValue(ctx, node, store, endpointIndex, toneId) {
const existingTimer = store.autoResetTimers.get(endpointIndex);
if (existingTimer) {
existingTimer.clear();
store.autoResetTimers.delete(endpointIndex);
}
if (toneId > 0) {
const durationSeconds = import_cc.SoundSwitchCC.getToneDurationCached(ctx, { nodeId: node.id, index: endpointIndex, virtual: false }, toneId);
if (durationSeconds !== void 0 && durationSeconds > 0) {
const timeoutMs = durationSeconds * 1e3;
const timer = (0, import_shared.setTimer)(() => {
node.valueDB.setValue(import_cc.SoundSwitchCCValues.toneId.endpoint(endpointIndex), 0);
store.autoResetTimers.delete(endpointIndex);
}, timeoutMs).unref();
store.autoResetTimers.set(endpointIndex, timer);
}
}
}
__name(handleSoundSwitchSetValue, "handleSoundSwitchSetValue");
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
getDefaultSoundSwitchHandlerStore,
handleSoundSwitchSetValue
});
//# sourceMappingURL=SoundSwitchCC.js.map