From 2dd4e0701394d90aa0e0f3e3ef9bebfeec90d8e8 Mon Sep 17 00:00:00 2001 From: Christian Stade-Schuldt Date: Tue, 9 Apr 2019 18:59:54 +0200 Subject: [PATCH] make checks language agnostic. Rely on position instead. --- fritzbox_memory_usage.py | 4 ++-- fritzbox_power_consumption.py | 15 ++++----------- fritzbox_wifi_devices.py | 10 ++++------ 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/fritzbox_memory_usage.py b/fritzbox_memory_usage.py index 598f13c..a73d13b 100755 --- a/fritzbox_memory_usage.py +++ b/fritzbox_memory_usage.py @@ -33,8 +33,8 @@ def get_memory_usage(): session_id = fh.get_session_id(server, password) xhr_data = fh.get_xhr_content(server, session_id, PAGE) data = json.loads(xhr_data) - for usage in enumerate(USAGE): - print('%s.value %s' % (usage[1], data['data']['ramusage']['series'][usage[0]][-1])) + for i, usage in enumerate(USAGE): + print('%s.value %s' % (usage, data['data']['ramusage']['series'][i][-1])) def print_config(): diff --git a/fritzbox_power_consumption.py b/fritzbox_power_consumption.py index 0669aa4..9d71a76 100755 --- a/fritzbox_power_consumption.py +++ b/fritzbox_power_consumption.py @@ -23,12 +23,7 @@ import sys import fritzbox_helper as fh PAGE = 'energy' -DEVICES = {'FRITZ!Box Gesamtsystem': 'system', - 'FRITZ!Box Hauptprozessor': 'cpu', - 'WLAN': 'wifi', - 'DSL': 'dsl', - 'analoge FON-Anschlüsse': 'ab', - 'USB-Geräte': 'usb'} +DEVICES = ['system', 'cpu', 'wifi', 'dsl', 'ab', 'usb'] def get_power_consumption(): @@ -40,11 +35,9 @@ def get_power_consumption(): session_id = fh.get_session_id(server, password) xhr_data = fh.get_xhr_content(server, session_id, PAGE) data = json.loads(xhr_data) - for d in data['data']['drain']: - try: - print('%s.value %s' % (DEVICES[d['name']], d['actPerc'])) - except KeyError as e: - pass + devices = data['data']['drain'] + for i, device in enumerate(DEVICES): + print('%s.value %s' % (device, devices[i]['actPerc'])) def print_config(): diff --git a/fritzbox_wifi_devices.py b/fritzbox_wifi_devices.py index e89e70e..bc8e24c 100755 --- a/fritzbox_wifi_devices.py +++ b/fritzbox_wifi_devices.py @@ -39,12 +39,10 @@ def get_connected_wifi_devices(): session_id = fh.get_session_id(server, password) xhr_data = fh.get_xhr_content(server, session_id, PAGE) data = json.loads(xhr_data) - for d in data['data']['drain']: - if d['name'] == 'WLAN': - m = re.search(pattern, d['statuses'][-1]) - if m: - connected_devices = int(m.group(1)) - print('wifi.value %d' % connected_devices) + m = re.search(pattern, data['data']['drain'][2]['statuses'][-1]) + if m: + connected_devices = int(m.group(1)) + print('wifi.value %d' % connected_devices) def print_config():