|
const fz = require('zigbee-herdsman-converters/converters/fromZigbee'); |
|
const tz = require('zigbee-herdsman-converters/converters/toZigbee'); |
|
const exposes = require('zigbee-herdsman-converters/lib/exposes'); |
|
const utils = require('zigbee-herdsman-converters/lib/utils'); |
|
const legacy = require('zigbee-herdsman-converters/lib/legacy'); |
|
const e = exposes.presets; |
|
const ea = exposes.access; |
|
|
|
const STARTUP_DELAY = 4.0 ; // how much to wait before reporting for the first time |
|
const PUBLISH_DELAY = 10.0 ; // And the delay before |
|
|
|
const legacy_tuya_air_quality_with_cache = { |
|
cluster: 'manuSpecificTuya', |
|
type: ['commandDataReport', 'commandDataResponse'], |
|
convert: (model, msg, publish, options, meta) => { |
|
// return legacy.fromZigbee.tuya_air_quality.convert(model, msg, publish, options, meta); |
|
const now = Date.now(); // current time in ms |
|
if ( ! ('_priv' in meta.device) ) { |
|
// Initialize the cache at startup |
|
meta.device.private_cache = {} ; |
|
meta.device.private_next_update = now + STARTUP_DELAY*1000; |
|
} |
|
const changes = legacy.fromZigbee.tuya_air_quality.convert(model, msg, publish, options, meta); |
|
Object.assign( meta.device.private_cache, changes ); |
|
if ( now >= meta.device.private_next_update ) { |
|
// Every PUBLISH_DELAY seconds, publish the attributes accumulated in the cache. |
|
const result = meta.device._cache; |
|
meta.device.private_next_update = now + PUBLISH_DELAY*1000; |
|
meta.device.private_cache = {}; |
|
return result; |
|
} else { |
|
return {} ; |
|
} |
|
} |
|
}; |
|
|
|
const definition = |
|
{ |
|
fingerprint: [{ modelID: 'TS0601', manufacturerName: '_TZE200_8ygsuhe1' }, |
|
{ modelID: 'TS0601', manufacturerName: '_TZE200_yvx5lh6k' }, |
|
{ modelID: 'TS0601', manufacturerName: '_TZE200_ryfmq5rl' }, |
|
{ modelID: 'TS0601', manufacturerName: '_TZE200_c2fmom5z' }, |
|
{ modelID: 'TS0601', manufacturerName: '_TZE200_mja3fuja' }], |
|
model: 'TS0601_air_quality_sensor', |
|
vendor: 'TuYa', |
|
description: 'Air quality sensor (WITH DELAYED OUTPUT)', |
|
// fromZigbee: [legacy.fromZigbee.tuya_air_quality], |
|
fromZigbee: [ legacy_tuya_air_quality_with_cache ], |
|
toZigbee: [], |
|
exposes: [e.temperature(), e.humidity(), e.co2(), e.voc().withUnit('ppm'), e.formaldehyd()], |
|
} ; |
|
|
|
module.exports = definition; |