Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fbx autodetection #22

Closed
wants to merge 64 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
588ffe7
Update aiofreepybox.py: Add freebox host port and api_version auto de…
foreign-sub Sep 25, 2019
8862c41
Update example.py: use autodetection
foreign-sub Sep 25, 2019
e03a73f
Update aiofreepybox.py: fix log
foreign-sub Sep 25, 2019
a6a9966
Update aiofreepybox.py: only detect if any parameter is set to auto
foreign-sub Sep 25, 2019
7789e23
Update aiofreebox.py: improve detect and host logic
foreign-sub Sep 25, 2019
52b7aef
Update aiofreepybox.py: formatting, small refactoring
foreign-sub Sep 25, 2019
d6d01ab
Update aiofreepybox.py: use f-strings
foreign-sub Sep 26, 2019
0908f5c
Update aiofreepybox.py: improve detection logic
foreign-sub Sep 27, 2019
560ba50
Update aiofreepybox.py: cosmetic fix
foreign-sub Sep 27, 2019
7edd975
Update aiofreepybox.py: split api version, use https by default for d…
foreign-sub Sep 30, 2019
0fd91a8
Update aiofreebox.py: pep257, small fix
foreign-sub Oct 4, 2019
25c5638
Update aiofreepybox.py: add hardcoded api_version_target, cleanup
foreign-sub Oct 7, 2019
2864a1c
Update aiofreepybox.py: rework logic
foreign-sub Oct 8, 2019
297ae8c
Update aiofreepybox.py: fix api_version logic
foreign-sub Oct 8, 2019
9d5b849
Update aiofreepybox.py: rework detection code
foreign-sub Oct 16, 2019
e56ce90
Merge branch 'aiofreepybox' into add-fbx-detect
foreign-sub Oct 16, 2019
7023229
Update aiofreepybox.py: cleanup and fixes
foreign-sub Oct 16, 2019
96f4a0d
Update aiofreepybox.py: update docstrings, some fixes
foreign-sub Oct 16, 2019
4d0950b
Update aiofreepybox.py: small cleanup
foreign-sub Oct 17, 2019
2efa0c5
Update aiofreepybox.py: more cleanup, add fbx_url
foreign-sub Oct 18, 2019
ba72a58
Update aiofreepybox.py: remove unused import time, cleanup
foreign-sub Oct 20, 2019
be2b0f7
Update aiofreepybox.py: more cleanup
foreign-sub Oct 20, 2019
e159d1f
Update aiofreepybox.py: None is the new auto, refactor, cleanup, form…
foreign-sub Oct 22, 2019
ae293fe
Update aiofreepybox.py: update docstring
foreign-sub Oct 22, 2019
680e7ee
Update aiofreepybox.py: update error message and improve detection
foreign-sub Oct 22, 2019
818f54a
Update aiofreepybox.py: fix error message
foreign-sub Oct 22, 2019
7803eed
Update aiofreepybox.py: update docstring, improve error detection
foreign-sub Oct 22, 2019
1041bdf
Update aiofreepybox.py: fix socket close, refactor
foreign-sub Oct 25, 2019
262e098
Update aiofreepybox.py: fix default
foreign-sub Oct 25, 2019
18e93cd
Update aiofreepybox.py: format fixes refactor
foreign-sub Oct 26, 2019
506e550
Update aiofreepybox.py: refactor
foreign-sub Oct 26, 2019
77f152b
Update aiofreepybox.py: refactor
foreign-sub Oct 27, 2019
05148d1
Update aiofreepybox.py: cleanup
foreign-sub Oct 27, 2019
2d76484
Update aiofreepybox: cleanup
foreign-sub Nov 6, 2019
f83ef09
Update aiofreepybox.py: docstring
foreign-sub Nov 7, 2019
edf2c7d
Update aiofreepybox.py: cleanup
foreign-sub Nov 8, 2019
1dceb66
Update example.py: fix home examples
foreign-sub Nov 8, 2019
9b6f56f
Update aiofreepybox.py: typing
foreign-sub Nov 9, 2019
2241607
Update aiofreepybox.py: add missing types
foreign-sub Nov 9, 2019
5571415
Update aiofreepybox.py: catch socket error, cleanup
foreign-sub Nov 11, 2019
ec8efec
Update aiofrepybox.py: add _fbx_api_url, refactor
foreign-sub Nov 11, 2019
2693939
Update aiofreepybox.py: use raise on discovery errors
foreign-sub Nov 14, 2019
c878af8
Update aiofreepybox.py: include error message in raise
foreign-sub Nov 14, 2019
349ef45
Update aiofreepybox.py: add _fbx_db, manage connections, refactor, op…
foreign-sub Nov 17, 2019
224a56e
Update .gitignore: ignore .vscode and api files
foreign-sub Nov 17, 2019
63f82d5
Update aiofreepybox.py: update raise error messages
foreign-sub Nov 17, 2019
b089cef
Update aiofreepybox.py: update raise error messages
foreign-sub Nov 17, 2019
d2f223b
Update aiofreepybox.py: auto import modules, use path, update error m…
foreign-sub Nov 18, 2019
0134fc9
update aiofreepybox.py: add db_get, db_clean, update error messages, …
foreign-sub Nov 18, 2019
8731046
Update aiofreepybox.py: update close, update error messages, cleanup
foreign-sub Nov 19, 2019
ef54de6
Update example.py: update demo
foreign-sub Nov 19, 2019
6d67bed
Update __init__.py: remove empty line
foreign-sub Nov 19, 2019
90b277e
Update aiofreepybox.py: cleanup discovery, update error message, impr…
foreign-sub Nov 20, 2019
c7aafb8
Update aiofreepybox.py: merge try blocks
foreign-sub Nov 21, 2019
607d9d1
Update aiofreepybox.py: polish, remove duplicates (blocks, lines), mo…
foreign-sub Nov 24, 2019
90626b0
Update aiofreepybox.py: purepath is not path, fix possible unbound va…
foreign-sub Nov 26, 2019
ae472db
Update aiofreepybox.py: more polish, setup api module instance on acc…
foreign-sub Nov 28, 2019
d27b25d
Update aiofreepybox.py: small polish
foreign-sub Nov 29, 2019
fc445b0
Update aiofreepybox.py: organize imports, add some error messages
foreign-sub Jan 21, 2020
91ba569
Update aiofreepybox.py: fix possible unbound session
foreign-sub Feb 6, 2020
b651ea8
Update aiofreepybox.py: Allow users to store settings files on an cus…
foreign-sub Feb 6, 2020
b8fe720
Update .gitignore
foreign-sub Feb 6, 2020
11b8815
Update aiofreepybox.py: fix get_permissions return type
foreign-sub Feb 7, 2020
7f309b7
Update aiofreepybox.py: fix, use "or" instead of "if" for str
foreign-sub Feb 8, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions aiofreepybox/aiofreepybox.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@


class Freepybox:
def __init__(self, app_desc=app_desc, token_file=token_file, api_version='v3', timeout=10):
def __init__(self, app_desc=app_desc, token_file=token_file, api_version='auto', timeout=10):
self.token_file = token_file
self.api_version = api_version
self.timeout = timeout
self.app_desc = app_desc
self._access = None

async def open(self, host, port):
async def open(self, host='auto', port='auto'):
'''
Open a session to the freebox, get a valid access module
and instantiate freebox modules
Expand All @@ -63,6 +63,24 @@ async def open(self, host, port):
conn = aiohttp.TCPConnector(ssl_context=ssl_ctx)
self._session = aiohttp.ClientSession(connector=conn)

# Detect host, port and api_version
r = await self._session.get('http://mafreebox.freebox.fr/api_version', timeout=self.timeout)
foreign-sub marked this conversation as resolved.
Show resolved Hide resolved
resp = await r.json()
if host == 'auto':
host = resp['api_domain']
logger.debug('host set to {0}'.format(host))
if port == 'auto':
port = resp['https_port']
logger.debug('port set to {0}'.format(port))
if self.api_version == 'auto':
self.api_version = 'v{0}'.format(resp['api_version'][:1])
logger.debug('api version set to {0}'.format(host))
elif resp['api_version'][:1] > self.api_version[1:]:
logger.warning('Freebox server support a newer api version: v{0}, check api_version ({1})'.format(resp['api_version'][:1], self.api_version))
elif resp['api_version'][:1] < self.api_version[1:]:
logger.warning('Freebox server does not support this version ({0}), downgrading to v{1}'.format(self.api_version, resp['api_version'][:1]))
self.api_version = 'v{0}'.format(resp['api_version'][:1])

self._access = await self._get_freebox_access(host, port, self.api_version, self.token_file, self.app_desc, self.timeout)

# Instantiate freebox modules
Expand Down
4 changes: 2 additions & 2 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ async def demo():
fbx = Freepybox()

# To find out the HTTPS host and port of your freebox, go to
# http://mafreebox.freebox.fr/api_version
# http://mafreebox.freebox.fr/api_version or let auto detect do it for you

# Connect to the freebox
# Be ready to authorize the application on the Freebox if you use this
# example for the first time
await fbx.open(host='abcdefgh.fbxos.fr', port=1234)
await fbx.open()

# Dump freebox configuration using system API
# Extract temperature and mac address
Expand Down