Skip to content

herrersystem/fbxtools

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fbxtools

Provide intialisation, connect and disconnect functions for Freebox OS application.

Installation

pip install fbxtools

Get started

Fbx class

from fbxtools.fbx import Fbx

Accept 3 arguments:

  • url (str) : Freebox OS API url's
  • app_infos (str) : filepath of app_infos file (default: 'app_infos.json')
  • app_auth (str) : filepath of app_auth file (default: 'app_auth.json')
  • verify_cert (bool or str) : disable SSL cert verification or get certfile path. (default True)

app_infos.json file

This file provide application informations. Must be created manually.

See http://dev.freebox.fr/sdk/os/login/#tokenrequest-object

example :

{
	"app_id": "fr.freebox.test",
	"app_name": "test",
	"app_version": "0.0.1",
	"device_name": "mycomputer"
}

app_auth.json file:

This file provide connect informations. Automatically generated with Fbx.get_app_token().

See http://dev.freebox.fr/sdk/os/login/#tokenrequest-object

example :

{
	"track_id": 6, 
	"app_token": "vfItuATAq8luiuDmo3ZeVVhb0Cv9uImxN2/VJRLa1rOjUsjkBxbEgPY9VwiwpSxq"
}

First use (Init app)

from fbxtools.fbx import Fbx

app = Fbx('http://mafreebox.freebox.fr/api/v3')
appToken, trackId = app.get_app_token()
print('[fbx] Press ">" on the dial of the Freebox')

## Optionnaly, you can verify your authorization status for your app.
import time

currentStatus = ''
attempt = 5
while attempt > 0:
	time.sleep(3)
	response = app.track_auth_progress(trackId)
	if response['data']['success']:
		currentStatus = response['data']['result']['status']
	if currentStatus == 'granted':
		print('[fbx] Your application got authorization !')
		break
	print('[fbx] attempts remaining: ' + str(attempt) + 
		', status: ' + currentStatus)
	attempt -= 1
app.disconnect_app()

This function generated automatically 'app_auth.json' file. For Fbx.url argument, you can use:

example :

from fbxtools.utils import get_url_api
from fbxtools.fbx import Fbx

url_api = get_url_api()
app = Fbx(url_api)
app.get_app_token()

Use this if you are on the same network as your freebox.

Call API.

from fbxtools.fbx import Fbx

app = Fbx('http://mafreebox.freebox.fr/api/v3')
app.get_session_token()


@app.api.call('/lcd/config')
def get_config():
	'''
	http://dev.freebox.fr/sdk/os/lcd/#get-the-current-lcd-configuration
	''' 
	return {}


@app.api.call('/lcd/config', method='PUT')
def update_config(config):
	'''
	http://dev.freebox.fr/sdk/os/lcd/#update-the-lcd-configuration
	'''
	return {'data': config, 'is_json': True}


new_config = {	
	"brightness": 50,
	"orientation": 90,
	"orientation_forced": False
}

resp = get_config()
app.disconnect_app()
print(resp)

About

Interface within Freebox API and Python

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages