From 218792a672aafe2971181b17e4b124c36ef6486e Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 10 Mar 2017 11:04:51 +0100 Subject: Improve lid plugin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/plugins/lid.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/plugins/lid.py b/src/plugins/lid.py index ed25bf8..29555d3 100644 --- a/src/plugins/lid.py +++ b/src/plugins/lid.py @@ -30,12 +30,15 @@ class Lid: ''' Check whether the lid is open - @param :bool? `True` if the lid is open, - `False` if the lid is closed, - `None` if there is no lid, or if the - computer does not report the lid's state + @param :dict A map from the ID:s of the lids (you probably just + have one or zero) to `True` for open and `False` + for closed. ''' - if not os.path.exists('/proc/acpi/button/lid/LID/state'): - return None - with open('/proc/acpi/button/lid/LID/state', 'rb') as file: - return 'open' in file.read().decode('utf-8', 'strict') + ret = {} + for lid in os.listdir('/proc/acpi/button/lid/'): + try: + with open('/proc/acpi/button/lid/%s/state' % lid, 'rb') as file: + ret[lid] = 'open' in file.read().decode('utf-8', 'strict') + except: + pass + return ret -- cgit v1.2.3-70-g09d2