mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2024-11-16 02:18:31 -07:00
Make retain a optional option and default it to false.
This commit is contained in:
parent
23cf8eade9
commit
af770acd2d
@ -263,7 +263,7 @@ class Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
retain: entity.settings.retain,
|
retain: entity.settings.hasOwnProperty('retain') ? entity.settings.retain : false,
|
||||||
qos: entity.settings.hasOwnProperty('qos') ? entity.settings.qos : 0,
|
qos: entity.settings.hasOwnProperty('qos') ? entity.settings.qos : 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -205,7 +205,7 @@ const schema = {
|
|||||||
retain: {type: 'boolean'},
|
retain: {type: 'boolean'},
|
||||||
qos: {type: 'number'},
|
qos: {type: 'number'},
|
||||||
},
|
},
|
||||||
required: ['friendly_name', 'retain'],
|
required: ['friendly_name'],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -224,7 +224,7 @@ const schema = {
|
|||||||
optimistic: {type: 'boolean'},
|
optimistic: {type: 'boolean'},
|
||||||
qos: {type: 'number'},
|
qos: {type: 'number'},
|
||||||
},
|
},
|
||||||
required: ['friendly_name', 'retain'],
|
required: ['friendly_name'],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -447,7 +447,7 @@ function addDevice(ID) {
|
|||||||
settings.devices = {};
|
settings.devices = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
settings.devices[ID] = {friendly_name: ID, retain: false};
|
settings.devices[ID] = {friendly_name: ID};
|
||||||
write();
|
write();
|
||||||
return getDevice(ID);
|
return getDevice(ID);
|
||||||
}
|
}
|
||||||
@ -507,7 +507,7 @@ function addGroup(name, ID=null) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
settings.groups[ID] = {friendly_name: name, retain: false};
|
settings.groups[ID] = {friendly_name: name};
|
||||||
write();
|
write();
|
||||||
|
|
||||||
return getGroup(ID);
|
return getGroup(ID);
|
||||||
|
@ -205,7 +205,7 @@ describe('Bridge config', () => {
|
|||||||
zigbeeHerdsman.createGroup.mockClear();
|
zigbeeHerdsman.createGroup.mockClear();
|
||||||
MQTT.events.message('zigbee2mqtt/bridge/config/add_group', 'new_group');
|
MQTT.events.message('zigbee2mqtt/bridge/config/add_group', 'new_group');
|
||||||
await flushPromises();
|
await flushPromises();
|
||||||
expect(settings.getGroup('new_group')).toStrictEqual({"ID": 3, "friendlyName": "new_group", "friendly_name": "new_group", "retain": false, devices: [], optimistic: true});
|
expect(settings.getGroup('new_group')).toStrictEqual({"ID": 3, "friendlyName": "new_group", "friendly_name": "new_group", devices: [], optimistic: true});
|
||||||
expect(zigbeeHerdsman.createGroup).toHaveBeenCalledTimes(1);
|
expect(zigbeeHerdsman.createGroup).toHaveBeenCalledTimes(1);
|
||||||
expect(zigbeeHerdsman.createGroup).toHaveBeenCalledWith(3)
|
expect(zigbeeHerdsman.createGroup).toHaveBeenCalledWith(3)
|
||||||
});
|
});
|
||||||
@ -214,7 +214,7 @@ describe('Bridge config', () => {
|
|||||||
zigbeeHerdsman.createGroup.mockClear();
|
zigbeeHerdsman.createGroup.mockClear();
|
||||||
MQTT.events.message('zigbee2mqtt/bridge/config/add_group', '{"friendly_name": "new_group"}');
|
MQTT.events.message('zigbee2mqtt/bridge/config/add_group', '{"friendly_name": "new_group"}');
|
||||||
await flushPromises();
|
await flushPromises();
|
||||||
expect(settings.getGroup('new_group')).toStrictEqual({"ID": 3, "friendlyName": "new_group", "friendly_name": "new_group", "retain": false, devices: [], optimistic: true});
|
expect(settings.getGroup('new_group')).toStrictEqual({"ID": 3, "friendlyName": "new_group", "friendly_name": "new_group", devices: [], optimistic: true});
|
||||||
expect(zigbeeHerdsman.createGroup).toHaveBeenCalledTimes(1);
|
expect(zigbeeHerdsman.createGroup).toHaveBeenCalledTimes(1);
|
||||||
expect(zigbeeHerdsman.createGroup).toHaveBeenCalledWith(3)
|
expect(zigbeeHerdsman.createGroup).toHaveBeenCalledWith(3)
|
||||||
});
|
});
|
||||||
@ -223,7 +223,7 @@ describe('Bridge config', () => {
|
|||||||
zigbeeHerdsman.createGroup.mockClear();
|
zigbeeHerdsman.createGroup.mockClear();
|
||||||
MQTT.events.message('zigbee2mqtt/bridge/config/add_group', '{"friendly_name": "new_group", "id": 42}');
|
MQTT.events.message('zigbee2mqtt/bridge/config/add_group', '{"friendly_name": "new_group", "id": 42}');
|
||||||
await flushPromises();
|
await flushPromises();
|
||||||
expect(settings.getGroup('new_group')).toStrictEqual({"ID": 42, "friendlyName": "new_group", "friendly_name": "new_group", "retain": false, devices: [], optimistic: true});
|
expect(settings.getGroup('new_group')).toStrictEqual({"ID": 42, "friendlyName": "new_group", "friendly_name": "new_group", devices: [], optimistic: true});
|
||||||
expect(zigbeeHerdsman.createGroup).toHaveBeenCalledTimes(1);
|
expect(zigbeeHerdsman.createGroup).toHaveBeenCalledTimes(1);
|
||||||
expect(zigbeeHerdsman.createGroup).toHaveBeenCalledWith(42)
|
expect(zigbeeHerdsman.createGroup).toHaveBeenCalledWith(42)
|
||||||
});
|
});
|
||||||
@ -232,7 +232,7 @@ describe('Bridge config', () => {
|
|||||||
zigbeeHerdsman.createGroup.mockClear();
|
zigbeeHerdsman.createGroup.mockClear();
|
||||||
MQTT.events.message('zigbee2mqtt/bridge/config/add_group', '{"id": 42}');
|
MQTT.events.message('zigbee2mqtt/bridge/config/add_group', '{"id": 42}');
|
||||||
await flushPromises();
|
await flushPromises();
|
||||||
expect(settings.getGroup('group_42')).toStrictEqual({"ID": 42, "friendlyName": "group_42", "friendly_name": "group_42", "retain": false, devices: [], optimistic: true});
|
expect(settings.getGroup('group_42')).toStrictEqual({"ID": 42, "friendlyName": "group_42", "friendly_name": "group_42", devices: [], optimistic: true});
|
||||||
expect(zigbeeHerdsman.createGroup).toHaveBeenCalledTimes(1);
|
expect(zigbeeHerdsman.createGroup).toHaveBeenCalledTimes(1);
|
||||||
expect(zigbeeHerdsman.createGroup).toHaveBeenCalledWith(42)
|
expect(zigbeeHerdsman.createGroup).toHaveBeenCalledWith(42)
|
||||||
});
|
});
|
||||||
|
@ -238,7 +238,7 @@ describe('Controller', () => {
|
|||||||
const payload = {device, endpoint: device.getEndpoint(1), type: 'attributeReport', linkquality: 10, groupID: 0, cluster: 'genBasic', data: {modelId: device.modelID}};
|
const payload = {device, endpoint: device.getEndpoint(1), type: 'attributeReport', linkquality: 10, groupID: 0, cluster: 'genBasic', data: {modelId: device.modelID}};
|
||||||
await zigbeeHerdsman.events.message(payload);
|
await zigbeeHerdsman.events.message(payload);
|
||||||
await flushPromises();
|
await flushPromises();
|
||||||
expect(settings.getDevice(device.ieeeAddr)).toStrictEqual({"ID": "0x0017880104e45519", "friendlyName": "0x0017880104e45519", "friendly_name": "0x0017880104e45519", "retain": false});
|
expect(settings.getDevice(device.ieeeAddr)).toStrictEqual({"ID": "0x0017880104e45519", "friendlyName": "0x0017880104e45519", "friendly_name": "0x0017880104e45519"});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('On zigbee deviceJoined', async () => {
|
it('On zigbee deviceJoined', async () => {
|
||||||
|
@ -55,7 +55,6 @@ describe('Settings', () => {
|
|||||||
devices: {
|
devices: {
|
||||||
'0x12345678': {
|
'0x12345678': {
|
||||||
friendly_name: '0x12345678',
|
friendly_name: '0x12345678',
|
||||||
retain: false,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -178,7 +177,6 @@ describe('Settings', () => {
|
|||||||
},
|
},
|
||||||
'0x1234': {
|
'0x1234': {
|
||||||
friendly_name: '0x1234',
|
friendly_name: '0x1234',
|
||||||
retain: false,
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -199,7 +197,6 @@ describe('Settings', () => {
|
|||||||
const expected = {
|
const expected = {
|
||||||
'0x1234': {
|
'0x1234': {
|
||||||
friendly_name: '0x1234',
|
friendly_name: '0x1234',
|
||||||
retain: false,
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -302,7 +299,6 @@ describe('Settings', () => {
|
|||||||
const expectedDevice = {
|
const expectedDevice = {
|
||||||
'0x1234': {
|
'0x1234': {
|
||||||
friendly_name: '0x1234',
|
friendly_name: '0x1234',
|
||||||
retain: false,
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -325,7 +321,6 @@ describe('Settings', () => {
|
|||||||
ID: '0x1234',
|
ID: '0x1234',
|
||||||
friendlyName: '0x1234',
|
friendlyName: '0x1234',
|
||||||
friendly_name: '0x1234',
|
friendly_name: '0x1234',
|
||||||
retain: false,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(settings.getDevice('0x1234')).toStrictEqual(expectedDevice2);
|
expect(settings.getDevice('0x1234')).toStrictEqual(expectedDevice2);
|
||||||
@ -338,7 +333,6 @@ describe('Settings', () => {
|
|||||||
const expected = {
|
const expected = {
|
||||||
'1': {
|
'1': {
|
||||||
friendly_name: 'test123',
|
friendly_name: 'test123',
|
||||||
retain: false,
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -352,7 +346,6 @@ describe('Settings', () => {
|
|||||||
const expected = {
|
const expected = {
|
||||||
'123': {
|
'123': {
|
||||||
friendly_name: 'test123',
|
friendly_name: 'test123',
|
||||||
retain: false,
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -369,7 +362,6 @@ describe('Settings', () => {
|
|||||||
const expected = {
|
const expected = {
|
||||||
'1': {
|
'1': {
|
||||||
friendly_name: 'test123',
|
friendly_name: 'test123',
|
||||||
retain: false,
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -386,7 +378,6 @@ describe('Settings', () => {
|
|||||||
const expected = {
|
const expected = {
|
||||||
'123': {
|
'123': {
|
||||||
friendly_name: 'test123',
|
friendly_name: 'test123',
|
||||||
retain: false,
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -408,7 +399,6 @@ describe('Settings', () => {
|
|||||||
const expected = {
|
const expected = {
|
||||||
'1': {
|
'1': {
|
||||||
friendly_name: 'test123',
|
friendly_name: 'test123',
|
||||||
retain: false,
|
|
||||||
devices: ['0x123'],
|
devices: ['0x123'],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user