Skip to content

Commit ecadda4

Browse files
NerivecKoenkk
andauthored
fix: Fix settings schema defaults (#27961)
Co-authored-by: Koen Kanters <[email protected]>
1 parent a837702 commit ecadda4

File tree

5 files changed

+60
-24
lines changed

5 files changed

+60
-24
lines changed

lib/util/settings.schema.json

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,8 @@
248248
"type": "number",
249249
"title": "Baudrate",
250250
"requiresRestart": true,
251-
"description": "Baud rate speed for serial port, this can be anything firmware support but default is 115200 for Z-Stack and EZSP, 38400 for Deconz, however note that some EZSP firmware need 57600",
252-
"examples": [38400, 57600, 115200]
251+
"description": "Baud rate speed for the serial port. This must match what the firmware on your adapter supports (most commonly 115200).",
252+
"examples": [115200, 921600, 460800, 230400, 57600, 38400]
253253
},
254254
"rtscts": {
255255
"type": "boolean",
@@ -291,38 +291,46 @@
291291
"type": "object",
292292
"properties": {
293293
"enddevice": {
294-
"type": "string"
294+
"type": "string",
295+
"default": "#fff8ce"
295296
},
296297
"coordinator": {
297-
"type": "string"
298+
"type": "string",
299+
"default": "#e04e5d"
298300
},
299301
"router": {
300-
"type": "string"
302+
"type": "string",
303+
"default": "#4ea3e0"
301304
}
302305
}
303306
},
304307
"font": {
305308
"type": "object",
306309
"properties": {
307310
"enddevice": {
308-
"type": "string"
311+
"type": "string",
312+
"default": "#000000"
309313
},
310314
"coordinator": {
311-
"type": "string"
315+
"type": "string",
316+
"default": "#ffffff"
312317
},
313318
"router": {
314-
"type": "string"
319+
"type": "string",
320+
"default": "#ffffff"
315321
}
316322
}
317323
},
318324
"line": {
319325
"type": "object",
320326
"properties": {
321327
"active": {
322-
"type": "string"
328+
"type": "string",
329+
"default": "#009900"
323330
},
324331
"inactive": {
325-
"type": "string"
332+
"type": "string",
333+
"default": "#994444"
326334
}
327335
}
328336
}
@@ -515,7 +523,8 @@
515523
"enum": ["console", "file", "syslog"]
516524
},
517525
"title": "Log output",
518-
"description": "Output location of the log, leave empty to suppress logging"
526+
"description": "Output location of the log, leave empty to suppress logging",
527+
"default": ["console", "file"]
519528
},
520529
"log_directory": {
521530
"type": "string",
@@ -530,7 +539,7 @@
530539
"requiresRestart": true,
531540
"description": "Log file name, can also contain timestamp",
532541
"examples": ["zigbee2mqtt_%TIMESTAMP%.log"],
533-
"default": "log.txt"
542+
"default": "log.log"
534543
},
535544
"log_level": {
536545
"type": "string",
@@ -659,7 +668,8 @@
659668
],
660669
"title": "Pan ID",
661670
"requiresRestart": true,
662-
"description": "ZigBee pan ID, changing requires re-pairing all devices!"
671+
"description": "ZigBee pan ID, changing requires re-pairing all devices!",
672+
"default": 6754
663673
},
664674
"ext_pan_id": {
665675
"oneOf": [
@@ -677,7 +687,8 @@
677687
],
678688
"title": "Ext Pan ID",
679689
"requiresRestart": true,
680-
"description": "Zigbee extended pan ID, changing requires re-pairing all devices!"
690+
"description": "Zigbee extended pan ID, changing requires re-pairing all devices!",
691+
"default": [221, 221, 221, 221, 221, 221, 221, 221]
681692
},
682693
"channel": {
683694
"type": "number",
@@ -695,6 +706,7 @@
695706
"type": ["number", "null"],
696707
"minimum": 1,
697708
"maximum": 64,
709+
"default": null,
698710
"description": "Adapter concurrency (e.g. 2 for CC2531 or 16 for CC26X2R1) (default: null, uses recommended value)"
699711
},
700712
"adapter_delay": {
@@ -703,6 +715,7 @@
703715
"title": "Adapter delay",
704716
"minimum": 0,
705717
"maximum": 1000,
718+
"default": null,
706719
"description": "Adapter delay"
707720
},
708721
"cache_state": {
@@ -752,14 +765,16 @@
752765
],
753766
"title": "Network key",
754767
"requiresRestart": true,
755-
"description": "Network encryption key, changing requires re-pairing all devices!"
768+
"description": "Network encryption key, changing requires re-pairing all devices!",
769+
"default": [1, 3, 5, 7, 9, 11, 13, 15, 0, 2, 4, 6, 8, 10, 12, 13]
756770
},
757771
"timestamp_format": {
758772
"type": "string",
759773
"title": "Timestamp format",
760774
"requiresRestart": true,
761775
"description": "Log timestamp format",
762-
"examples": ["YYYY-MM-DD HH:mm:ss"]
776+
"default": "YYYY-MM-DD HH:mm:ss",
777+
"examples": ["YYYY-MM-DD HH:mm:ss.SSS"]
763778
},
764779
"transmit_power": {
765780
"type": ["number", "null"],
@@ -773,7 +788,8 @@
773788
"type": "string",
774789
"enum": ["attribute_and_json", "attribute", "json"],
775790
"title": "MQTT output type",
776-
"description": "Examples when 'state' of a device is published json: topic: 'zigbee2mqtt/my_bulb' payload '{\"state\": \"ON\"}' attribute: topic 'zigbee2mqtt/my_bulb/state' payload 'ON' attribute_and_json: both json and attribute (see above)"
791+
"description": "Examples when 'state' of a device is published json: topic: 'zigbee2mqtt/my_bulb' payload '{\"state\": \"ON\"}' attribute: topic 'zigbee2mqtt/my_bulb/state' payload 'ON' attribute_and_json: both json and attribute (see above)",
792+
"default": "json"
777793
}
778794
}
779795
},
@@ -827,7 +843,8 @@
827843
"description": "Sets the MQTT Message Expiry in seconds, Make sure to set mqtt.version to 5"
828844
},
829845
"qos": {
830-
"type": "number",
846+
"type": ["number"],
847+
"enum": [0, 1, 2],
831848
"title": "QoS",
832849
"description": "QoS level for MQTT messages of this device"
833850
},
@@ -917,13 +934,16 @@
917934
"type": "boolean"
918935
},
919936
"qos": {
920-
"type": "number"
937+
"type": ["number"],
938+
"enum": [0, 1, 2],
939+
"title": "QoS",
940+
"description": "QoS level for MQTT messages of this group"
921941
},
922942
"off_state": {
923943
"type": ["string"],
924944
"enum": ["all_members_off", "last_member_state"],
925945
"title": "Group off state",
926-
"default": "auto",
946+
"default": "all_members_off",
927947
"requiresRestart": true,
928948
"description": "Control when to publish state OFF or CLOSE for a group. 'all_members_off': only publish state OFF/CLOSE when all group members are in state OFF/CLOSE, 'last_member_state': publish state OFF whenever one of its members changes to OFF"
929949
},

lib/util/settings.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ export const defaults = {
5252
force_disable_retain: false,
5353
// 1MB = roughly 3.5KB per device * 300 devices for `/bridge/devices`
5454
maximum_packet_size: 1048576,
55+
keepalive: 60,
56+
reject_unauthorized: true,
57+
version: 4,
5558
},
5659
serial: {
5760
disable_led: false,
@@ -295,9 +298,6 @@ export function validate(): string[] {
295298
if ("icon" in e && e.icon && !e.icon.startsWith("http://") && !e.icon.startsWith("https://") && !e.icon.startsWith("device_icons/")) {
296299
errors.push(`Device icon of '${e.friendly_name}' should start with 'device_icons/', got '${e.icon}'`);
297300
}
298-
if (e.qos != null && ![0, 1, 2].includes(e.qos)) {
299-
errors.push(`QOS for '${e.friendly_name}' not valid, should be 0, 1 or 2 got ${e.qos}`);
300-
}
301301
};
302302

303303
const settingsWithDefaults = get();

test/controller.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ describe("Controller", () => {
112112
expect(mockMQTTConnectAsync).toHaveBeenCalledWith("mqtt://localhost", {
113113
will: {payload: Buffer.from('{"state":"offline"}'), retain: true, topic: "zigbee2mqtt/bridge/state", qos: 1},
114114
properties: {maximumPacketSize: 1048576},
115+
keepalive: 60,
116+
protocolVersion: 4,
115117
});
116118
expect(mockMQTTPublishAsync).toHaveBeenCalledWith(
117119
"zigbee2mqtt/bulb",
@@ -1045,6 +1047,8 @@ describe("Controller", () => {
10451047
expect(mockMQTTConnectAsync).toHaveBeenCalledTimes(1);
10461048
const expected = {
10471049
will: {payload: Buffer.from('{"state":"offline"}'), retain: false, topic: "zigbee2mqtt/bridge/state", qos: 1},
1050+
keepalive: 60,
1051+
protocolVersion: 4,
10481052
properties: {maximumPacketSize: 1048576},
10491053
};
10501054
expect(mockMQTTConnectAsync).toHaveBeenCalledWith("mqtt://localhost", expected);

test/extensions/bridge.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,9 @@ describe("Extension: Bridge", () => {
309309
force_disable_retain: false,
310310
include_device_information: false,
311311
maximum_packet_size: 1048576,
312+
keepalive: 60,
313+
reject_unauthorized: true,
314+
version: 4,
312315
server: "mqtt://localhost",
313316
},
314317
ota: {

test/settings.test.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,9 @@ describe("Settings", () => {
312312
base_topic: "zigbee2mqtt",
313313
include_device_information: false,
314314
maximum_packet_size: 1048576,
315+
keepalive: 60,
316+
reject_unauthorized: true,
317+
version: 4,
315318
force_disable_retain: false,
316319
password: "mysecretpassword",
317320
server: "my.mqtt.server",
@@ -357,6 +360,9 @@ describe("Settings", () => {
357360
base_topic: "zigbee2mqtt",
358361
include_device_information: false,
359362
maximum_packet_size: 1048576,
363+
keepalive: 60,
364+
reject_unauthorized: true,
365+
version: 4,
360366
force_disable_retain: false,
361367
password: "mysecretpassword",
362368
server: "my.mqtt.server",
@@ -675,6 +681,9 @@ describe("Settings", () => {
675681
base_topic: "zigbee2mqtt",
676682
include_device_information: false,
677683
maximum_packet_size: 1048576,
684+
keepalive: 60,
685+
reject_unauthorized: true,
686+
version: 4,
678687
force_disable_retain: false,
679688
server: "my.mqtt.server",
680689
user: "myusername",
@@ -865,7 +874,7 @@ describe("Settings", () => {
865874

866875
settings.reRead();
867876

868-
const error = `QOS for 'myname' not valid, should be 0, 1 or 2 got 3`;
877+
const error = "devices/0x0017880104e45519/qos must be equal to one of the allowed values";
869878
expect(settings.validate()).toEqual(expect.arrayContaining([error]));
870879
});
871880

0 commit comments

Comments
 (0)