Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance reporting of nimly pro door lock #6009

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 58 additions & 5 deletions src/devices/onesti.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,66 @@ import tz from '../converters/toZigbee';
import * as reporting from '../lib/reporting';
const e = exposes.presets;
const ea = exposes.access;
import * as constants from '../lib/constants';
import {KeyValue} from 'zigbee-herdsman/dist/controller/tstype';

const fzLocal = {
nimly_pro_lock_actions: {
cluster: 'closuresDoorLock',
type: ['attributeReport', 'readResponse'],
convert: (model, msg) => {
const result: KeyValue = {};
const attributes: KeyValue = {};
// Handle attribute 257
if (msg.data['257'] !== undefined) {
const buffer = Buffer.from(msg.data['257']);
let pincode = '';
for (const byte of buffer) {
pincode += byte.toString(16);
}
attributes.last_used_pincode = pincode;
}

// Handle attribute 256
if (msg.data['256'] !== undefined) {
const hex = msg.data['256'].toString(16).padStart(8, '0');
const firstOctet = hex.substring(0, 2);
const lookup = {
'00': 'MQTT',
'02': 'Keypad',
'03': 'Fingerprint',
'04': 'RFID',
'0a': 'Self',
};
result.last_action_source = lookup[firstOctet]||'Unknown';
const secondOctet = hex.substring(2, 4);
const thirdOctet = hex.substring(4, 8);
result.last_action_user = parseInt(thirdOctet, 16);
if (secondOctet == '01') {
attributes.last_lock_user = result.last_action_user;
attributes.last_lock_source = result.last_action_source;
} else if (secondOctet == '02') {
attributes.last_unlock_user = result.last_action_user;
attributes.last_unlock_source = result.last_action_source;
}
}

// Return result if not empty
if (Object.keys(attributes).length > 0) {
return attributes;
}
},
},
};


const definitions: Definition[] = [
{
zigbeeModel: ['easyCodeTouch_v1', 'EasyCodeTouch', 'EasyFingerTouch', 'NimlyPRO', 'NimlyCode'],
model: 'easyCodeTouch_v1',
vendor: 'Onesti Products AS',
description: 'Zigbee module for EasyAccess code touch series',
fromZigbee: [fz.lock, fz.lock_operation_event, fz.battery, fz.lock_programming_event, fz.easycodetouch_action],
// eslint-disable-next-line max-len
fromZigbee: [fzLocal.nimly_pro_lock_actions, fz.lock, fz.lock_operation_event, fz.battery, fz.lock_programming_event, fz.easycodetouch_action],
toZigbee: [tz.lock, tz.easycode_auto_relock, tz.lock_sound_volume, tz.pincode_lock],
meta: {pinCodeCount: 50},
configure: async (device, coordinatorEndpoint, logger) => {
Expand All @@ -26,10 +77,12 @@ const definitions: Definition[] = [
device.save();
},
exposes: [e.lock(), e.battery(), e.sound_volume(),
e.lock_action_source_name(), e.lock_action_user(),
e.action(Array.from(Object.values(constants.easyCodeTouchActions))),
e.text('last_unlock_source', ea.STATE).withDescription('Last unlock source'),
e.text('last_unlock_user', ea.STATE).withDescription('Last unlock user'),
e.text('last_lock_source', ea.STATE).withDescription('Last lock source'),
e.text('last_lock_user', ea.STATE).withDescription('Last lock user'),
e.text('last_used_pin_code', ea.STATE).withDescription('Last used pin code'),
e.binary('auto_relock', ea.STATE_SET, true, false).withDescription('Auto relock after 7 seconds.'),
e.pincode(),
],
},
{
Expand Down