Skip to content

Commit

Permalink
Merge pull request #3 from sweebee/master
Browse files Browse the repository at this point in the history
Added PIR and Contact devices
  • Loading branch information
sirchia committed Feb 9, 2016
2 parents c994caa + d5c7ae0 commit 4f49d96
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 121 deletions.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,38 @@ is used for sending or receiving. Default is `true` for both.
"switch": "1"
}]
}
```

### ContactSensor example:
```json
{
"id": "window",
"name": "Window",
"class": "RFLinkContactSensor",
"autoReset": false,
"protocols": [
{
"name": "NewKaku",
"id": "00d199ee",
"switch": "1"
}
]
},
```

### PIR sensor example:
```json
{
"id": "movement",
"name": "Movement",
"class": "RFLinkPir",
"autoReset": false,
"protocols": [
{
"name": "NewKaku",
"id": "00d189ee",
"switch": "1"
}
]
},
```
122 changes: 64 additions & 58 deletions device-config-schema.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -68,35 +68,38 @@ module.exports = {
default: true
required: ["protocols"]
},
# RFLinkContactSensor: {
# title: "RFLinkContactSensor config options"
# type: "object"
# extensions: ["xConfirm", "xLink", "xClosedLabel", "xOpenedLabel"]
# properties:
# protocols:
# description: "The protocols to use."
# type: "array"
# default: []
# format: "table"
# items:
# type: "object"
# properties:
# name:
# type: "string"
# options:
# description: "The protocol options"
# type: "object"
# autoReset:
# description: """Reset the state after resetTime. Useful for contact sensors,
# that only emit open or close events"""
# type: "boolean"
# default: false
# resetTime:
# description: """Time after that the contact state is reseted."""
# type: "integer"
# default: 10000
# required: ["protocols"]
# }
RFLinkContactSensor: {
title: "RFLinkContactSensor config options"
type: "object"
extensions: ["xConfirm", "xLink", "xClosedLabel", "xOpenedLabel"]
properties:
protocols:
description: "The switch protocols to use."
type: "array"
default: []
format: "table"
items:
type: "object"
properties:
name:
type: "string"
id:
description: "The device/home id of the switch"
type: "string"
switch:
description: "The button id of the switch"
type: "string"
required: ["name", "id", "switch"]
autoReset:
description: "Reset the state after resetTime. Useful for pir sensors that emit a absent signal"
type: "boolean"
default: true
resetTime:
description: "Time after that the presence value is reset to absent."
type: "integer"
default: 10000
required: ["protocols"]
}
# RFLinkShutter: {
# title: "RFLinkShutter config options"
# type: "object"
Expand Down Expand Up @@ -245,33 +248,36 @@ module.exports = {
# type: "string"
# required: false
# }
# RFLinkPir: {
# title: "RFLinkPir config options"
# type: "object"
# extensions: ["xLink", "xPresentLabel", "xAbsentLabel"]
# properties:
# protocols:
# description: "The protocols to use."
# type: "array"
# default: []
# format: "table"
# items:
# type: "object"
# properties:
# name:
# type: "string"
# options:
# description: "The protocol options"
# type: "object"
# autoReset:
# description: """Reset the state after resetTime. Useful for pir sensors,
# that emit present and absent events"""
# type: "boolean"
# default: true
# resetTime:
# description: "Time after that the presence value is reset to absent."
# type: "integer"
# default: 10000
# required: ["protocols"]
# }
RFLinkPir: {
title: "RFLinkPir config options"
type: "object"
extensions: ["xLink", "xPresentLabel", "xAbsentLabel"]
properties:
protocols:
description: "The switch protocols to use."
type: "array"
default: []
format: "table"
items:
type: "object"
properties:
name:
type: "string"
id:
description: "The device/home id of the switch"
type: "string"
switch:
description: "The button id of the switch"
type: "string"
required: ["name", "id", "switch"]
autoReset:
description: "Reset the state after resetTime. Useful for pir sensors that don't emit a absent signal"
type: "boolean"
default: true
resetTime:
description: "Time after that the presence value is reset to absent."
type: "integer"
default: 10000
required: ["protocols"]
}
}
106 changes: 43 additions & 63 deletions rflink.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ module.exports = (env) ->
RFLinkDimmer
# RFLinkTemperature
# RFLinkWeatherStation
# RFLinkPir
# RFLinkContactSensor
RFLinkPir
RFLinkContactSensor
# RFLinkShutter
# RFLinkGenericSensor
]
Expand Down Expand Up @@ -238,35 +238,25 @@ module.exports = (env) ->
)


# class RFLinkContactSensor extends env.devices.ContactSensor
#
# constructor: (@config, lastState, @board, @_pluginConfig) ->
# @id = config.id
# @name = config.name
# @_contact = lastState?.contact?.value or false
#
# for p in config.protocols
# _protocol = Board.getRfProtocol(p.name)
# unless _protocol?
# throw new Error("Could not find a protocol with the name \"#{p.name}\".")
#
# @board.on('rf', (event) =>
# for p in @config.protocols
# match = doesProtocolMatch(event, p)
# if match
# hasContact = (
# if event.values.contact? then event.values.contact
# else (not event.values.state)
# )
# @_setContact(hasContact)
# if @config.autoReset is true
# clearTimeout(@_resetContactTimeout)
# @_resetContactTimeout = setTimeout(( =>
# @_setContact(!hasContact)
# ), @config.resetTime)
# )
# super()
#
class RFLinkContactSensor extends env.devices.ContactSensor

constructor: (@config, lastState, @board, @_pluginConfig, @protocol) ->
@id = config.id
@name = config.name
@_contact = lastState?.contact?.value or false

@board.on('rf', (event) =>
for p in @config.protocols
if @protocol.switchEventMatches(event, p)
@_setContact(event.cmd.state)
if @config.autoReset is true
clearTimeout(@_resetContactTimeout)
@_resetContactTimeout = setTimeout(( =>
@_setContact(!event.cmd.state)
), @config.resetTime)
)
super()

# class RFLinkShutter extends env.devices.ShutterController
#
# constructor: (@config, lastState, @board, @_pluginConfig) ->
Expand Down Expand Up @@ -317,38 +307,28 @@ module.exports = (env) ->
# )
#
#
# class RFLinkPir extends env.devices.PresenceSensor
#
# constructor: (@config, lastState, @board, @_pluginConfig) ->
# @id = config.id
# @name = config.name
# @_presence = lastState?.presence?.value or false
#
# for p in config.protocols
# _protocol = Board.getRfProtocol(p.name)
# unless _protocol?
# throw new Error("Could not find a protocol with the name \"#{p.name}\".")
# unless _protocol.type is "pir"
# throw new Error("\"#{p.name}\" is not a PIR protocol.")
#
# resetPresence = ( =>
# @_setPresence(no)
# )
#
# @board.on('rf', (event) =>
# for p in @config.protocols
# match = doesProtocolMatch(event, p)
# if match
# unless @_setPresence is event.values.presence
# @_setPresence(event.values.presence)
# clearTimeout(@_resetPresenceTimeout)
# if @config.autoReset is true
# @_resetPresenceTimeout = setTimeout(resetPresence, @config.resetTime)
# )
# super()
#
# getPresence: -> Promise.resolve @_presence
#
class RFLinkPir extends env.devices.PresenceSensor

constructor: (@config, lastState, @board, @_pluginConfig, @protocol) ->
@id = config.id
@name = config.name
@_presence = lastState?.presence?.value or false

resetPresence = ( =>
@_setPresence(no)
)

@board.on('rf', (event) =>
for p in @config.protocols
if @protocol.switchEventMatches(event, p)
@_setPresence(event.cmd.state)
if @config.autoReset is true
@_resetPresenceTimeout = setTimeout(resetPresence, @config.resetTime)
)
super()

getPresence: -> Promise.resolve @_presence

#
# class RFLinkTemperature extends env.devices.TemperatureSensor
#
Expand Down

0 comments on commit 4f49d96

Please sign in to comment.