Skip to content

Commit

Permalink
Add type to Docstring
Browse files Browse the repository at this point in the history
Change PyPI to 0.0.3-alpha
  • Loading branch information
HydrelioxGitHub committed Oct 5, 2016
1 parent 4392f7c commit d8bbfcc
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 30 deletions.
10 changes: 10 additions & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# file GENERATED by distutils, do NOT edit
setup.cfg
setup.py
pybbox\__init__.py
pybbox\bboxApiURL.py
pybbox\bboxAuth.py
pybbox\bboxConstant.py
pybbox\boxApiCall.py
pybbox\pybbox.py
pybbox\test_bbox.py
Binary file added dist/pybbox-0.0.1-alpha.zip
Binary file not shown.
Binary file added dist/pybbox-0.0.2-alpha.zip
Binary file not shown.
Binary file added dist/pybbox-0.0.3-alpha.zip
Binary file not shown.
78 changes: 50 additions & 28 deletions pybbox/pybbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ class Bbox:
def __init__(self, ip=BboxConstant.DEFAULT_LOCAL_IP):
"""
Initiate a Bbox instance with a default local ip (192.168.1.254)
:param ip: ip of the bow
:param ip: Ip of the box if you do not want the default one
:type ip: str
:return: A Bbox Api Instance
:rtype: None
"""
self.bbox_url = BboxAPIUrl(None, None, ip)
self.bbox_auth = BboxAuth(None, None, False, self.bbox_url.authentication_type)
Expand All @@ -23,7 +26,8 @@ def __init__(self, ip=BboxConstant.DEFAULT_LOCAL_IP):
def get_access_type(self):
"""
Return if the access is made on the local network or remotely
:return: AUTHENTICATION_TYPE_LOCAL or AUTHENTICATION_TYPE_REMOTE
:return: AUTHENTICATION_TYPE_LOCAL (0) or AUTHENTICATION_TYPE_REMOTE (1)
:rtype: int
"""
return self.bbox_url.authentication_type

Expand All @@ -37,7 +41,9 @@ def get_access_type(self):

def get_bbox_info(self):
"""
This API returns Bbox information
:return: numbers of info about the box itself (see API doc)
:rtype: dict
"""
self.bbox_auth.set_access(BboxConstant.AUTHENTICATION_LEVEL_PUBLIC, BboxConstant.AUTHENTICATION_LEVEL_PRIVATE)
self.bbox_url.set_api_name(BboxConstant.API_DEVICE, None)
Expand All @@ -48,9 +54,10 @@ def get_bbox_info(self):

def set_display_luminosity(self, luminosity):
"""
:param luminosity: int must be between 0 (light off) and 100
Change the intensity of light of the front panel of the box
:param luminosity: must be between 0 (light off) and 100
:type luminosity: int
"""

if (luminosity < 0) or (luminosity > 100):
raise ValueError("Luminosity must be between 0 and 100")
self.bbox_auth.set_access(BboxConstant.AUTHENTICATION_LEVEL_PRIVATE,
Expand All @@ -59,29 +66,28 @@ def set_display_luminosity(self, luminosity):
data = {'luminosity': luminosity}
api = BoxApiCall(self.bbox_url, BboxConstant.HTTP_METHOD_PUT, data,
self.bbox_auth)
response = api.execute_api_request()
return response
api.execute_api_request()

def reboot(self):
"""
Reboot the device
Useful when trying to get xDSL sync
:return: bool
"""
token = self.get_token()
self.bbox_auth.set_access(BboxConstant.AUTHENTICATION_LEVEL_PRIVATE, BboxConstant.AUTHENTICATION_LEVEL_PRIVATE)
url_suffix = "reboot?btoken={}".format(token)
self.bbox_url.set_api_name(BboxConstant.API_DEVICE, url_suffix)
api = BoxApiCall(self.bbox_url, BboxConstant.HTTP_METHOD_POST, None,
self.bbox_auth)
resp = api.execute_api_request()
return resp.status_code == 200
api.execute_api_request()

def get_token(self):
"""
Return a string which is a token, needed for some API calls
TODO : make a token class to be able to store date of expiration
:return: string
:return: Token (can be used with some API call
:rtype: str
.. todo:: make a token class to be able to store date of expiration
"""
self.bbox_auth.set_access(BboxConstant.AUTHENTICATION_LEVEL_PRIVATE, BboxConstant.AUTHENTICATION_LEVEL_PRIVATE)
self.bbox_url.set_api_name(BboxConstant.API_DEVICE, "token")
Expand All @@ -97,7 +103,8 @@ def get_token(self):
def get_all_connected_devices(self):
"""
Get all info about devices connected to the box
:return: a list with all devices data
:return: a list with each device info
:rtype: list
"""
self.bbox_auth.set_access(BboxConstant.AUTHENTICATION_LEVEL_PUBLIC, BboxConstant.AUTHENTICATION_LEVEL_PRIVATE)
self.bbox_url.set_api_name(BboxConstant.API_HOSTS, None)
Expand All @@ -109,8 +116,10 @@ def get_all_connected_devices(self):
def is_device_connected(self, ip):
"""
Check if a device identified by it IP is connected to the box
:param ip: IP of the device
:param ip: IP of the device you want to test
:type ip: str
:return: True is the device is connected, False if it's not
:rtype: bool
"""
all_devices = self.get_all_connected_devices()
for device in all_devices:
Expand All @@ -124,9 +133,11 @@ def is_device_connected(self, ip):

def login(self, password):
"""
:param password:
:return:
Authentify yourself against the box,
:param password: Admin password of the box
:type password: str
:return: True if your auth is successful
:rtype: bool
"""
self.bbox_auth.set_access(BboxConstant.AUTHENTICATION_LEVEL_PUBLIC, BboxConstant.AUTHENTICATION_LEVEL_PUBLIC)
self.bbox_url.set_api_name("login", None)
Expand All @@ -140,7 +151,9 @@ def login(self, password):

def logout(self):
"""
:return:
Destroy the auth session against the box
:return: True if your logout is successful
:rtype: bool
"""
self.bbox_auth.set_access(BboxConstant.AUTHENTICATION_LEVEL_PUBLIC, BboxConstant.AUTHENTICATION_LEVEL_PUBLIC)
self.bbox_url.set_api_name("logout", None)
Expand All @@ -157,8 +170,9 @@ def logout(self):

def get_xdsl_info(self):
"""
Get all info about the xdsl connection
:return: dict
Get all data about your xDSL connection
:return: A dict with all data about your xdsl connection (see API doc)
:rtype: dict
"""
self.bbox_auth.set_access(BboxConstant.AUTHENTICATION_LEVEL_PUBLIC, BboxConstant.AUTHENTICATION_LEVEL_PRIVATE)
self.bbox_url.set_api_name(BboxConstant.API_WAN, "xdsl")
Expand All @@ -169,8 +183,9 @@ def get_xdsl_info(self):

def get_xdsl_stats(self):
"""
Get stat about the xdsl connection
:return: dict
Get all stats about your xDSL connection
:return: A dict with all stats about your xdsl connection (see API doc)
:rtype: dict
"""
self.bbox_auth.set_access(BboxConstant.AUTHENTICATION_LEVEL_PUBLIC, BboxConstant.AUTHENTICATION_LEVEL_PRIVATE)
self.bbox_url.set_api_name(BboxConstant.API_WAN, "xdsl/stats")
Expand All @@ -181,8 +196,9 @@ def get_xdsl_stats(self):

def get_ip_stats(self):
"""
Get stat about the ip connection
:return: dict
Get all stats about your Wan ip connection
:return: A dict with all stats about your Wan ip connection (see API doc)
:rtype: dict
"""
self.bbox_auth.set_access(BboxConstant.AUTHENTICATION_LEVEL_PUBLIC, BboxConstant.AUTHENTICATION_LEVEL_PRIVATE)
self.bbox_url.set_api_name(BboxConstant.API_WAN, "ip/stats")
Expand All @@ -193,30 +209,35 @@ def get_ip_stats(self):

def is_bbox_connected(self):
"""
Check if your xDsl connection is ok
:return: True is the box has an xdsl connection
:rtype: bool
"""
xdsl_info = self.get_xdsl_info()
return xdsl_info["state"] == "Connected"

def get_up_bitrates(self):
"""
:return: the upload bitrates of the xdsl connectionbitrates in Mbps
:rtype: float
"""
xdsl_info = self.get_xdsl_info()
return xdsl_info["up"]["bitrates"] / 1000

def get_down_bitrates(self):
"""
:return: the download bitrates of the xdsl connectionbitrates in Mbps
:rtype: float
"""
xdsl_info = self.get_xdsl_info()
return xdsl_info["down"]["bitrates"] / 1000

def get_up_used_bandwith(self):
"""
Return a percentage of the current used xdsl upload bandwith
0 no bandwith is used, 100 all your bandwith is used
:return: int
Instant measure, can be very different from one call to another
:return: 0 no bandwith is used, 100 all your bandwith is used
:rtype: int
"""
ip_stats_up = self.get_ip_stats()['tx']
percent = ip_stats_up['bandwidth']*100/ip_stats_up['maxBandwidth']
Expand All @@ -225,8 +246,9 @@ def get_up_used_bandwith(self):
def get_down_used_bandwith(self):
"""
Return a percentage of the current used xdsl download bandwith
0 no bandwith is used, 100 all your bandwith is used
:return: int
Instant measure, can be very different from one call to another
:return: 0 no bandwith is used, 100 all your bandwith is used
:rtype: int
"""
ip_stats_up = self.get_ip_stats()['rx']
percent = ip_stats_up['bandwidth']*100/ip_stats_up['maxBandwidth']
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
setup(
name = 'pybbox',
packages = ['pybbox'], # this must be the same as the name above
version = '0.0.2-alpha',
version = '0.0.3-alpha',
description = 'a simple python3 library for the Bouygues BBox Routeur API',
author = 'Hydreliox',
author_email = 'hydreliox@gmail.com',
url = 'https://github.com/HydrelioxGitHub/pybbox', # use the URL to the github repo
download_url = 'https://github.com/HydrelioxGitHub/pybbox/tarball/0.0.2-alpha',
download_url = 'https://github.com/HydrelioxGitHub/pybbox/tarball/0.0.3-alpha',
keywords = ['bbox', 'Bouygues', 'routeur', 'API'], # arbitrary keywords
classifiers = [],
)

0 comments on commit d8bbfcc

Please sign in to comment.