-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Description
const zigbeeHerdsmanConverters = require('zigbee-herdsman-converters');
const zigbeeHerdsmanUtils = require('zigbee-herdsman-converters/lib/utils');
const exposes = zigbeeHerdsmanConverters['exposes'] || require("zigbee-herdsman-converters/lib/exposes");
const ea = exposes.access;
const e = exposes.presets;
const fz = zigbeeHerdsmanConverters.fromZigbeeConverters || zigbeeHerdsmanConverters.fromZigbee;
const tz = zigbeeHerdsmanConverters.toZigbeeConverters || zigbeeHerdsmanConverters.toZigbee;
const ptvo_switch = (zigbeeHerdsmanConverters.findByModel)?zigbeeHerdsmanConverters.findByModel('ptvo.switch'):zigbeeHerdsmanConverters.findByDevice({modelID: 'ptvo.switch'});
fz.legacy = ptvo_switch.meta.tuyaThermostatPreset;
fz.ptvo_on_off = {
cluster: 'genOnOff',
type: ['attributeReport', 'readResponse'],
convert: (model, msg, publish, options, meta) => {
if (msg.data.hasOwnProperty('onOff')) {
const channel = msg.endpoint.ID;
const endpointName = l${channel};
const binaryEndpoint = model.meta && model.meta.binaryEndpoints && model.meta.binaryEndpoints[endpointName];
const prefix = (binaryEndpoint) ? model.meta.binaryEndpoints[endpointName] : 'state';
const property = ${prefix}_${endpointName};
if (binaryEndpoint) {
return {[property]: msg.data['onOff'] === 1};
}
return {[property]: msg.data['onOff'] === 1 ? 'ON' : 'OFF'};
}
},
};
// Copied from fromZigbee.js
// The standard converter does not append the endpoint number
fz.ptvo_humidity = {
cluster: 'msRelativeHumidity',
type: ['attributeReport', 'readResponse'],
options: [exposes.options.precision('humidity'), exposes.options.calibration('humidity')],
convert: (model, msg, publish, options, meta) => {
const humidity = parseFloat(msg.data['measuredValue']) / 100.0;
// https://github.com/Koenkk/zigbee2mqtt/issues/798
// Sometimes the sensor publishes non-realistic vales, it should only publish message
// in the 0 - 100 range, don't produce messages beyond these values.
if (humidity >= 0 && humidity <= 100) {
const property = zigbeeHerdsmanUtils.postfixWithEndpointName('humidity', msg, model, meta);
return {[property]: zigbeeHerdsmanUtils.calibrateAndPrecisionRoundOptions(humidity, options, 'humidity')};
}
},
};
fz.ptvo_pressure = {
cluster: 'msPressureMeasurement',
type: ['attributeReport', 'readResponse'],
options: [exposes.options.precision('pressure'), exposes.options.calibration('pressure')],
convert: (model, msg, publish, options, meta) => {
let pressure = 0;
if (msg.data.hasOwnProperty('scaledValue')) {
const scale = msg.endpoint.getClusterAttributeValue('msPressureMeasurement', 'scale');
pressure = msg.data['scaledValue'] / Math.pow(10, scale) / 100.0; // convert to hPa
} else {
pressure = parseFloat(msg.data['measuredValue']);
}
const property = zigbeeHerdsmanUtils.postfixWithEndpointName('pressure', msg, model, meta);
return {[property]: zigbeeHerdsmanUtils.calibrateAndPrecisionRoundOptions(pressure, options, 'pressure')};
},
};
const device = {
zigbeeModel: ['THB.Salon'],
model: 'THB.Salon',
vendor: 'mata99',
description: 'Configurable firmware',
fromZigbee: [fz.ignore_basic_report, fz.temperature, fz.ptvo_humidity,],
toZigbee: [],
exposes: [e.temperature().withEndpoint('l1'),
e.humidity().withEndpoint('l1'),
],
meta: {
multiEndpoint: true,
},
endpoint: (device) => {
return {
l1: 1,
};
},
configure: async (device, coordinatorEndpoint, logger) => {
const endpoint = device.getEndpoint(1);
await endpoint.read('genBasic', ['modelId', 'swBuildId', 'powerSource']);
},
};
module.exports = device;