Skip to content

Commit

Permalink
feat: Add new features for Onesti Products AS easyCodeTouch_v1 (#6010)
Browse files Browse the repository at this point in the history
* enhance reporting of nimly pro door lock

* fix build errors, need to test locally

* Fix type and import errors

* make full converter line to pass test

* accidentally removed the pincode setting function from original

* Update onesti.ts

* change lookup to lower case

* missed 'Unknown' for lower case to unknown in onesti.ts

* change mqtt to zigbee as initiator of user action

* change to enum for two lookups

---------

Co-authored-by: Koen Kanters <koenkanters94@gmail.com>
  • Loading branch information
slackspace-io and Koenkk authored Jul 27, 2023
1 parent 34b577e commit 62fbaa2
Showing 1 changed file with 58 additions and 5 deletions.
63 changes: 58 additions & 5 deletions src/devices/onesti.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,69 @@
import {Definition} from '../lib/types';
import * as exposes from '../lib/exposes';
import fz from '../converters/fromZigbee';
import tz from '../converters/toZigbee';
import {Definition, Fz, KeyValue} from 'src/lib/types';
import * as reporting from '../lib/reporting';
const e = exposes.presets;
const ea = exposes.access;
import * as constants from '../lib/constants';

const fzLocal = {
nimly_pro_lock_actions: {
cluster: 'closuresDoorLock',
type: ['attributeReport', 'readResponse'],
convert: (model, msg, publish, options, meta) => {
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 = String(hex.substring(0, 2));
const lookup: { [key: string]: string } = {
'00': 'zigbee',
'02': 'keypad',
'03': 'fingerprintsensor',
'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;
}
},
} as Fz.Converter,
};


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],
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,8 +76,11 @@ 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.enum('last_unlock_source', ea.STATE, ['zigbee', 'keypad', 'fingerprintsensor', 'rfid', 'self', 'unknown']),
e.text('last_unlock_user', ea.STATE).withDescription('Last unlock user'),
e.enum('last_lock_source', ea.STATE, ['zigbee', 'keypad', 'fingerprintsensor', 'rfid', 'self', 'unknown']),
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

0 comments on commit 62fbaa2

Please sign in to comment.