Freebox thin client
Go to file
Laurent 3e7ad3ba6f Merge branch 'feat' into 'dev'
Feat

See merge request sun/pyfbx!13
2019-04-16 01:54:18 +02:00
pyfbx Update for a few features 2019-04-16 01:39:45 +02:00
tests Cover Exception 2019-04-16 01:52:53 +02:00
.gitignore NoMdns, Logs and script 2019-04-04 14:45:48 +02:00
.gitlab-ci.yml Tests with python 3.5 2019-04-15 12:29:26 +02:00
LICENSE Initial commit 2019-04-01 21:40:21 +02:00
MANIFEST.in Initial commit 2019-04-01 21:40:21 +02:00
README.md Update doc 2019-04-15 15:21:14 +02:00
requirements-dev.txt Minimal pytest version for coverage support 2019-04-16 01:43:54 +02:00
requirements.txt Initial commit 2019-04-01 21:40:21 +02:00
setup.cfg NoMdns, Logs and script 2019-04-04 14:45:48 +02:00
setup.py rc 2019-04-16 01:37:14 +02:00

README.md

Freebox client library

Features

  • Full API coverage
  • Https and Mdns discovery
  • Thin client wrapper library (<200 lines)
  • CLI script example to access any command

pipeline status coverage report

Script

A script called pyfbx is installed and can be used like this:

To register the application:

$ pyfbx SuperAppId

Once registration is done on the device, write down the application token.

Using this app token, acquire a session token to execute a test command.

$ pyfbx -t '<TOKEN>' SuperAppId
$ pyfbx -t 'f:<TOKEN_FILE>' SuperAppId

You can run any commands on the freebox and retrieve complete result or single value

$ pyfbx -t f:/home/foo/token.txt SuperAppId -c 'Contacts.Create_a_contact(\
post_data={"display_name": "Sandy Kilo", "first_name": "Sandy", "last_name":"Kilo"})'
{   'birthday': '',
    'company': '',
    'display_name': 'Sandy Kilo',
    'first_name': 'Sandy',
    'id': 17,
    'last_name': 'Kilo',
    'last_update': 1554378898,
    'notes': '',
    'photo_url': ''}

$ pyfbx -t f:token.txt -u https://0s2efr3i.fbxos.fr:15628 id -c "Connection.Get_the_current_Connection_status()['rate_up']"
1700

Note : Don't forget to escape token and command with quotes.

The complete script help is:

pyfbx -h
usage: pyfbx [-h] [-c COMMAND] [-t TOKEN] [-v] [-n] [-u URL] app_id

positional arguments:
  app_id                application identifier

optional arguments:
  -h, --help            show this help message and exit
  -c COMMAND, --command COMMAND
                        command, defaults to
                        System.Get_the_current_system_info()
  -t TOKEN, --token TOKEN
                        token (or f:<filename>)
  -v, --verbose         increase verbosity to INFO, use twice for DEBUG
  -n, --http            Disable MDNS and use http known address
  -u URL, --url URL     specific url to query

Library usage

The REST API is generated at runtime with the creation of class attributes for all Freebox subsystems.

>>> from pyfbx import Fbx
>>> f=Fbx()             # By default, this will perform MDNS discovery
>>> f=Fbx(nomdns=True)  # Use faster http api discovery
>>> f.<TAB>
f.Airmedia         f.Download_Config  f.Lan              f.Rrd              f.Upnpav
f.Call             f.Download_Feeds   f.Lcd              f.Share            f.Vpn
f.Connection       f.Freeplug         f.Nat              f.Storage          f.Vpn_Client
f.Contacts         f.Fs               f.Network_Share    f.Switch           f.Wifi
f.Dhcp             f.Ftp              f.Parental         f.System           f.mksession(
f.Download         f.Igd              f.Pvr              f.Upload           f.register(
>>> f.Freeplug.<TAB>
f.Freeplug.Get_a_particular_Freeplug_information(
f.Freeplug.Reset_a_Freeplug(
f.Freeplug.Get_the_current_Freeplugs_networks(

# Register application to get app token. Physical access is required.
>>> token = f.register("AppId", "My App", "PC")
# Generate session token
>>> f.mksession(app_id="AppId", token=token)

>>> help(f.Lan.Update_the_current_Lan_configuration)
Help on method Update_the_current_Lan_configuration:

Update_the_current_Lan_configuration(post_data) method of pyfbx.client.Lan instance
    Update the current Lan configuration

    Url parameters:
    Post data:PostData

>>> help(f.Contacts.Access_a_given_contact_entry)
Help on method Access_a_given_contact_entry:

Access_a_given_contact_entry(id) method of pyfbx.client.Contacts instance
    Access a given contact entry

    Url parameters: id
    Post data:

>>> f.Lan.Get_the_current_Lan_configuration()
{'name_dns': 'freebox-server', 'name': 'Freebox Server', 'name_mdns': 'Freebox-Server', 
'mode': 'router', 'name_netbios': 'Freebox_Server', 'ip': '192.168.1.254'}

# Any subsequent call to mksession will refresh the session token
>>> f.mksession()

Developpment

Testing

You can run tests with

pip3 install -r requirements-dev.txt
pytest tests

The library mechanisms are tested. To get 100% coverage, a Freebox on its default IP (192.168.1.254) is required.

The API description is generated and thus not functionnaly tested.