mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2026-08-28 05:24:29 +00:00
Allow to redefine device icon (#7013)
* Device-specific icon * Updated tests. * Updated test * Updated tests * Updated tests. * Updated tests Co-authored-by: ptvoinfo <xagga@ya.ru>
This commit is contained in:
@@ -654,7 +654,13 @@ class Bridge extends Extension {
|
||||
|
||||
getDefinitionPayload(definition, resolvedDevice) {
|
||||
if (definition) {
|
||||
let icon = definition.icon;
|
||||
let icon = null;
|
||||
if (resolvedDevice && resolvedDevice.hasOwnProperty('settings')) {
|
||||
icon = resolvedDevice.settings.icon;
|
||||
}
|
||||
if (!icon) {
|
||||
icon = definition.icon;
|
||||
}
|
||||
if (icon) {
|
||||
let zigbeeModel = '';
|
||||
/* istanbul ignore else */
|
||||
|
||||
+7
-1
@@ -1055,6 +1055,7 @@ describe('Bridge', () => {
|
||||
|
||||
const definition = {'model': 'lumi.plug'};
|
||||
const device = zigbeeHerdsman.devices.ZNCZ02LM;
|
||||
const svg_icon = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDo';
|
||||
const icon_link = 'https://www.zigbee2mqtt.io/images/devices/ZNCZ02LM.jpg';
|
||||
definition.icon = icon_link;
|
||||
let payload = bridge.getDefinitionPayload(definition, {device: device});
|
||||
@@ -1062,6 +1063,12 @@ describe('Bridge', () => {
|
||||
expect(payload['icon']).not.toBeUndefined()
|
||||
expect(payload.icon).toBe(icon_link);
|
||||
|
||||
definition.icon = icon_link;
|
||||
payload = bridge.getDefinitionPayload(definition, {device: device, settings: {icon: svg_icon}});
|
||||
expect(payload).not.toBeUndefined()
|
||||
expect(payload['icon']).not.toBeUndefined()
|
||||
expect(payload.icon).toBe(svg_icon);
|
||||
|
||||
definition.icon = '_${model}_';
|
||||
payload = bridge.getDefinitionPayload(definition, {device: device});
|
||||
expect(payload).not.toBeUndefined()
|
||||
@@ -1074,7 +1081,6 @@ describe('Bridge', () => {
|
||||
expect(payload['icon']).not.toBeUndefined()
|
||||
expect(payload.icon).toBe('_lumi.plug_lumi.plug_');
|
||||
|
||||
const svg_icon = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDo';
|
||||
definition.icon = svg_icon;
|
||||
payload = bridge.getDefinitionPayload(definition, {device: device});
|
||||
expect(payload).not.toBeUndefined()
|
||||
|
||||
Reference in New Issue
Block a user