From 568143779e9fda0047196694e5e051de24e9d639 Mon Sep 17 00:00:00 2001 From: Anders Melchiorsen Date: Sat, 30 Mar 2019 19:19:53 +0100 Subject: [PATCH 1/6] Remove unused attribute --- eternalegypt/eternalegypt.py | 1 - 1 file changed, 1 deletion(-) diff --git a/eternalegypt/eternalegypt.py b/eternalegypt/eternalegypt.py index 17c9598..b40e4af 100644 --- a/eternalegypt/eternalegypt.py +++ b/eternalegypt/eternalegypt.py @@ -83,7 +83,6 @@ class LB2120: listeners = attr.ib(init=False, factory=list) max_sms_id = attr.ib(init=False, default=None) - task = attr.ib(init=False, default=None) @property def _baseurl(self): From 544bf0f2ae9800691634fa59f9748f26d609f0c8 Mon Sep 17 00:00:00 2001 From: Anders Melchiorsen Date: Sat, 30 Mar 2019 19:22:06 +0100 Subject: [PATCH 2/6] Generic _config_call method to construct POST request --- eternalegypt/eternalegypt.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/eternalegypt/eternalegypt.py b/eternalegypt/eternalegypt.py index b40e4af..b5ef950 100644 --- a/eternalegypt/eternalegypt.py +++ b/eternalegypt/eternalegypt.py @@ -150,18 +150,21 @@ async def sms(self, phone, message): async with self.websession.post(url, data=data) as response: _LOGGER.debug("Sent message with status %d", response.status) - @autologin - async def delete_sms(self, sms_id): - """Delete a message.""" - + def _config_call(self, key, value): + """Set a configuration key to a certain value.""" url = self._url('Forms/config') data = { - 'sms.deleteId': sms_id, + key: value, 'err_redirect': '/error.json', 'ok_redirect': '/success.json', 'token': self.token } - async with self.websession.post(url, data=data) as response: + return self.websession.post(url, data=data) + + @autologin + async def delete_sms(self, sms_id): + """Delete a message.""" + async with self._config_call('sms.deleteId', sms_id) as response: _LOGGER.debug("Delete %d with status %d", sms_id, response.status) def _build_information(self, data): From 881b1bf474ead211e5eb7c6215a6ac10a54feb96 Mon Sep 17 00:00:00 2001 From: Anders Melchiorsen Date: Sat, 30 Mar 2019 19:22:46 +0100 Subject: [PATCH 3/6] Add set_failover_mode --- eternalegypt/eternalegypt.py | 16 ++++++++++++++++ examples/failover.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100755 examples/failover.py diff --git a/eternalegypt/eternalegypt.py b/eternalegypt/eternalegypt.py index b5ef950..8baeba5 100644 --- a/eternalegypt/eternalegypt.py +++ b/eternalegypt/eternalegypt.py @@ -167,6 +167,22 @@ async def delete_sms(self, sms_id): async with self._config_call('sms.deleteId', sms_id) as response: _LOGGER.debug("Delete %d with status %d", sms_id, response.status) + @autologin + async def set_failover_mode(self, mode): + """Set failover mode.""" + modes = { + 'auto': 'Auto', + 'wire': 'WAN', + 'mobile': 'LTE', + } + + if mode not in modes.keys(): + _LOGGER.error("Invalid mode %s not %s", mode, "/".join(modes.keys())) + return + + async with self._config_call('failover.mode', modes[mode]) as response: + _LOGGER.debug("Set mode to %s", mode) + def _build_information(self, data): """Read the bits we need from returned data.""" if 'wwan' not in data: diff --git a/examples/failover.py b/examples/failover.py new file mode 100755 index 0000000..a48ba6a --- /dev/null +++ b/examples/failover.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 + +"""Example file for eternalegypt library.""" + +import sys +import asyncio +import aiohttp +import logging + +import eternalegypt + +async def set_failover_mode(mode): + """Example of printing the current upstream.""" + jar = aiohttp.CookieJar(unsafe=True) + websession = aiohttp.ClientSession(cookie_jar=jar) + + try: + modem = eternalegypt.Modem(hostname=sys.argv[1], websession=websession) + await modem.login(password=sys.argv[2]) + + await modem.set_failover_mode(mode) + + await modem.logout() + except eternalegypt.Error: + print("Could not login") + + await websession.close() + +if len(sys.argv) != 4: + print("{}: ".format(sys.argv[0])) +else: + asyncio.get_event_loop().run_until_complete(set_failover_mode(sys.argv[3])) From dc77741e856edde0572b862d870f8d860f89b709 Mon Sep 17 00:00:00 2001 From: Anders Melchiorsen Date: Sat, 30 Mar 2019 19:23:00 +0100 Subject: [PATCH 4/6] Add set_autoconnect_mode --- eternalegypt/eternalegypt.py | 16 ++++++++++++++++ examples/auto_connect.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100755 examples/auto_connect.py diff --git a/eternalegypt/eternalegypt.py b/eternalegypt/eternalegypt.py index 8baeba5..0139ef8 100644 --- a/eternalegypt/eternalegypt.py +++ b/eternalegypt/eternalegypt.py @@ -183,6 +183,22 @@ async def set_failover_mode(self, mode): async with self._config_call('failover.mode', modes[mode]) as response: _LOGGER.debug("Set mode to %s", mode) + @autologin + async def set_autoconnect_mode(self, mode): + """Set autoconnect mode.""" + modes = { + 'never': 'Never', + 'home': 'HomeNetwork', + 'always': 'Always', + } + + if mode not in modes.keys(): + _LOGGER.error("Invalid mode %s not %s", mode, "/".join(modes.keys())) + return + + async with self._config_call('wwan.autoconnect', modes[mode]) as response: + _LOGGER.debug("Set mode to %s", mode) + def _build_information(self, data): """Read the bits we need from returned data.""" if 'wwan' not in data: diff --git a/examples/auto_connect.py b/examples/auto_connect.py new file mode 100755 index 0000000..2453668 --- /dev/null +++ b/examples/auto_connect.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 + +"""Example file for eternalegypt library.""" + +import sys +import asyncio +import aiohttp +import logging + +import eternalegypt + +async def set_autoconnect_mode(mode): + """Example of printing the current upstream.""" + jar = aiohttp.CookieJar(unsafe=True) + websession = aiohttp.ClientSession(cookie_jar=jar) + + try: + modem = eternalegypt.Modem(hostname=sys.argv[1], websession=websession) + await modem.login(password=sys.argv[2]) + + await modem.set_autoconnect_mode(mode) + + await modem.logout() + except eternalegypt.Error: + print("Could not login") + + await websession.close() + +if len(sys.argv) != 4: + print("{}: ".format(sys.argv[0])) +else: + asyncio.get_event_loop().run_until_complete(set_autoconnect_mode(sys.argv[3])) From 16e78ac6cd5db3c6bfbc8e7d25710414145e9101 Mon Sep 17 00:00:00 2001 From: Anders Melchiorsen Date: Sat, 30 Mar 2019 19:28:07 +0100 Subject: [PATCH 5/6] Add connect_lte --- eternalegypt/eternalegypt.py | 6 ++++++ examples/connect_lte.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100755 examples/connect_lte.py diff --git a/eternalegypt/eternalegypt.py b/eternalegypt/eternalegypt.py index 0139ef8..dc0742e 100644 --- a/eternalegypt/eternalegypt.py +++ b/eternalegypt/eternalegypt.py @@ -161,6 +161,12 @@ def _config_call(self, key, value): } return self.websession.post(url, data=data) + @autologin + async def connect_lte(self): + """Do an LTE reconnect.""" + async with self._config_call('wwan.connect', 'DefaultProfile') as response: + _LOGGER.debug("Connected to LTE with status %d", response.status) + @autologin async def delete_sms(self, sms_id): """Delete a message.""" diff --git a/examples/connect_lte.py b/examples/connect_lte.py new file mode 100755 index 0000000..571630e --- /dev/null +++ b/examples/connect_lte.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 + +"""Example file for eternalegypt library.""" + +import sys +import asyncio +import aiohttp +import logging + +import eternalegypt + +async def connect(): + """Example of printing the current upstream.""" + jar = aiohttp.CookieJar(unsafe=True) + websession = aiohttp.ClientSession(cookie_jar=jar) + + try: + modem = eternalegypt.Modem(hostname=sys.argv[1], websession=websession) + await modem.login(password=sys.argv[2]) + + await modem.connect_lte() + + await modem.logout() + except eternalegypt.Error: + print("Could not login") + + await websession.close() + +if len(sys.argv) != 3: + print("{}: ".format(sys.argv[0])) +else: + asyncio.get_event_loop().run_until_complete(connect()) From 4da4af79883027e188c366644b1b30f9aa665464 Mon Sep 17 00:00:00 2001 From: Anders Melchiorsen Date: Sat, 30 Mar 2019 20:42:18 +0100 Subject: [PATCH 6/6] Add wire_connected, mobile_connected status The mobile_connected status replaces connection. --- eternalegypt/eternalegypt.py | 5 +++-- examples/status.py | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/eternalegypt/eternalegypt.py b/eternalegypt/eternalegypt.py index dc0742e..33e3037 100644 --- a/eternalegypt/eternalegypt.py +++ b/eternalegypt/eternalegypt.py @@ -212,10 +212,11 @@ def _build_information(self, data): result = Information() + result.serial_number = data['general']['FSN'] result.usage = data['wwan']['dataUsage']['generic']['dataTransferred'] result.upstream = data['failover']['backhaul'] - result.serial_number = data['general']['FSN'] - result.connection = data['wwan']['connection'] + result.wire_connected = 'Connected' if data['failover']['wanConnected'] else 'Disconnected' + result.mobile_connected = data['wwan']['connection'] result.connection_text = data['wwan']['connectionText'] result.connection_type = data['wwan']['connectionType'] result.current_nw_service_type = data['wwan']['currentNWserviceType'] diff --git a/examples/status.py b/examples/status.py index 2e1b410..91fd9ee 100755 --- a/examples/status.py +++ b/examples/status.py @@ -20,7 +20,8 @@ async def get_information(): result = await modem.information() print("upstream: {}".format(result.upstream)) print("serial_number: {}".format(result.serial_number)) - print("connection: {}".format(result.connection)) + print("wire_connected: {}".format(result.wire_connected)) + print("mobile_connected: {}".format(result.mobile_connected)) print("connection_text: {}".format(result.connection_text)) print("connection_type: {}".format(result.connection_type)) print("current_nw_service_type: {}".format(result.current_nw_service_type))