refactor(unas): replace disable flag with enable, defaulting to off

`disable = false` is a double negative, and a bool named disable cannot
express opt-in anyway: it zero-values to false, so the flag was inert and
opt-in rested entirely on the device list being empty.

`enable` defaults to false and is now the real gate -- Initialize, Metrics
and DebugInput all return early unless it is set. The two existing guards
remain: an empty device list is still a no-op, and no default URL is ever
synthesized.

Configuring devices while enable is false is always a mistake, so that
combination logs one error instead of silently collecting nothing.

Adds binding tests for the flag across toml, json, yaml and UP_UNAS_ENABLE
(the env name derives from the xml tag, not the json one), plus a test that
all three shipped examples default to off. Both were verified by mutation:
breaking a struct tag or flipping an example fails the suite.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Cody Lee
2026-08-19 09:34:02 -05:00
co-authored by Claude Opus 5
parent 3d178bed8d
commit 01ac7ca2b7
8 changed files with 129 additions and 37 deletions
+3 -3
View File
@@ -275,13 +275,13 @@
# A UNAS Pro is a standalone UniFi OS console with no Network application, so it is polled
# by its own input plugin with its own credentials and host -- not as a UniFi controller.
#
# This section is entirely optional and does nothing unless you add at least one
# [[unas.device]] below: with no devices configured the plugin stays silent and inert.
# This section is entirely optional. The plugin is off unless you set enable = true and
# add at least one [[unas.device]] below; otherwise it stays silent and inert.
# Metrics land under the unifi_unas_ prefix in Prometheus, and in the unas_device,
# unas_pool, unas_disk, and unas_share measurements in InfluxDB.
#
#[unas]
# disable = false
# enable = true
#
# Defaults applied to every device that does not set its own value.
#[unas.defaults]
+2 -2
View File
@@ -87,8 +87,8 @@
},
"unas": {
"//": "UNAS Pro consoles. JSON cannot carry comments, so this section ships disabled: it shows the shape, and flipping disable to false with a real url turns it on.",
"disable": true,
"//": "UNAS Pro consoles. JSON cannot carry comments, so this section ships off: it shows the shape, and setting enable to true with a real url turns it on.",
"enable": false,
"defaults": {
"user": "unpoller",
"pass": "",
+1 -1
View File
@@ -91,7 +91,7 @@ unifi:
# by its own input plugin with its own credentials and host -- not as a UniFi controller.
# This section is optional: with no devices configured the plugin stays silent and inert.
#unas:
# disable: false
# enable: true
# defaults:
# user: "unpoller"
# pass: ""