mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2026-08-26 12:39:56 +00:00
Update zigbee-shepherd-converters to 8.1.0 (always assume state). #1349
This commit is contained in:
@@ -10,39 +10,10 @@ const postfixes = utils.getPostfixes();
|
||||
const maxDepth = 20;
|
||||
|
||||
const groupConverters = [
|
||||
{
|
||||
from: (converted) => {
|
||||
if (converted.cid === 'genOnOff') {
|
||||
return {state: converted.cmd.toUpperCase()};
|
||||
} else if (converted.cid === 'genLevelCtrl') {
|
||||
return {state: 'ON', brightness: Number(converted.zclData.level)};
|
||||
}
|
||||
},
|
||||
to: zigbeeShepherdConverters.toZigbeeConverters.light_onoff_brightness,
|
||||
},
|
||||
{
|
||||
from: (converted) => {
|
||||
return {color_temp: Number(converted.zclData.colortemp)};
|
||||
},
|
||||
to: zigbeeShepherdConverters.toZigbeeConverters.light_colortemp,
|
||||
},
|
||||
{
|
||||
from: (converted) => {
|
||||
if (converted.zclData.hasOwnProperty('colorx') && converted.zclData.hasOwnProperty('colory')) {
|
||||
return {
|
||||
color: {
|
||||
x: converted.zclData.colorx / 65535,
|
||||
y: converted.zclData.colory / 65535,
|
||||
},
|
||||
};
|
||||
}
|
||||
},
|
||||
to: zigbeeShepherdConverters.toZigbeeConverters.light_color,
|
||||
},
|
||||
{
|
||||
from: () => null,
|
||||
to: zigbeeShepherdConverters.toZigbeeConverters.ignore_transition,
|
||||
},
|
||||
zigbeeShepherdConverters.toZigbeeConverters.light_onoff_brightness,
|
||||
zigbeeShepherdConverters.toZigbeeConverters.light_colortemp,
|
||||
zigbeeShepherdConverters.toZigbeeConverters.light_color,
|
||||
zigbeeShepherdConverters.toZigbeeConverters.ignore_transition,
|
||||
];
|
||||
|
||||
class DevicePublish {
|
||||
@@ -102,37 +73,15 @@ class DevicePublish {
|
||||
}
|
||||
|
||||
handlePublished(entity, topic, converter, converted, key, value) {
|
||||
if (entity.type === 'device' && topic.type === 'set') {
|
||||
// Devices do not report when they go off, this ensures state (on/off) is always in sync.
|
||||
// Brightness onoff converters also control the state. (do a moveToLevelWithOnOff)
|
||||
const msg = {};
|
||||
const _key = topic.postfix ? `state_${topic.postfix}` : 'state';
|
||||
if (topic.type === 'set' && converted.hasOwnProperty('newState') && converted.newState) {
|
||||
const msg = converted.newState;
|
||||
|
||||
if (converted.cid === 'genOnOff') {
|
||||
const state = converted.cmd.toUpperCase();
|
||||
msg[_key] = state;
|
||||
|
||||
// Turn of through brightness.
|
||||
if (state === 'OFF' && key.startsWith('brightness') && value === 0) {
|
||||
msg['brightness'] = 0;
|
||||
}
|
||||
} else if (converted.cid === 'genLevelCtrl' && converted.cmd === 'moveToLevelWithOnOff') {
|
||||
const brightness = Number(converted.zclData.level);
|
||||
msg[_key] = brightness === 0 ? 'OFF' : 'ON';
|
||||
msg['brightness'] = brightness;
|
||||
} else if (converted.cid === 'genLevelCtrl' && converted.cmd === 'moveToLevel') {
|
||||
msg['brightness'] = Number(converted.zclData.level);
|
||||
if (topic.postfix) {
|
||||
msg[`state_${topic.postfix}`] = msg.state;
|
||||
delete msg.state;
|
||||
}
|
||||
|
||||
if (Object.keys(msg).length > 0) {
|
||||
this.publishEntityState(entity.ID, msg);
|
||||
}
|
||||
} else if (entity.type === 'group' && topic.type === 'set') {
|
||||
// As a group doesn't confirm it's state, we mock the state here.
|
||||
const payload = groupConverters.find((g) => g.to === converter).from(converted);
|
||||
if (payload) {
|
||||
this.publishEntityState(entity.ID, payload);
|
||||
}
|
||||
this.publishEntityState(entity.ID, msg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,7 +127,7 @@ class DevicePublish {
|
||||
|
||||
converters = model.toZigbee;
|
||||
} else if (entity.type === 'group') {
|
||||
converters = groupConverters.map((g) => g.to);
|
||||
converters = groupConverters;
|
||||
}
|
||||
|
||||
// Convert the MQTT message to a Zigbee message.
|
||||
|
||||
@@ -628,6 +628,7 @@ const mapping = {
|
||||
'HS2SK': [configurations.switch, configurations.sensor_power],
|
||||
'45853GE': [configurations.switch],
|
||||
'50064': [configurations.light_brightness_colortemp],
|
||||
'9290011998B': [configurations.light_brightness_colortemp],
|
||||
};
|
||||
|
||||
Object.keys(mapping).forEach((key) => {
|
||||
|
||||
Generated
+14
-96
@@ -446,9 +446,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"@types/node": {
|
||||
"version": "11.12.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-11.12.1.tgz",
|
||||
"integrity": "sha512-sKDlqv6COJrR7ar0+GqqhrXQDzQlMcqMnF2iEU6m9hLo8kxozoAGUazwPyELHlRVmjsbvlnGXjnzyptSXVmceA==",
|
||||
"version": "11.12.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-11.12.2.tgz",
|
||||
"integrity": "sha512-c82MtnqWB/CqqK7/zit74Ob8H1dBdV7bK+BcErwtXbe0+nUGkgzq5NTDmRW/pAv2lFtmeNmW95b0zK2hxpeklg==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/stack-utils": {
|
||||
@@ -2418,9 +2418,9 @@
|
||||
}
|
||||
},
|
||||
"eslint": {
|
||||
"version": "5.15.3",
|
||||
"resolved": "https://registry.npmjs.org/eslint/-/eslint-5.15.3.tgz",
|
||||
"integrity": "sha512-vMGi0PjCHSokZxE0NLp2VneGw5sio7SSiDNgIUn2tC0XkWJRNOIoHIg3CliLVfXnJsiHxGAYrkw0PieAu8+KYQ==",
|
||||
"version": "5.16.0",
|
||||
"resolved": "https://registry.npmjs.org/eslint/-/eslint-5.16.0.tgz",
|
||||
"integrity": "sha512-S3Rz11i7c8AA5JPv7xAH+dOyq/Cu/VXHiHXBPOU1k/JAM5dXqQPt3qcrhpHSorXmrpu2g0gkIBVXAqCpzfoZIg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@babel/code-frame": "^7.0.0",
|
||||
@@ -2443,7 +2443,7 @@
|
||||
"import-fresh": "^3.0.0",
|
||||
"imurmurhash": "^0.1.4",
|
||||
"inquirer": "^6.2.2",
|
||||
"js-yaml": "^3.12.0",
|
||||
"js-yaml": "^3.13.0",
|
||||
"json-stable-stringify-without-jsonify": "^1.0.1",
|
||||
"levn": "^0.3.0",
|
||||
"lodash": "^4.17.11",
|
||||
@@ -4632,66 +4632,10 @@
|
||||
"dev": true
|
||||
},
|
||||
"nwsapi": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/nwsapi/-/nwsapi-2.1.2.tgz",
|
||||
"integrity": "sha512-TQOQNxqEdxVjwgwNZyvKDF0vALmzQKZJEZwE3fZWDb7Ns5Hw6l9PxJTGKOHZGsmf7R6grsOe8lWxI43Clz79zg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"jsdom": "^14.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"jsdom": {
|
||||
"version": "14.0.0",
|
||||
"resolved": "https://registry.npmjs.org/jsdom/-/jsdom-14.0.0.tgz",
|
||||
"integrity": "sha512-/VkyPmdtbwqpJSkwDx3YyJ3U1oawYNB/h5z8vTUZGAzjtu2OHTeFRfnJqyMHsJ5Cyes23trOmvUpM1GfHH1leA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"abab": "^2.0.0",
|
||||
"acorn": "^6.0.4",
|
||||
"acorn-globals": "^4.3.0",
|
||||
"array-equal": "^1.0.0",
|
||||
"cssom": "^0.3.4",
|
||||
"cssstyle": "^1.1.1",
|
||||
"data-urls": "^1.1.0",
|
||||
"domexception": "^1.0.1",
|
||||
"escodegen": "^1.11.0",
|
||||
"html-encoding-sniffer": "^1.0.2",
|
||||
"nwsapi": "^2.0.9",
|
||||
"parse5": "5.1.0",
|
||||
"pn": "^1.1.0",
|
||||
"request": "^2.88.0",
|
||||
"request-promise-native": "^1.0.5",
|
||||
"saxes": "^3.1.5",
|
||||
"symbol-tree": "^3.2.2",
|
||||
"tough-cookie": "^2.5.0",
|
||||
"w3c-hr-time": "^1.0.1",
|
||||
"w3c-xmlserializer": "^1.0.1",
|
||||
"webidl-conversions": "^4.0.2",
|
||||
"whatwg-encoding": "^1.0.5",
|
||||
"whatwg-mimetype": "^2.3.0",
|
||||
"whatwg-url": "^7.0.0",
|
||||
"ws": "^6.1.2",
|
||||
"xml-name-validator": "^3.0.0"
|
||||
}
|
||||
},
|
||||
"parse5": {
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/parse5/-/parse5-5.1.0.tgz",
|
||||
"integrity": "sha512-fxNG2sQjHvlVAYmzBZS9YlDp6PTSSDwa98vkD4QgVDDCAo84z5X1t5XyJQ62ImdLXx5NdIIfihey6xpum9/gRQ==",
|
||||
"dev": true
|
||||
},
|
||||
"whatwg-url": {
|
||||
"version": "7.0.0",
|
||||
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-7.0.0.tgz",
|
||||
"integrity": "sha512-37GeVSIJ3kn1JgKyjiYNmSLP1yzbpb29jdmwBSgkD9h40/hyrR/OifpVUndji3tmwGgD8qpw7iQu3RSbCrBpsQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"lodash.sortby": "^4.7.0",
|
||||
"tr46": "^1.0.1",
|
||||
"webidl-conversions": "^4.0.2"
|
||||
}
|
||||
}
|
||||
}
|
||||
"version": "2.1.3",
|
||||
"resolved": "https://registry.npmjs.org/nwsapi/-/nwsapi-2.1.3.tgz",
|
||||
"integrity": "sha512-RowAaJGEgYXEZfQ7tvvdtAQUKPyTR6T6wNu0fwlNsGQYr/h3yQc6oI8WnVZh3Y/Sylwc+dtAlvPqfFZjhTyk3A==",
|
||||
"dev": true
|
||||
},
|
||||
"oauth-sign": {
|
||||
"version": "0.9.0",
|
||||
@@ -5444,15 +5388,6 @@
|
||||
"integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==",
|
||||
"dev": true
|
||||
},
|
||||
"saxes": {
|
||||
"version": "3.1.9",
|
||||
"resolved": "https://registry.npmjs.org/saxes/-/saxes-3.1.9.tgz",
|
||||
"integrity": "sha512-FZeKhJglhJHk7eWG5YM0z46VHmI3KJpMBAQm3xa9meDvd+wevB5GuBB0wc0exPInZiBBHqi00DbS8AcvCGCFMw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"xmlchars": "^1.3.1"
|
||||
}
|
||||
},
|
||||
"semver": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/semver/-/semver-6.0.0.tgz",
|
||||
@@ -6286,17 +6221,6 @@
|
||||
"browser-process-hrtime": "^0.1.2"
|
||||
}
|
||||
},
|
||||
"w3c-xmlserializer": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/w3c-xmlserializer/-/w3c-xmlserializer-1.1.2.tgz",
|
||||
"integrity": "sha512-p10l/ayESzrBMYWRID6xbuCKh2Fp77+sA0doRuGn4tTIMrrZVeqfpKjXHY+oDh3K4nLdPgNwMTVP6Vp4pvqbNg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"domexception": "^1.0.1",
|
||||
"webidl-conversions": "^4.0.2",
|
||||
"xml-name-validator": "^3.0.0"
|
||||
}
|
||||
},
|
||||
"walker": {
|
||||
"version": "1.0.7",
|
||||
"resolved": "https://registry.npmjs.org/walker/-/walker-1.0.7.tgz",
|
||||
@@ -6483,12 +6407,6 @@
|
||||
"integrity": "sha512-A5CUptxDsvxKJEU3yO6DuWBSJz/qizqzJKOMIfUJHETbBw/sFaDxgd6fxm1ewUaM0jZ444Fc5vC5ROYurg/4Pw==",
|
||||
"dev": true
|
||||
},
|
||||
"xmlchars": {
|
||||
"version": "1.3.1",
|
||||
"resolved": "https://registry.npmjs.org/xmlchars/-/xmlchars-1.3.1.tgz",
|
||||
"integrity": "sha512-tGkGJkN8XqCod7OT+EvGYK5Z4SfDQGD30zAa58OcnAa0RRWgzUEK72tkXhsX1FZd+rgnhRxFtmO+ihkp8LHSkw==",
|
||||
"dev": true
|
||||
},
|
||||
"xtend": {
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz",
|
||||
@@ -6586,9 +6504,9 @@
|
||||
}
|
||||
},
|
||||
"zigbee-shepherd-converters": {
|
||||
"version": "8.0.14",
|
||||
"resolved": "https://registry.npmjs.org/zigbee-shepherd-converters/-/zigbee-shepherd-converters-8.0.14.tgz",
|
||||
"integrity": "sha512-TjFjDZNpmmaG3FjDIGlQ1q+fEouVPBDrrtGIDkoWvlrg8MGkRlwBgJhRAHSJAASSw7g31WrpOikeOWfxo9Yreg==",
|
||||
"version": "8.1.0",
|
||||
"resolved": "https://registry.npmjs.org/zigbee-shepherd-converters/-/zigbee-shepherd-converters-8.1.0.tgz",
|
||||
"integrity": "sha512-N52XPeO0MLunx7bHr7ZgTQhyipNVxXaJrSZoTNIhxv+eAfPfJfeMZwpfHk2VnfBQmimFsgpYkEg1oV0TyDLfWg==",
|
||||
"requires": {
|
||||
"chai": "*",
|
||||
"debounce": "*",
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@
|
||||
"zcl-id": "git+https://github.com/Koenkk/zcl-id.git#4fa75c92424cd070a3bf6e1f4640b1e3ad8f802d",
|
||||
"ziee": "*",
|
||||
"zigbee-shepherd": "git+https://github.com/Koenkk/zigbee-shepherd.git#12c2e7f875e8ebccc3971736a4b684f86de9d79e",
|
||||
"zigbee-shepherd-converters": "8.0.14",
|
||||
"zigbee-shepherd-converters": "8.1.0",
|
||||
"zive": "*"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
+115
-27
@@ -153,6 +153,7 @@ describe('DevicePublish', () => {
|
||||
|
||||
it('Should publish messages to zigbee devices with color_temp', async () => {
|
||||
zigbee.publish.mockClear();
|
||||
publishEntityState.mockClear();
|
||||
zigbee.getDevice = () => ({modelId: 'TRADFRI bulb E27 WS opal 980lm'});
|
||||
devicePublish.onMQTTMessage('zigbee2mqtt/0x00000005/set', JSON.stringify({color_temp: '222'}));
|
||||
expect(zigbee.publish).toHaveBeenCalledTimes(1);
|
||||
@@ -162,10 +163,14 @@ describe('DevicePublish', () => {
|
||||
'lightingColorCtrl',
|
||||
'moveToColorTemp',
|
||||
'functional',
|
||||
{colortemp: '222', transtime: 0},
|
||||
{colortemp: 222, transtime: 0},
|
||||
cfg.default,
|
||||
null,
|
||||
expect.any(Function));
|
||||
expect(publishEntityState).toHaveBeenCalledTimes(1);
|
||||
expect(publishEntityState).toHaveBeenNthCalledWith(1,
|
||||
'0x00000005',
|
||||
{color_temp: 222});
|
||||
await wait(10);
|
||||
expect(zigbee.publish).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
@@ -182,11 +187,14 @@ describe('DevicePublish', () => {
|
||||
'lightingColorCtrl',
|
||||
'moveToColorTemp',
|
||||
'functional',
|
||||
{colortemp: '500', transtime: 0},
|
||||
{colortemp: 500, transtime: 0},
|
||||
cfg.default,
|
||||
null,
|
||||
expect.any(Function));
|
||||
expect(publishEntityState).toHaveBeenCalledTimes(0);
|
||||
expect(publishEntityState).toHaveBeenCalledTimes(1);
|
||||
expect(publishEntityState).toHaveBeenNthCalledWith(1,
|
||||
'0x00000006',
|
||||
{color_temp: 500});
|
||||
await wait(10);
|
||||
expect(zigbee.publish).toHaveBeenCalledTimes(2);
|
||||
}
|
||||
@@ -194,6 +202,7 @@ describe('DevicePublish', () => {
|
||||
|
||||
it('Should publish messages to zigbee devices with non-default ep', async () => {
|
||||
zigbee.publish.mockClear();
|
||||
publishEntityState.mockClear();
|
||||
zigbee.getDevice = () => ({modelId: 'lumi.ctrl_neutral1'});
|
||||
devicePublish.onMQTTMessage('zigbee2mqtt/0x00000007/set', JSON.stringify({state: 'OFF'}));
|
||||
expect(zigbee.publish).toHaveBeenCalledTimes(1);
|
||||
@@ -207,6 +216,10 @@ describe('DevicePublish', () => {
|
||||
cfg.default,
|
||||
2,
|
||||
expect.any(Function));
|
||||
expect(publishEntityState).toHaveBeenCalledTimes(1);
|
||||
expect(publishEntityState).toHaveBeenNthCalledWith(1,
|
||||
'0x00000007',
|
||||
{state: 'OFF'});
|
||||
await wait(10);
|
||||
expect(zigbee.publish).toHaveBeenCalledTimes(1);
|
||||
}
|
||||
@@ -288,6 +301,7 @@ describe('DevicePublish', () => {
|
||||
|
||||
it('Should publish messages to zigbee devices with color xy', async () => {
|
||||
zigbee.publish.mockClear();
|
||||
publishEntityState.mockClear();
|
||||
zigbee.getDevice = () => ({modelId: 'TRADFRI bulb E27 CWS opal 600lm'});
|
||||
devicePublish.onMQTTMessage('zigbee2mqtt/0x00000011/set', JSON.stringify({color: {x: 100, y: 50}}));
|
||||
expect(zigbee.publish).toHaveBeenCalledTimes(1);
|
||||
@@ -303,6 +317,10 @@ describe('DevicePublish', () => {
|
||||
expect.any(Function));
|
||||
await wait(10);
|
||||
expect(zigbee.publish).toHaveBeenCalledTimes(2);
|
||||
expect(publishEntityState).toHaveBeenCalledTimes(1);
|
||||
expect(publishEntityState).toHaveBeenNthCalledWith(1,
|
||||
'0x00000011',
|
||||
{color: {x: 100, y: 50}});
|
||||
});
|
||||
|
||||
it('Should publish messages to zigbee devices with color xy and state', async () => {
|
||||
@@ -332,10 +350,13 @@ describe('DevicePublish', () => {
|
||||
cfg.default,
|
||||
null,
|
||||
expect.any(Function));
|
||||
expect(publishEntityState).toHaveBeenCalledTimes(1);
|
||||
expect(publishEntityState).toHaveBeenCalledTimes(2);
|
||||
expect(publishEntityState).toHaveBeenNthCalledWith(1,
|
||||
'0x00000012',
|
||||
{state: 'ON'});
|
||||
expect(publishEntityState).toHaveBeenNthCalledWith(2,
|
||||
'0x00000012',
|
||||
{color: {x: 100, y: 50}});
|
||||
await wait(10);
|
||||
expect(zigbee.publish).toHaveBeenCalledTimes(4);
|
||||
expect(zigbee.publish.mock.calls[2][2]).toBe('genLevelCtrl');
|
||||
@@ -372,12 +393,15 @@ describe('DevicePublish', () => {
|
||||
cfg.default,
|
||||
null,
|
||||
expect.any(Function));
|
||||
expect(publishEntityState).toHaveBeenCalledTimes(1);
|
||||
await wait(10);
|
||||
expect(zigbee.publish).toHaveBeenCalledTimes(4);
|
||||
expect(publishEntityState).toHaveBeenCalledTimes(2);
|
||||
expect(publishEntityState).toHaveBeenNthCalledWith(1,
|
||||
'0x00000013',
|
||||
{state: 'ON', brightness: 20});
|
||||
await wait(10);
|
||||
expect(zigbee.publish).toHaveBeenCalledTimes(4);
|
||||
expect(publishEntityState).toHaveBeenNthCalledWith(2,
|
||||
'0x00000013',
|
||||
{color: {x: 100, y: 50}});
|
||||
}
|
||||
);
|
||||
|
||||
@@ -408,12 +432,15 @@ describe('DevicePublish', () => {
|
||||
cfg.default,
|
||||
null,
|
||||
expect.any(Function));
|
||||
expect(publishEntityState).toHaveBeenCalledTimes(1);
|
||||
await wait(10);
|
||||
expect(zigbee.publish).toHaveBeenCalledTimes(4);
|
||||
expect(publishEntityState).toHaveBeenCalledTimes(2);
|
||||
expect(publishEntityState).toHaveBeenNthCalledWith(1,
|
||||
'0x00000014',
|
||||
{state: 'ON', brightness: 20});
|
||||
await wait(10);
|
||||
expect(zigbee.publish).toHaveBeenCalledTimes(4);
|
||||
expect(publishEntityState).toHaveBeenNthCalledWith(2,
|
||||
'0x00000014',
|
||||
{color: {x: 100, y: 50}});
|
||||
}
|
||||
);
|
||||
|
||||
@@ -444,10 +471,13 @@ describe('DevicePublish', () => {
|
||||
cfg.default,
|
||||
null,
|
||||
expect.any(Function));
|
||||
expect(publishEntityState).toHaveBeenCalledTimes(1);
|
||||
expect(publishEntityState).toHaveBeenCalledTimes(2);
|
||||
expect(publishEntityState).toHaveBeenNthCalledWith(1,
|
||||
'0x00000015',
|
||||
{state: 'OFF'});
|
||||
expect(publishEntityState).toHaveBeenNthCalledWith(2,
|
||||
'0x00000015',
|
||||
{color: {x: 100, y: 50}});
|
||||
await wait(10);
|
||||
expect(zigbee.publish).toHaveBeenCalledTimes(3);
|
||||
}
|
||||
@@ -455,6 +485,7 @@ describe('DevicePublish', () => {
|
||||
|
||||
it('Should publish messages to zigbee devices with color rgb', async () => {
|
||||
zigbee.publish.mockClear();
|
||||
publishEntityState.mockClear();
|
||||
zigbee.getDevice = () => ({modelId: 'TRADFRI bulb E27 CWS opal 600lm'});
|
||||
devicePublish.onMQTTMessage('zigbee2mqtt/0x00000016/set', JSON.stringify({color: {r: 100, g: 200, b: 10}}));
|
||||
expect(zigbee.publish).toHaveBeenCalledTimes(1);
|
||||
@@ -470,10 +501,15 @@ describe('DevicePublish', () => {
|
||||
expect.any(Function));
|
||||
await wait(10);
|
||||
expect(zigbee.publish).toHaveBeenCalledTimes(2);
|
||||
expect(publishEntityState).toHaveBeenCalledTimes(1);
|
||||
expect(publishEntityState).toHaveBeenNthCalledWith(1,
|
||||
'0x00000016',
|
||||
{color: {x: 0.2607, y: 0.6714}});
|
||||
});
|
||||
|
||||
it('Should publish messages to zigbee devices with color rgb string', async () => {
|
||||
zigbee.publish.mockClear();
|
||||
publishEntityState.mockClear();
|
||||
zigbee.getDevice = () => ({modelId: 'TRADFRI bulb E27 CWS opal 600lm'});
|
||||
devicePublish.onMQTTMessage('zigbee2mqtt/0x00000017/set', JSON.stringify({color: {rgb: '100,200,10'}}));
|
||||
expect(zigbee.publish).toHaveBeenCalledTimes(1);
|
||||
@@ -489,6 +525,10 @@ describe('DevicePublish', () => {
|
||||
expect.any(Function));
|
||||
await wait(10);
|
||||
expect(zigbee.publish).toHaveBeenCalledTimes(2);
|
||||
expect(publishEntityState).toHaveBeenCalledTimes(1);
|
||||
expect(publishEntityState).toHaveBeenNthCalledWith(1,
|
||||
'0x00000017',
|
||||
{color: {x: 0.2607, y: 0.6714}});
|
||||
}
|
||||
);
|
||||
|
||||
@@ -612,6 +652,54 @@ describe('DevicePublish', () => {
|
||||
await wait(10);
|
||||
expect(zigbee.publish).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('Should publish messages to groups color', async () => {
|
||||
jest.spyOn(settings, 'getGroupIDByFriendlyName').mockReturnValue('1');
|
||||
zigbee.publish.mockClear();
|
||||
publishEntityState.mockClear();
|
||||
devicePublish.onMQTTMessage('zigbee2mqtt/group/group_1/set', JSON.stringify({color: {x: 0.37, y: 0.28}}));
|
||||
expect(zigbee.publish).toHaveBeenCalledTimes(1);
|
||||
expect(zigbee.publish).toHaveBeenNthCalledWith(1,
|
||||
1,
|
||||
'group',
|
||||
'lightingColorCtrl',
|
||||
'moveToColor',
|
||||
'functional',
|
||||
{colorx: 24248, colory: 18350, transtime: 0},
|
||||
cfg.default,
|
||||
null,
|
||||
expect.any(Function));
|
||||
expect(publishEntityState).toHaveBeenCalledTimes(1);
|
||||
expect(publishEntityState).toHaveBeenNthCalledWith(1,
|
||||
1,
|
||||
{color: {x: 0.37, y: 0.28}});
|
||||
await wait(10);
|
||||
expect(zigbee.publish).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('Should publish messages to groups color temperature', async () => {
|
||||
jest.spyOn(settings, 'getGroupIDByFriendlyName').mockReturnValue('1');
|
||||
zigbee.publish.mockClear();
|
||||
publishEntityState.mockClear();
|
||||
devicePublish.onMQTTMessage('zigbee2mqtt/group/group_1/set', JSON.stringify({color_temp: 100}));
|
||||
expect(zigbee.publish).toHaveBeenCalledTimes(1);
|
||||
expect(zigbee.publish).toHaveBeenNthCalledWith(1,
|
||||
1,
|
||||
'group',
|
||||
'lightingColorCtrl',
|
||||
'moveToColorTemp',
|
||||
'functional',
|
||||
{colortemp: 100, transtime: 0},
|
||||
cfg.default,
|
||||
null,
|
||||
expect.any(Function));
|
||||
expect(publishEntityState).toHaveBeenCalledTimes(1);
|
||||
expect(publishEntityState).toHaveBeenNthCalledWith(1,
|
||||
1,
|
||||
{color_temp: 100});
|
||||
await wait(10);
|
||||
expect(zigbee.publish).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Parse topic', () => {
|
||||
@@ -825,7 +913,7 @@ describe('DevicePublish', () => {
|
||||
expect(zigbee.publish).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it('Should turn device of when brightness 0 is send', async () => {
|
||||
it('Should turn device off when brightness 0 is send', async () => {
|
||||
zigbee.publish.mockClear();
|
||||
publishEntityState.mockClear();
|
||||
zigbee.getDevice = () => ({modelId: 'TRADFRI bulb E27 CWS opal 600lm'});
|
||||
@@ -983,11 +1071,10 @@ describe('DevicePublish', () => {
|
||||
null,
|
||||
expect.any(Function));
|
||||
|
||||
// TODO
|
||||
// expect(publishEntityState).toHaveBeenCalledTimes(1);
|
||||
// expect(publishEntityState).toHaveBeenNthCalledWith(1,
|
||||
// '0x00000001',
|
||||
// {state: 'ON', brightness: 100});
|
||||
expect(publishEntityState).toHaveBeenCalledTimes(1);
|
||||
expect(publishEntityState).toHaveBeenNthCalledWith(1,
|
||||
'0x00000001',
|
||||
{color_temp: 100});
|
||||
});
|
||||
|
||||
it('Home Assistant: should not set state when color is also set', async () => {
|
||||
@@ -1012,11 +1099,10 @@ describe('DevicePublish', () => {
|
||||
null,
|
||||
expect.any(Function));
|
||||
|
||||
// TODO
|
||||
// expect(publishEntityState).toHaveBeenCalledTimes(1);
|
||||
// expect(publishEntityState).toHaveBeenNthCalledWith(1,
|
||||
// '0x00000001',
|
||||
// {state: 'ON', brightness: 100});
|
||||
expect(publishEntityState).toHaveBeenCalledTimes(1);
|
||||
expect(publishEntityState).toHaveBeenNthCalledWith(1,
|
||||
'0x00000001',
|
||||
{color: {x: 0.41, y: 0.25}});
|
||||
});
|
||||
|
||||
it('Home Assistant: should set state when color is also set and bulb is off', async () => {
|
||||
@@ -1051,10 +1137,12 @@ describe('DevicePublish', () => {
|
||||
null,
|
||||
expect.any(Function));
|
||||
|
||||
// TODO
|
||||
// expect(publishEntityState).toHaveBeenCalledTimes(1);
|
||||
// expect(publishEntityState).toHaveBeenNthCalledWith(1,
|
||||
// '0x00000001',
|
||||
// {state: 'ON', brightness: 100});
|
||||
expect(publishEntityState).toHaveBeenCalledTimes(2);
|
||||
expect(publishEntityState).toHaveBeenNthCalledWith(1,
|
||||
'0x00000001',
|
||||
{state: 'ON'});
|
||||
expect(publishEntityState).toHaveBeenNthCalledWith(2,
|
||||
'0x00000001',
|
||||
{color: {x: 0.41, y: 0.25}});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user