parsePowerSection function
Parses the power: yaml section (sleepPrevention level + hold
lifecycle). A null node means the section is absent — the CALLER
applies the defaults (level idle, hold per-run; "not configured"
and "explicitly off" stay distinct). Any present-but-invalid shape,
value or key throws ConfigException, consistent with the other
strict config sections.
Implementation
PowerSection parsePowerSection(Object? node) {
if (node == null) return const PowerSection();
if (node is! Map) {
throw ConfigException('power must be a map, got: $node');
}
PowerAssertionLevel? level;
PowerAssertionHold? hold;
for (final key in node.keys) {
switch ('$key') {
case 'sleepPrevention':
final value = '${node[key]}'.trim();
level = PowerAssertionLevel.fromValue(value);
if (level == null) {
throw ConfigException(
'"power.sleepPrevention" must be off, idle, display or system, '
'got: $value',
);
}
case 'hold':
final value = '${node[key]}'.trim();
hold = PowerAssertionHold.fromValue(value);
if (hold == null) {
throw ConfigException(
'"power.hold" must be per-run or session, got: $value',
);
}
default:
throw ConfigException('unknown "power" key: $key');
}
}
return PowerSection(sleepPrevention: level, hold: hold);
}