()
| 261 | } |
| 262 | |
| 263 | export function validate(): string[] { |
| 264 | getPersistedSettings(); |
| 265 | |
| 266 | if (!ajvSetting(_settings)) { |
| 267 | // biome-ignore lint/style/noNonNullAssertion: When `ajvSetting()` return false it always has `errors` |
| 268 | return ajvSetting.errors!.map((v) => `${v.instancePath.substring(1)} ${v.message}`); |
| 269 | } |
| 270 | |
| 271 | const errors = []; |
| 272 | |
| 273 | if (_settings.advanced?.network_key && typeof _settings.advanced.network_key === "string" && _settings.advanced.network_key !== "GENERATE") { |
| 274 | errors.push(`advanced.network_key: should be array or 'GENERATE' (is '${_settings.advanced.network_key}')`); |
| 275 | } |
| 276 | |
| 277 | if (_settings.advanced?.pan_id && typeof _settings.advanced.pan_id === "string" && _settings.advanced.pan_id !== "GENERATE") { |
| 278 | errors.push(`advanced.pan_id: should be number or 'GENERATE' (is '${_settings.advanced.pan_id}')`); |
| 279 | } |
| 280 | |
| 281 | if (_settings.advanced?.ext_pan_id && typeof _settings.advanced.ext_pan_id === "string" && _settings.advanced.ext_pan_id !== "GENERATE") { |
| 282 | errors.push(`advanced.ext_pan_id: should be array or 'GENERATE' (is '${_settings.advanced.ext_pan_id}')`); |
| 283 | } |
| 284 | |
| 285 | // Verify that all friendly names are unique |
| 286 | const names: string[] = []; |
| 287 | const check = (e: DeviceOptions | GroupOptions): void => { |
| 288 | if (names.includes(e.friendly_name)) errors.push(`Duplicate friendly_name '${e.friendly_name}' found`); |
| 289 | errors.push(...utils.validateFriendlyName(e.friendly_name)); |
| 290 | names.push(e.friendly_name); |
| 291 | if ("icon" in e && e.icon && !e.icon.startsWith("http://") && !e.icon.startsWith("https://") && !e.icon.startsWith("device_icons/")) { |
| 292 | errors.push(`Device icon of '${e.friendly_name}' should start with 'device_icons/', got '${e.icon}'`); |
| 293 | } |
| 294 | }; |
| 295 | |
| 296 | const settingsWithDefaults = get(); |
| 297 | |
| 298 | for (const key in settingsWithDefaults.devices) { |
| 299 | check(settingsWithDefaults.devices[key]); |
| 300 | } |
| 301 | |
| 302 | for (const key in settingsWithDefaults.groups) { |
| 303 | check(settingsWithDefaults.groups[key]); |
| 304 | } |
| 305 | |
| 306 | if (settingsWithDefaults.mqtt.version !== 5) { |
| 307 | for (const device of Object.values(settingsWithDefaults.devices)) { |
| 308 | if (device.retention) { |
| 309 | errors.push("MQTT retention requires protocol version 5"); |
| 310 | } |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | return errors; |
| 315 | } |
| 316 | |
| 317 | export function validateNonRequired(): string[] { |
| 318 | getPersistedSettings(); |
nothing calls this directly
no test coverage detected