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

Added New Features To ZYA-C4-MOD-S #6713

Merged
merged 5 commits into from
Dec 18, 2023
Merged
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
187 changes: 165 additions & 22 deletions src/devices/yale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import * as exposes from '../lib/exposes';
import fz from '../converters/fromZigbee';
import tz from '../converters/toZigbee';
import * as reporting from '../lib/reporting';
import {Extend, Definition, Fz, Reporting} from 'src/lib/types';
import {Extend, Definition, Fz, Reporting, Tz} from 'src/lib/types';
import {getFromLookup} from '../lib/utils';
import {KeyValue} from 'zigbee-herdsman/dist/controller/tstype';
const e = exposes.presets;
const ea = exposes.access;

const lockExtend = (meta={}, lockStateOptions: Reporting.Override=null, binds=['closuresDoorLock', 'genPowerCfg']): Extend => {
return {
Expand All @@ -30,39 +31,168 @@ const lockExtend = (meta={}, lockStateOptions: Reporting.Override=null, binds=['
};

const fzLocal = {
c4_lock_operation_event: {
c4_alarm: {
cluster: 'genAlarms',
type: ['commandAlarm'],
convert: async (model, msg, publish, options, meta) => {
let result: KeyValue = {};
if (msg.data.clusterid == 64512) {
const alarmcode = msg.data.alarmcode;
const lookup = {
9: {action: 'error_jammed', state: 'UNLOCK', lock_state: 'not_fully_locked'},
21: {action: 'manual_lock', state: 'LOCK', lock_state: 'locked'},
22: {action: 'manual_unlock', state: 'UNLOCK', lock_state: 'unlocked'},
24: {action: 'lock', state: 'LOCK', lock_state: 'locked'},
25: {action: 'unlock', state: 'UNLOCK', lock_state: 'unlocked'},
27: {action: 'auto_lock', state: 'LOCK', lock_state: 'locked'},
9: {state: 'UNLOCKED', lock_state: 'not_fully_locked', alarm: 'deadbolt_jammed'},
18: {action: 'keypad_lock', state: 'LOCKED', lock_state: 'locked'},
19: {action: 'keypad_unlock', state: 'UNLOCKED', lock_state: 'unlocked'},
21: {action: 'manual_lock_key_or_thumbturn', state: 'LOCKED', lock_state: 'locked'},
22: {action: 'manual_unlock_key_or_thumbturn', state: 'UNLOCKED', lock_state: 'unlocked'},
24: {action: 'lock_module', state: 'LOCKED', lock_state: 'locked'},
25: {action: 'unlock_module', state: 'UNLOCKED', lock_state: 'unlocked'},
27: {action: 'auto_lock', state: 'LOCKED', lock_state: 'locked'},
32: {action: 'manual_lock_touch', state: 'LOCKED', lock_state: 'locked'},
48: {alarm: 'lock_reset_to_factory_defaults'},
112: {alarm: 'master_code_changed'},
113: {alarm: 'duplicate_pin_code_error'},
128: {alarm: 'battery_replaced', battery_low: false},
129: {alarm: 'handing_cycle_completed_right'},
130: {alarm: 'rf_module_power_cycled'},
131: {alarm: 'handing_cycle_completed_left'},
161: {alarm: 'tamper_alarm_keypad_attempts', tamper: true},
162: {alarm: 'tamper_alarm_front_escutcheon', tamper: true},
167: {alarm: 'tamper_alarm_low_battery', tamper: true, battery_low: true},
168: {alarm: 'tamper_alarm_critical_battery', tamper: true, battery_low: true},
169: {alarm: 'low_battery', battery_low: true},
};
if (!getFromLookup(alarmcode, lookup)) {
result.action = 'unknown';
meta.logger.warn(`zigbee-herdsman-converters:Yale Lock: Unrecognized Operation Event (${alarmcode})`);
// We need to read the lock state as the alarm code is unknown
try {
await msg.endpoint.read('closuresDoorLock', ['lockState']);
} catch (error) {
meta.logger.warn(`zigbee-herdsman-converters:Yale Lock: failed to read lock state`);
}
} else {
result = getFromLookup(alarmcode, lookup);
result = getFromLookup(alarmcode, lookup);
// reset tamper and battery_low values as these will not self clear and will also be re-reported by device
if (!('tamper' in result)) {
result.tamper = false;
}
if (!('battery_low' in result)) {
result.battery_low = false;
}
}
// We need to read the lock attributes as these are not reported by the device
try {
await msg.endpoint.read('manuSpecificAssaDoorLock', ['batteryLevel']);
} catch (error) {
meta.logger.warn(`zigbee-herdsman-converters:Yale Lock: failed to read lock attributes`);
}
return result;
},
} satisfies Fz.Converter,
c4_assa_lock_attribute: {
cluster: 'manuSpecificUbisysDeviceSetup',
type: ['readResponse'],
convert: async (model, msg, publish, options, meta) => {
const data = msg.data;
const result: KeyValue = {};
if (data['18']) {
const lookup = {
0: 'off',
30: '30seconds',
60: '60seconds',
120: '2minutes',
180: '3minutes',
};
result.auto_lock_time = getFromLookup(data['18'], lookup);
}
if (data['19']) {
result.wrong_code_attempts = data['19'];
}
if (data['20']) {
result.shutdown_time = data['20'];
}
if (data['21']) {
result.battery = data['21'];
result.battery_low = data['21'] <= 15 ? true : false;
}
if (data['22']) {
result.inside_escutcheon_led = data['22'] == 1 ? true : false;
}
if (data['23']) {
const lookup = {
1: 'silent',
2: 'low',
3: 'high',
};
result.volume = getFromLookup(data['23'], lookup);
}
if (data['24']) {
const lookup = {
0: 'normal',
1: 'vacation',
2: 'privacy',
};
result.lock_mode = getFromLookup(data['24'], lookup);
}
if (data['25']) {
const lookup = {
1: 'english',
2: 'spanish',
3: 'french',
};
result.lock_mode = getFromLookup(data['25'], lookup);
}
if (data['26']) {
result.all_codes_lockout = data['26'];
}
if (data['27']) {
result.one_touch_locking = data['27'];
}
if (data['28']) {
result.privacy_button = data['28'];
}
if (data['33']) {
result.number_log_records_supported = data['33'];
}
if (data['48']) {
result.number_pins_supported = data['48'];
}
if (data['64']) {
result.number_schedule_slots_per_user = data['64'];
}
if (data['80']) {
result.alarm_mask = data['80'];
}
return result;
},
} satisfies Fz.Converter,
};

const tzLocal = {
auto_lock_time: {
key: ['auto_lock_time'],
convertSet: async (entity, key, value, meta) => {
const lookup = {
'off': 0,
'30seconds': 30,
'60seconds': 60,
'2minutes': 120,
'3minutes': 180,
};
await entity.write('manuSpecificAssaDoorLock', {'autoLockTime': getFromLookup(value, lookup)}, {disableDefaultResponse: true});
return {state: {auto_lock_time: value}};
},
convertGet: async (entity, key, meta) => {
await entity.read('manuSpecificAssaDoorLock', ['autoLockTime']);
},
} satisfies Tz.Converter,
volume: {
key: ['volume'],
convertSet: async (entity, key, value, meta) => {
const lookup = {
'silent': 1,
'low': 2,
'high': 3,
};
await entity.write('manuSpecificAssaDoorLock', {'volume': getFromLookup(value, lookup)}, {disableDefaultResponse: true});
return {state: {volume: value}};
},
convertGet: async (entity, key, meta) => {
await entity.read('manuSpecificAssaDoorLock', ['volume']);
},
} satisfies Tz.Converter,
};

const definitions: Definition[] = [
{
zigbeeModel: ['YRD446 BLE TSDB'],
Expand Down Expand Up @@ -229,9 +359,22 @@ const definitions: Definition[] = [
model: 'ZYA-C4-MOD-S',
vendor: 'Yale',
description: 'Control4 module for Yale KeyFree/Keyless/Doorman/Assure/nexTouch locks',
fromZigbee: [fz.lock, fzLocal.c4_lock_operation_event],
toZigbee: [tz.lock],
exposes: [e.lock(), e.lock_action()],
fromZigbee: [fz.lock, fzLocal.c4_alarm, fzLocal.c4_assa_lock_attribute],
toZigbee: [tz.lock, tzLocal.auto_lock_time, tzLocal.volume],
exposes: [
e.lock(),
e.lock_action(),
e.battery(),
e.battery_low(),
e.enum('auto_lock_time', ea.ALL, ['off', '30seconds', '60seconds', '2minutes', '3minutes']),
e.enum('volume', ea.ALL, ['silent', 'low', 'high']),
],
configure: async (device, coordinatorEndpoint, logger) => {
const endpoint = device.getEndpoint(1);
await endpoint.read('closuresDoorLock', ['lockState']);
await endpoint.read('manuSpecificAssaDoorLock', ['autoLockTime', 'wrongCodeAttempts', 'shutdownTime', 'batteryLevel', 'volume']);
await reporting.bind(endpoint, coordinatorEndpoint, ['manuSpecificAssaDoorLock']);
},
},
];

Expand Down