zigbee-herdsman-converters
Version:
Collection of device converters to be used with zigbee-herdsman
299 lines • 12.1 kB
JavaScript
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.definitions = void 0;
const reporting = __importStar(require("../lib/reporting"));
const exposes_1 = require("../lib/exposes");
const m = __importStar(require("../lib/modernExtend"));
const utils_1 = require("../lib/utils");
const defaultReporting = { min: 0, max: 3600, change: 0 };
const defaultReportingOnOff = { min: 0, max: 3600, change: 0, attribute: "onOff" };
const time_to_str_min = (time) => {
const date = new Date(null);
date.setSeconds(time);
return date.toISOString().slice(11, 16);
};
const str_min_to_time = (strMin) => {
return Number(strMin.substring(0, 2)) * 60 * 60 + Number(strMin.substring(3, 5)) * 60;
};
function timeHHMM(args) {
const { name, cluster, attribute, description, zigbeeCommandOptions, endpointName, reporting, entityCategory, validate } = args;
const attributeKey = (0, utils_1.isString)(attribute) ? attribute : attribute.ID;
const access = exposes_1.access[args.access ?? "ALL"];
const mExtend = m.text(args);
const fromZigbee = [
{
cluster: cluster.toString(),
type: ["attributeReport", "readResponse"],
convert: (model, msg, publish, options, meta) => {
if (attributeKey in msg.data && (!endpointName || (0, utils_1.getEndpointName)(msg, model, meta) === endpointName)) {
return { [name]: time_to_str_min(msg.data[attributeKey]) };
}
},
},
];
const toZigbee = [
{
key: [name],
convertSet: access & exposes_1.access.SET
? async (entity, key, value, meta) => {
const value_str = str_min_to_time(value.toString());
const payload = (0, utils_1.isString)(attribute) ? { [attribute]: value_str } : { [attribute.ID]: { value_str, type: attribute.type } };
await m.determineEndpoint(entity, meta, cluster).write(cluster, payload, zigbeeCommandOptions);
return { state: { [key]: value } };
}
: undefined,
convertGet: access & exposes_1.access.GET
? async (entity, key, meta) => {
await m.determineEndpoint(entity, meta, cluster).read(cluster, [attributeKey], zigbeeCommandOptions);
}
: undefined,
},
];
const configure = [];
configure.push(m.setupConfigureForBinding(cluster, "input"));
return { ...mExtend, fromZigbee, toZigbee, configure, isModernExtend: true };
}
function binaryWithOnOffCommand(args) {
const { name, valueOn, valueOff, cluster, attribute, zigbeeCommandOptions, endpointName, reporting } = args;
const attributeKey = (0, utils_1.isString)(attribute) ? attribute : attribute.ID;
const access = exposes_1.access[args.access ?? "ALL"];
const mExtend = m.binary(args);
const toZigbee = [
{
key: [name],
convertSet: access & exposes_1.access.SET
? async (entity, key, value, meta) => {
const state = (0, utils_1.isString)(meta.message[key]) ? meta.message[key].toLowerCase() : null;
(0, utils_1.validateValue)(state, ["toggle", "off", "on"]);
await m.determineEndpoint(entity, meta, cluster).command(cluster, state, {}, zigbeeCommandOptions);
await m.determineEndpoint(entity, meta, cluster).read(cluster, [attributeKey], zigbeeCommandOptions);
return { state: { [key]: value } };
}
: undefined,
convertGet: access & exposes_1.access.GET
? async (entity, key, meta) => {
await m.determineEndpoint(entity, meta, cluster).read(cluster, [attributeKey], zigbeeCommandOptions);
}
: undefined,
},
];
const configure = [];
if (reporting) {
configure.push(m.setupConfigureForReporting(cluster, attribute, reporting, access));
}
return { ...mExtend, toZigbee, configure, isModernExtend: true };
}
exports.definitions = [
{
zigbeeModel: ["Presence_Sensor_v2.6"],
model: "Presence_Sensor_v2.6",
vendor: "Bacchus",
description: "Presence sensor with illuminance",
meta: { multiEndpoint: true },
extend: [
m.deviceEndpoints({
endpoints: { "1": 1, "2": 2, "3": 3 },
}),
m.occupancy({
endpointNames: ["1"],
}),
m.illuminance({
reporting: defaultReporting,
}),
m.numeric({
name: "target_distance",
unit: "cm",
cluster: "msOccupancySensing",
attribute: { ID: 0xf005, type: 0x21 },
description: "Target distance",
access: "STATE",
reporting: defaultReporting,
}),
m.enumLookup({
name: "target_type",
lookup: { None: 0, Moving: 1, Stationary: 2, "Moving and stationary": 3 },
cluster: "msOccupancySensing",
attribute: { ID: 0xf006, type: 0x30 },
description: "Target type",
access: "STATE",
reporting: defaultReporting,
}),
timeHHMM({
name: "local_time",
cluster: "genTime",
attribute: "localTime",
description: "Local time",
access: "STATE_GET",
}),
m.enumLookup({
endpointName: "3",
name: "led_mode",
lookup: { Always: 0, Never: 1, Night: 2 },
cluster: "genOnOff",
attribute: { ID: 0xf004, type: 0x30 },
description: "Led working mode",
access: "ALL",
}),
m.numeric({
name: "illuminance_threshold",
unit: "raw",
valueMin: 0,
valueMax: 50000,
cluster: "msIlluminanceMeasurement",
attribute: { ID: 0xf001, type: 0x21 },
description: "Illuminance threshold",
access: "ALL",
}),
m.numeric({
name: "measurement_period",
unit: "sec",
valueMin: 0,
valueMax: 30,
cluster: "msOccupancySensing",
attribute: { ID: 0xf007, type: 0x21 },
description: "Illuminance threshold",
access: "ALL",
}),
timeHHMM({
name: "min_time",
cluster: "genTime",
attribute: "dstStart",
description: "Day start",
access: "ALL",
}),
timeHHMM({
name: "max_time",
cluster: "genTime",
attribute: "dstEnd",
description: "Day end",
access: "ALL",
}),
binaryWithOnOffCommand({
endpointName: "1",
name: "sensor",
valueOn: ["ON", 1],
valueOff: ["OFF", 0],
cluster: "genOnOff",
attribute: "onOff",
description: "Enable sensor",
access: "ALL",
reporting: defaultReportingOnOff,
}),
binaryWithOnOffCommand({
endpointName: "2",
name: "day_output",
valueOn: ["ON", 1],
valueOff: ["OFF", 0],
cluster: "genOnOff",
attribute: "onOff",
description: "Day binding output",
access: "STATE",
reporting: defaultReportingOnOff,
}),
binaryWithOnOffCommand({
endpointName: "3",
name: "night_output",
valueOn: ["ON", 1],
valueOff: ["OFF", 0],
cluster: "genOnOff",
attribute: "onOff",
description: "Night binding output",
access: "STATE",
reporting: defaultReportingOnOff,
}),
],
configure: async (device, coordinatorEndpoint) => {
// In second endpoint onOff cluster is only output, so need this:
await reporting.bind(device.getEndpoint(2), coordinatorEndpoint, ["genOnOff"]);
await reporting.onOff(device.getEndpoint(2));
await device.getEndpoint(1).read("genTime", ["dstEnd", "dstStart"]);
await device.getEndpoint(1).read("msIlluminanceMeasurement", [0xf001]);
await device.getEndpoint(1).read("msOccupancySensing", [0xf007]);
await device.getEndpoint(1).read("genOnOff", ["onOff"]);
await device.getEndpoint(3).read("genOnOff", [0xf004]);
},
},
{
zigbeeModel: ["Flower_Sensor_v2"],
model: "Flower_Sensor_v2",
vendor: "Bacchus",
description: "Flower soil moisture sensor",
extend: [
m.deviceEndpoints({ endpoints: { "1": 1 } }),
m.soilMoisture({
access: "STATE",
reporting: defaultReporting,
}),
m.temperature({
access: "STATE",
reporting: defaultReporting,
}),
m.illuminance({
access: "STATE",
reporting: defaultReporting,
}),
m.numeric({
name: "report_delay",
unit: "min",
valueMin: 1,
valueMax: 600,
cluster: "msSoilMoisture",
attribute: { ID: 0x0203, type: 0x21 },
description: "Reporting interval",
access: "STATE_SET",
}),
m.numeric({
name: "threshold",
unit: "%",
valueMin: 0,
valueMax: 100,
cluster: "msSoilMoisture",
attribute: { ID: 0x0202, type: 0x21 },
description: "Reporting interval",
access: "STATE_SET",
}),
m.battery({
voltage: true,
voltageReportingConfig: defaultReporting,
percentageReportingConfig: defaultReporting,
}),
],
configure: async (device, coordinatorEndpoint) => {
await device.getEndpoint(1).read("msSoilMoisture", [0x0202, 0x0203]);
},
},
];
//# sourceMappingURL=bacchus.js.map