Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

Commit

Permalink
#20, #23 added config options to exclude devices from homekit and to …
Browse files Browse the repository at this point in the history
…override service. For now just power switches can be set to Lightbulb instead of Switch.
  • Loading branch information
michbeck100 committed Feb 10, 2016
1 parent e93bae5 commit 5ee9b93
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 4 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,34 @@ Please use 031-45-154 as pin, when pairing with the pimatic homekit bridge.

Every iOS app that works with homekit should work with this (like Elgato Eve), so no need for an Apple developer account.

#### Configuration

The configuration of pimatic can be extended by adding an attribute called "hap" on every supported device.
Example:

```json
"devices": [
{
"id": "switch",
"class": "DummySwitch",
"name": "Switch",
"hap": {
"service": "Lightbulb",
"exclude": true
}
}
]

```
To exclude devices from being registered as Homekit Accessory, just set the "exclude" flag to true. By default all supported devices will be registered.

For some devices it's possible to override the default Service (find the explanation of Services [here](https://github.com/KhaosT/HAP-NodeJS#api)).
This is helpful if e.g. a lamp is connected to a pimatic-enabled outlet. Changing the Service to "Lightbulb" will make Homekit recognize the outlet as light, not as switch. This may also change the commands, that one can use with Siri.

Since the "hap" attribute doesn't belong to the device config schema, pimatic will issue a warning,
that this is an unknown config entry. Maybe it will be officially possible to extend the configuration. Since then just ignore this warning.


### Sponsoring

Do you like this plugin? Then consider a donation to support development.
Expand Down
17 changes: 17 additions & 0 deletions accessories/base.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ module.exports = (env) ->
# base class for all homekit accessories in pimatic
class BaseAccessory extends Accessory

supportedServiceOverrides: {
"Lightbulb": Service.Lightbulb
}

hapConfig: null

constructor: (device) ->
@hapConfig = device.config.hap
serialNumber = uuid.generate('pimatic-hap:accessories:' + device.id)
super(device.name, serialNumber)
# accessories are reachable as long as the server lives
Expand Down Expand Up @@ -57,3 +64,13 @@ module.exports = (env) ->
callback(error, null)
)
.done()

exclude: =>
if @hapConfig != null && @hapConfig != undefined
return @hapConfig.exclude != null && @hapConfig.exclude
return false

getServiceOverride: (service) =>
if @hapConfig != null && @hapConfig != undefined && @hapConfig.service != null && @hapConfig.service != undefined && @hapConfig.service of @supportedServiceOverrides
return @supportedServiceOverrides[@hapConfig.service]
return service
8 changes: 5 additions & 3 deletions accessories/powerswitch.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@ module.exports = (env) ->
constructor: (device) ->
super(device)

@addService(Service.Switch, device.name)
service = @getServiceOverride(Service.Switch)

@addService(service, device.name)
.getCharacteristic(Characteristic.On)
.on 'set', (value, callback) =>
promise = if value then device.turnOn() else device.turnOff()
@handleVoidPromise(promise, callback)

@getService(Service.Switch)
@getService(service)
.getCharacteristic(Characteristic.On)
.on 'get', (callback) =>
@handleReturnPromise(device.getState(), callback, null)

device.on 'state', (state) =>
@getService(Service.Switch)
@getService(service)
.setCharacteristic(Characteristic.On, state)
2 changes: 1 addition & 1 deletion hap.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ module.exports = (env) =>
@framework.on 'deviceAdded', (device) =>
accessory = @createAccessoryFromTemplate(device)

if accessory?
if !accessory?.exclude()
bridge.addBridgedAccessory(accessory)
env.logger.debug("successfully added device " + device.name)

Expand Down

0 comments on commit 5ee9b93

Please sign in to comment.