-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
153 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
Create an Accessory | ||
=================== | ||
|
||
The following code snippet how you would model a fictious accessory | ||
representing a mobile power bank. | ||
|
||
```swift | ||
class PowerBankAccessory: Accessory { | ||
let service = PowerBankService() | ||
init(info: Service.Info) { | ||
super.init(info: info, type: .outlet, services: [service]) | ||
} | ||
} | ||
class PowerBankService: Service { | ||
public let on = GenericCharacteristic<Bool>( | ||
type: .on, | ||
value: false) | ||
public let inUse = GenericCharacteristic<Bool>( | ||
type: .outletInUse, | ||
value: true, | ||
permissions: [.read, .events]) | ||
public let batteryLevel = GenericCharacteristic<Double>( | ||
type: .batteryLevel, | ||
value: 100, | ||
permissions: [.read, .events]) | ||
|
||
init() { | ||
super.init(type: .outlet, characteristics: [ | ||
AnyCharacteristic(on), | ||
AnyCharacteristic(inUse), | ||
AnyCharacteristic(batteryLevel) | ||
]) | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
Design | ||
====== | ||
|
||
## Object-Oriented Design | ||
|
||
A high-level overview of the objects involved are shown in the diagram below. | ||
The terminology of HAP (Device, Accessory, Service, Characteristic) is | ||
followed for ease of understanding. | ||
|
||
``` | ||
+------------+ | ||
| NetService | | ||
+------------+ | ||
| | ||
| delegate | ||
v | ||
+--------+ 1 0…1 +--------+ * * +---------------------+ | ||
| Device |-----------| Server |-------| Controller (iPhone) | | ||
+--------+ +--------+ +---------------------+ | ||
| 1 * / | ||
| * / | ||
+-----------+ / | ||
| Accessory | / | ||
+-----------+ / | ||
| 1 / > read, events | ||
| * / < write, subscribe | ||
+---------+ / | ||
| Service | / | ||
+---------+ / | ||
| 1 / | ||
| * * / | ||
+----------------+ | ||
| Characteristic | | ||
+----------------+ | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Development | ||
=========== | ||
|
||
## Running tests | ||
|
||
Certain tests involve crypto, which can be a bit slow in debug builds. Best to run the tests with a release build, like this: | ||
|
||
``` | ||
swift test -c release -Xswiftc -enable-testing | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
Getting Started | ||
=============== | ||
|
||
## Installing dependencies | ||
|
||
### macOS | ||
On macOS this package depends on libsodium to provide certain crypto algorithms. Install it using homebrew: | ||
``` | ||
brew install libsodium | ||
``` | ||
|
||
### Linux | ||
On Debian based Linux distributions you need a few packages. Install them using apt: | ||
``` | ||
sudo apt install openssl libssl-dev libsodium-dev libcurl4-openssl-dev libavahi-compat-libdnssd-dev | ||
``` | ||
|
||
If your package manager doesn't provide libsodium 1.0.9 or higher, install it from source: | ||
``` | ||
wget https://download.libsodium.org/libsodium/releases/libsodium-1.0.12.tar.gz | ||
tar xzf libsodium-1.0.12.tar.gz | ||
cd libsodium-1.0.12 | ||
./configure | ||
make && make check | ||
sudo make install | ||
sudo ldconfig | ||
``` | ||
|
||
### Linux ARM / Raspberry Pi (Raspbian Stretch) | ||
There are currently no official binaries from swift.org targetting ARM / Raspbian, however there's an active community working on Swift on ARM. You can [install binaries from their repository][1]: | ||
|
||
``` | ||
curl -s https://packagecloud.io/install/repositories/swift-arm/release/script.deb.sh | sudo bash | ||
sudo apt install swift5 | ||
``` | ||
|
||
## First run | ||
Now that you have all the dependencies installed, you should be able to build and run the project. For optimal performance, use a release build: | ||
``` | ||
swift run -c release hap-server | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Usage | ||
===== | ||
|
||
Modify `Sources/hap-server/main.swift` to include your own accessories, or import the _HAP_ library into your own project. | ||
|
||
On Mac OS, you can debug using XCode by running the command `swift package generate-xcodeproj` and the opening the resulting `HAP.xcodeproj` project. Select and run the `hap-server` target. | ||
|
||
- See also: [My Home](https://github.com/Bouke/My-Home/tree/master/Sources) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Use the `Device` instance to manage the setup code, accessories and controller pairings. You can assign a delegate to be notified of certain events. The `Server` manages IP connectivity and network discovery advertisements. |