Skip to content

Commit

Permalink
Merge branch 'expose_controller_api'
Browse files Browse the repository at this point in the history
  • Loading branch information
jlusiardi committed Oct 3, 2018
2 parents 1fda7b0 + d1fdc13 commit 40f9a6b
Show file tree
Hide file tree
Showing 57 changed files with 3,059 additions and 1,268 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,4 @@ ENV/
/tmp
/.idea/homekit_python.iml
*.json
MANIFEST
34 changes: 23 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ The demonstration uses this JSON in `~/.homekit/demoserver.json`:
"accessory_pin": "031-45-154",
"peers": {},
"unsuccessful_tries": 0,
"c#": 0
"c#": 0,
"category": "Lightbulb"

}
```

Expand Down Expand Up @@ -82,9 +84,11 @@ This tool will list all available HomeKit IP Accessories within the local networ

Usage:
```bash
python3 -m homekit.discover
python3 -m homekit.discover [-t ${TIMEOUT}]
```

The option `-t` specifies the timeout for the inquiry. This is optional and 10s are the default.

Output:
```
Name: smarthomebridge3._hap._tcp.local.
Expand All @@ -105,11 +109,13 @@ Hints:

## identify.py

#TODO rework after identify.py was converted to controller

This tool will use the Identify Routine of a HomeKit IP Accessory.

Usage:
```bash
python3 -m homekit.identify -d ${DEVICEID}
python3 -m homekit.identify -d ${DEVICEID}
```

Output:
Expand All @@ -123,7 +129,7 @@ This tool will perform a pairing to a new accessory.

Usage:
```bash
python3 -m homekit.pair -d ${DEVICEID} -p ${SETUPCODE} -f ${PAIRINGDATAFILE} -o
python3 -m homekit.pair -d ${DEVICEID} -p ${SETUPCODE} -f ${PAIRINGDATAFILE} -a ${ALIAS}
```

The option `-d` specifies the device id of the accessory to pair. Can be obtained via discovery.
Expand All @@ -132,8 +138,8 @@ The option `-p` specifies the HomeKit Setup Code. Can be obtained from the acces

The option `-f` specifies the file that contains the pairing data.

Since the pairing data file is important, the command will exit if the file already exists.
The option `-o` will therefore overwrite the pairing data file if set.
The option `-a` specifies the alias for the device.


The file with the pairing data will be required to for any additional commands to the accessory.

Expand All @@ -143,11 +149,13 @@ This tool will perform a query to list all pairings of an accessory.

Usage:
```bash
python3 -m homekit.list_pairings -f ${PAIRINGDATAFILE}
python3 -m homekit.list_pairings -f ${PAIRINGDATAFILE} -a ${ALIAS}
```

The option `-f` specifies the file that contains the pairing data.

The option `-a` specifies the alias for the device.

This will print information for each controller that is paired with the accessory:

```
Expand All @@ -164,24 +172,26 @@ This tool will remove a pairing from an accessory.

Usage:
```bash
python -m homekit.unpair -f ${PAIRINGDATAFILE} -d
python -m homekit.unpair -f ${PAIRINGDATAFILE} -a ${ALIAS}
```

The option `-f` specifies the file that contains the pairing data.

The option `-d` is optional and will remove the pairing data file if set.
The option `-a` specifies the alias for the device.

## get_accessories.py

This tool will read the accessory attribute database.

Usage:
```bash
python3 -m homekit.get_accessories -f ${PAIRINGDATAFILE} [-o {json,compact}]
python3 -m homekit.get_accessories -f ${PAIRINGDATAFILE} -a ${ALIAS} [-o {json,compact}]
```

The option `-f` specifies the file that contains the pairing data.

The option `-a` specifies the alias for the device.

The option `-o` specifies the format of the output:
* `json` displays the result as pretty printed JSON
* `compact` reformats the output to get more on one screen
Expand All @@ -191,11 +201,13 @@ This tool will read values from one or more characteristics.

Usage:
```bash
python3 -m homekit.get_characteristic -f ${PAIRINGDATAFILE} -c ${Characteristics} [-m] [-p] [-t] [-e]
python3 -m homekit.get_characteristic -f ${PAIRINGDATAFILE} -a ${ALIAS} -c ${Characteristics} [-m] [-p] [-t] [-e]
```

The option `-f` specifies the file that contains the pairing data.

The option `-a` specifies the alias for the device.

The option `-c` specifies the characteristics to read. The format is `<aid>.<cid>`. This
option can be repeated to retrieve multiple characteristics with one call.

Expand Down
21 changes: 6 additions & 15 deletions demoserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@
import os.path
import logging
import argparse
import sys

from homekit import HomeKitServer, HomeKitServerData
from homekit.exception import ConfigurationException
from homekit.model import Accessory, LightBulbService
from homekit import AccessoryServer
from homekit.model import Accessory
from homekit.model.services import LightBulbService


def light_switched(new_value):
Expand All @@ -48,25 +47,17 @@ def setup_args_parser():
logger.addHandler(ch)
logger.info('starting')

# load and check configuration
config_file = os.path.expanduser(args.file)
try:
logger.info('using %s as config file', config_file)
HomeKitServerData(config_file).check()
except ConfigurationException as e:
logger.error('Error in config file %s: %s', config_file, e)
sys.exit(-1)

# create a server and an accessory an run it unless ctrl+c was hit
try:
httpd = HomeKitServer(config_file, logger)
httpd = AccessoryServer(config_file, logger)

accessory = Accessory('Testlicht', 'lusiardi.de', 'Demoserver', '0001', '0.1')
lightBulbService = LightBulbService()
lightBulbService.set_on_set_callback(light_switched)
accessory.services.append(lightBulbService)
httpd.accessories.add_accessory(accessory)

logger.info('offering: %s', httpd.accessories.__str__())
httpd.add_accessory(accessory)

httpd.publish_device()
logger.info('published device and start serving')
Expand Down
Binary file added doc/accessory.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions doc/accessory.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@startuml

!include overview.puml

hide homekit.Pairing
hide homekit.Controller
hide homekit.unpair
hide homekit.pair
hide homekit.list_pairings
hide homekit.discover
hide homekit.get_accessories
hide homekit.get_events
hide homekit.get_characteristics
hide homekit.put_characteristics
hide homekit.get_accessories
hide exceptions

@enduml
Binary file added doc/controller.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions doc/controller.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@startuml

!include overview.puml

hide model
hide AccessoryServer
hide exceptions
@enduml
27 changes: 27 additions & 0 deletions doc/lightbulb_service.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
@startuml

!include overview.puml

hide AccessoryServer
hide Accessory
hide AccessoryInformationService
hide GenericService
hide NameCharacteristic
hide GenericCharacteristic
hide n1
hide n2
hide homekit.Pairing
hide homekit.Controller
hide homekit.unpair
hide homekit.pair
hide homekit.list_pairings
hide homekit.discover
hide homekit.get_accessories
hide homekit.get_events
hide homekit.get_characteristics
hide homekit.put_characteristics
hide homekit.get_accessories
hide exceptions


@enduml
Binary file added doc/overview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 40f9a6b

Please sign in to comment.