diff --git a/jc/parsers/amixer.py b/jc/parsers/amixer.py index baa22c49..b7818cf9 100644 --- a/jc/parsers/amixer.py +++ b/jc/parsers/amixer.py @@ -251,10 +251,16 @@ def parse( channel_data = channel_info.split(" ") if channel_data[0] == "": continue + + if "dB" in channel_data[3]: + db_value = channel_data[3].strip("[]") + status = channel_data[4].strip("[]") + else: + db_value = "0.0db" + status = channel_data[3].strip("[]") + playback_value = channel_data[1] percentage = channel_data[2].strip("[]") # Extract percentage e.g., "100%" - db_value = channel_data[3].strip("[]") # Extract db value e.g., "0.00db" - status = channel_data[4].strip("[]") # Extract status e.g., "on" or "off" # Store channel mapping in the dictionary mapping[channel_name] = { diff --git a/tests/test_amixer.py b/tests/test_amixer.py index b5eb0937..d333d54f 100644 --- a/tests/test_amixer.py +++ b/tests/test_amixer.py @@ -49,6 +49,22 @@ class AmixerTests(unittest.TestCase): quiet=True) self.assertEqual(amixer_sget_json_processed_map, expected_amixer_sget_processed_json_map) + def test_amixer_missing_db(self): + data = '''Simple mixer control 'Master',0 + Capabilities: pvolume pswitch pswitch-joined + Playback channels: Front Left - Front Right + Limits: Playback 0 - 65536 + Mono: + Front Left: Playback 55039 [84%] [on] + Front Right: Playback 54383 [83%] [on] +Simple mixer control 'Capture',0 + Capabilities: cvolume cswitch cswitch-joined + Capture channels: Front Left - Front Right + Limits: Capture 0 - 65536 + Front Left: Capture 24672 [38%] [on] + Front Right: Capture 24672 [38%] [on]''' + expected = {"control_name":"Master","capabilities":["cvolume","cswitch","cswitch-joined"],"playback_channels":["Front Left","Front Right"],"limits":{"playback_min":0,"playback_max":65536},"front_left":{"playback_value":24672,"percentage":38,"db":0.0,"status":True},"front_right":{"playback_value":24672,"percentage":38,"db":0.0,"status":True}} + self.assertEqual(expected, jc.parsers.amixer.parse(data, quiet=True)) if __name__ == '__main__': unittest.main()