Skip to content

Commit

Permalink
Prevent Xiaomi reset on long press
Browse files Browse the repository at this point in the history
Respond to long press like stock hub does.
Currently added behavior only to devices I own, but most likely applies
to "without neutral" variants as well, since those lie inbetween battery
and "with neutral" devices.

Tested, really prevents escape.
  • Loading branch information
qm3ster committed Mar 12, 2020
1 parent 4f4f5c8 commit ea8283c
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions devices.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,26 @@ const legrand = {
},
};

const xiaomi = {
prevent_reset: async (type, data, device) => {
if (
// options.allow_reset ||
type !== "message" ||
data.type !== "attributeReport" ||
data.cluster !== "genBasic" ||
!data.data[0xfff0] ||
// eg: [0xaa, 0x10, 0x05, 0x41, 0x87, 0x01, 0x01, 0x10, 0x00]
!data.data[0xFFF0].slice(0,5).equals(Buffer.from([0xaa, 0x10, 0x05, 0x41, 0x87]))
)
return;
const options = {manufacturerCode: 0x115f};
const payload = {[0xfff0]: {
value: [0xaa, 0x10, 0x05, 0x41, 0x47, 0x01, 0x01, 0x10, 0x01],
type: 0x41
}};
await device.getEndpoint(1).write('genBasic', payload, options);
}
};
const devices = [
// Xiaomi
{
Expand Down Expand Up @@ -553,6 +573,7 @@ const devices = [
fz.xiaomi_action_click_multistate,
],
toZigbee: [],
onEvent: xiaomi.prevent_reset,
},
{
zigbeeModel: ['lumi.sensor_86sw2', 'lumi.sensor_86sw2.es1', 'lumi.remote.b286acn01'],
Expand All @@ -568,6 +589,7 @@ const devices = [
endpoint: (device) => {
return {'left': 1, 'right': 2, 'both': 3};
},
onEvent: xiaomi.prevent_reset,
},
{
zigbeeModel: ['lumi.ctrl_neutral1'],
Expand Down Expand Up @@ -600,6 +622,7 @@ const devices = [
endpoint: (device) => {
return {'system': 1};
},
onEvent: xiaomi.prevent_reset,
},
{
zigbeeModel: ['lumi.ctrl_neutral2'],
Expand Down Expand Up @@ -632,6 +655,7 @@ const devices = [
endpoint: (device) => {
return {'left': 1, 'right': 2, 'system': 1};
},
onEvent: xiaomi.prevent_reset,
},
{
zigbeeModel: ['lumi.sens', 'lumi.sensor_ht'],
Expand Down

0 comments on commit ea8283c

Please sign in to comment.