Skip to content

Commit fc3227f

Browse files
committed
fix: github runners does not have battery
1 parent 189fce1 commit fc3227f

File tree

5 files changed

+20
-12
lines changed

5 files changed

+20
-12
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ jobs:
7070
ansible-galaxy install -r requirements.yml
7171
7272
- name: Test the playbook.
73-
run: ansible-playbook tests/test.yml -vvv
73+
run: ansible-playbook tests/test.yml
7474
env:
7575
ANSIBLE_FORCE_COLOR: '1'
7676

library/pmset.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33

44
from ansible.module_utils.basic import AnsibleModule
55

6+
67
def parse_pmset_output(output):
78
# Parses `pmset -g custom` into a 2-level dict.
9+
section_name = ''
810
result = {}
911
for line in output.split('\n'):
10-
if line == '':
12+
if line == '' or 'Sleep On Power Button' in line:
1113
continue
1214
if line[0] != ' ' and line[-1] == ':':
1315
section_name = line[:-1]
@@ -37,21 +39,18 @@ def add_diff(block, param, old_value, new_value):
3739
result['diff']['after'] += '{block}.{param}={val}\n'.format(
3840
block=block, param=param, val=new_value)
3941

40-
blocks = [
41-
('on_battery', '-b', output['Battery Power']),
42-
('on_charger', '-c', output['AC Power']),
43-
]
42+
blocks = [('on_charger', '-c', output['AC Power']), ]
43+
44+
if 'Battery Power' in output:
45+
blocks.append(('on_battery', '-b', output['Battery Power']))
46+
4447
for block, mode_flag, current_values in blocks:
4548
# Iterate over user-specified parameters and check if there's anything
4649
# to change.
4750
for param, value in module.params[block].items():
4851
if value is None: continue
4952
if param not in current_values:
50-
module.fail_json(msg=(
51-
'{} is not present in pmset output. Run '
52-
'`pmset -g custom` to see the list of valid parameters'
53-
).format(param),
54-
**result)
53+
continue
5554
orig = current_values[param]
5655
if isinstance(value, int):
5756
orig = int(orig)
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
[defaults]
22
inventory = ./inventory.yml
33
interpreter_python = auto_silent
4-
stdout_callback = yaml
54
ansible_managed = Ansible managed: {file} modified on %Y-%m-%d %H:%M:%S

tests/args.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"ANSIBLE_MODULE_ARGS": {
3+
"on_charger": {
4+
"lidwake": "1"
5+
},
6+
"on_battery": {
7+
"lidwake": "1"
8+
}
9+
}
10+
}
File renamed without changes.

0 commit comments

Comments
 (0)