Skip to content

Commit

Permalink
Add support for Sonoff SNZB-01
Browse files Browse the repository at this point in the history
  • Loading branch information
VonOx committed May 18, 2022
1 parent d45a7aa commit c95d5b9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
7 changes: 6 additions & 1 deletion server/services/zigbee2mqtt/exposes/enumType.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ module.exports = {
case BUTTON_STATUS.DOUBLE_CLICK:
relatedValue = 'double';
break;
case BUTTON_STATUS.LONG_CLICK:
case BUTTON_STATUS.HOLD_CLICK:
relatedValue = 'hold';
break;
case BUTTON_STATUS.LONG_CLICK:
relatedValue = 'long';
break;
default:
relatedValue = undefined;
}
Expand All @@ -34,6 +37,8 @@ module.exports = {
case 'double':
return BUTTON_STATUS.DOUBLE_CLICK;
case 'hold':
return BUTTON_STATUS.HOLD_CLICK;
case 'long':
return BUTTON_STATUS.LONG_CLICK;
default:
return undefined;
Expand Down
7 changes: 4 additions & 3 deletions server/test/services/zigbee2mqtt/exposes/enumType.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ describe('zigbee2mqtt enumType', () => {
[
{ enumValue: 'single', intValue: BUTTON_STATUS.CLICK },
{ enumValue: 'double', intValue: BUTTON_STATUS.DOUBLE_CLICK },
{ enumValue: 'hold', intValue: BUTTON_STATUS.LONG_CLICK },
{ enumValue: 'hold', intValue: BUTTON_STATUS.HOLD_CLICK },
{ enumValue: 'long', intValue: BUTTON_STATUS.LONG_CLICK },
].forEach((mapping) => {
const { enumValue, intValue } = mapping;

Expand All @@ -28,14 +29,14 @@ describe('zigbee2mqtt enumType', () => {

it('should write undefined value on missing enum', () => {
const missingEnumExpose = {
values: ['single', 'long', 'short', 'double', 'triple'],
values: ['single', 'short', 'double', 'triple'],
};
const result = enumType.writeValue(missingEnumExpose, BUTTON_STATUS.LONG_CLICK);
assert.equal(result, undefined);
});

it('should write undefined value', () => {
const result = enumType.writeValue(expose, 6);
const result = enumType.writeValue(expose, 7);
assert.equal(result, undefined);
});

Expand Down
3 changes: 2 additions & 1 deletion server/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const BUTTON_STATUS = {
DOUBLE_CLICK: 2,
LONG_CLICK_PRESS: 3,
LONG_CLICK_RELEASE: 4,
LONG_CLICK: 5,
HOLD_CLICK: 5,
LONG_CLICK: 6,
};

const USER_ROLE = {
Expand Down

0 comments on commit c95d5b9

Please sign in to comment.