Skip to content

Commit

Permalink
Implemented ability to switch net mode
Browse files Browse the repository at this point in the history
  • Loading branch information
m-krasikov committed Aug 14, 2020
1 parent feac71b commit 8cae130
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
38 changes: 38 additions & 0 deletions huaweisms/api/dialup.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,41 @@ def switch_mobile_on(ctx: huaweisms.api.common.ApiCtx, proxy=None):
}
url = "{}/dialup/mobile-dataswitch".format(ctx.api_base_url)
return huaweisms.api.common.post_to_url(url, data, ctx, additional_headers=headers, proxy=proxy)


def switch_net_mode(ctx: huaweisms.api.common.ApiCtx, net_mode='lte_umts', proxy=None):
xml_template = (
'<?xml version="1.0" encoding="UTF-8"?>'
'<request>'
'<NetworkMode>{mode}</NetworkMode>'
'<NetworkBand>3FFFFFFF</NetworkBand>'
'<LTEBand>7FFFFFFFFFFFFFFF</LTEBand>'
'</request>'
)
if net_mode == 'lte':
data = xml_template.format(mode='03')
elif net_mode == 'umts':
data = xml_template.format(mode='02')
elif net_mode == 'lte_umts':
data = xml_template.format(mode='0302')
else:
data = xml_template.format(mode='0302')
headers = {
'__RequestVerificationToken': ctx.token,
}
url = "{}/net/net-mode".format(ctx.api_base_url)
return huaweisms.api.common.post_to_url(url, data, ctx, additional_headers=headers, proxy=proxy)


def get_net_mode(ctx: huaweisms.api.common.ApiCtx, proxy=None):
url = "{}/net/net-mode".format(ctx.api_base_url)
result = huaweisms.api.common.get_from_url(url, ctx, proxy=proxy)
if result and result.get('type') == 'response':
response = result['response']
if response and response.get('NetworkMode') == '0302':
return 'lte_umts'
if response and response.get('NetworkMode') == '03':
return 'lte'
if response and response.get('NetworkMode') == '02':
return 'umts'
return 'UNKNOWN_MODE'
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import setup

version = '0.0.7'
version = '0.0.8'

with open('requirements.txt') as fd:
requirements = [line.strip() for line in fd if line.strip()]
Expand Down

0 comments on commit 8cae130

Please sign in to comment.