Skip to content

Commit 06e32a1

Browse files
committed
Allow unquoted on/off YAML booleans in LED mode config
1 parent 41931c4 commit 06e32a1

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,8 @@ zha:
6060
tx_power:
6161

6262
# Only if your stick has a controllable LED (the CC2531)
63-
# If set, must be one of: "off", "on", blink, flash, toggle
64-
# Note: "off" and "on" must be quoted!
65-
led_mode: "off"
63+
# If set, must be one of: off, on, blink, flash, toggle
64+
led_mode: off
6665

6766

6867
### Internal configuration, there's no reason to touch these values

tests/api/test_request.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ async def test_znp_sreq_srsp(connected_znp, event_loop):
262262

263263
# Each SREQ must have a corresponding SRSP, so this will fail
264264
with pytest.raises(asyncio.TimeoutError):
265-
with async_timeout.timeout(0.5):
265+
async with async_timeout.timeout(0.5):
266266
await znp.request(c.SYS.Ping.Req())
267267

268268
# This will work

tests/application/test_startup.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,12 @@ async def test_tx_power(device, succeed, make_application):
205205
await app.shutdown()
206206

207207

208+
@pytest.mark.parametrize("led_mode", ["off", False, "on", True])
208209
@pytest.mark.parametrize("device", FORMED_DEVICES)
209-
async def test_led_mode(device, make_application):
210+
async def test_led_mode(device, led_mode, make_application):
210211
app, znp_server = make_application(
211212
server_cls=device,
212-
client_config={conf.CONF_ZNP_CONFIG: {conf.CONF_LED_MODE: "off"}},
213+
client_config={conf.CONF_ZNP_CONFIG: {conf.CONF_LED_MODE: led_mode}},
213214
)
214215

215216
# Z-Stack just does not respond to this command if HAL_LED is not enabled
@@ -224,7 +225,11 @@ async def test_led_mode(device, make_application):
224225
await app.startup(auto_form=False)
225226
led_req = await set_led_mode
226227

227-
assert led_req.Mode == c.util.LEDMode.OFF
228+
if led_mode in ("off", False):
229+
assert led_req.Mode == c.util.LEDMode.OFF
230+
else:
231+
assert led_req.Mode == c.util.LEDMode.ON
232+
228233
assert led_req.LED == 0xFF
229234

230235
await app.shutdown()

zigpy_znp/config.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,19 @@ def validator(config):
6262
return validator
6363

6464

65+
def bool_to_upper_str(value: typing.Any) -> str:
66+
"""
67+
Converts the value into an uppercase string, including unquoted YAML booleans.
68+
"""
69+
70+
if value is True:
71+
return "ON"
72+
elif value is False:
73+
return "OFF"
74+
else:
75+
return str(value).upper()
76+
77+
6578
CONF_ZNP_CONFIG = "znp_config"
6679
CONF_TX_POWER = "tx_power"
6780
CONF_LED_MODE = "led_mode"
@@ -89,7 +102,7 @@ def validator(config):
89102
): VolPositiveNumber,
90103
vol.Optional(CONF_SKIP_BOOTLOADER, default=True): cv_boolean,
91104
vol.Optional(CONF_LED_MODE, default=LEDMode.OFF): vol.Any(
92-
None, EnumValue(LEDMode, lambda v: str(v).upper())
105+
None, EnumValue(LEDMode, transformer=bool_to_upper_str)
93106
),
94107
vol.Optional(CONF_MAX_CONCURRENT_REQUESTS, default="auto"): vol.Any(
95108
"auto", VolPositiveNumber

0 commit comments

Comments
 (0)