Allow string values for permit_join call. https://github.com/Koenkk/zigbee2mqtt/issues/5644

This commit is contained in:
Koen Kanters 2021-01-10 16:54:01 +01:00
parent 8026dde26a
commit 19c54040bc
2 changed files with 16 additions and 0 deletions

View File

@ -185,6 +185,10 @@ class Bridge extends Extension {
value = message; value = message;
} }
if (typeof value === 'string') {
value = value.toLowerCase() === 'true';
}
await this.zigbee.permitJoin(value, resolvedEntity, time); await this.zigbee.permitJoin(value, resolvedEntity, time);
const response = {value}; const response = {value};
if (resolvedEntity) response.device = message.device; if (resolvedEntity) response.device = message.device;

View File

@ -219,6 +219,18 @@ describe('Bridge', () => {
{retain: false, qos: 0}, expect.any(Function) {retain: false, qos: 0}, expect.any(Function)
); );
zigbeeHerdsman.permitJoin.mockClear();
MQTT.publish.mockClear();
MQTT.events.message('zigbee2mqtt/bridge/request/permit_join', stringify({"value": "False"}));
await flushPromises();
expect(zigbeeHerdsman.permitJoin).toHaveBeenCalledTimes(1);
expect(zigbeeHerdsman.permitJoin).toHaveBeenCalledWith(false, undefined, undefined);
expect(MQTT.publish).toHaveBeenCalledWith(
'zigbee2mqtt/bridge/response/permit_join',
stringify({"data":{"value":false},"status":"ok"}),
{retain: false, qos: 0}, expect.any(Function)
);
// Invalid payload // Invalid payload
zigbeeHerdsman.permitJoin.mockClear(); zigbeeHerdsman.permitJoin.mockClear();
MQTT.publish.mockClear(); MQTT.publish.mockClear();