Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Garage #30

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
59 changes: 59 additions & 0 deletions smartapps/DashingAccess.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ mappings {
POST: "postLock"
]
}
path("/garage") {
action: [
GET: "getGarage",
POST: "postGarage"
]
}
path("/mode") {
action: [
GET: "getMode",
Expand Down Expand Up @@ -157,6 +163,8 @@ def initialize() {
subscribe(contacts, "contact", contactHandler)
subscribe(location, locationHandler)
subscribe(locks, "lock", lockHandler)
subscribe(contacts, "contact", garageHandler)
subscribe(contacts, "door", garageHandler)
subscribe(motions, "motion", motionHandler)
subscribe(meters, "power", meterHandler)
subscribe(presences, "presence", presenceHandler)
Expand Down Expand Up @@ -266,6 +274,57 @@ def lockHandler(evt) {
notifyWidget(widgetId, ["state": evt.value])
}

//
// Z-Wave Garages
//
def getGarage() {
def deviceId = request.JSON?.deviceId
log.debug "getGarage ${deviceId}"

if (deviceId) {
registerWidget("contact", deviceId, request.JSON?.widgetId)

def whichGarage = contacts.find { it.displayName == deviceId }
if (!whichGarage) {
return respondWithStatus(404, "Device '${deviceId}' not found.")
} else {
return [
"deviceId": deviceId,
"state": whichGarage.currentContact]
}
}

def result = [:]
garages.each {
result[it.displayName] = [
"state": it.currentContact,
"widgetId": state.widgets.garage[it.displayName]]}

return result
}

def postGarage() {
def command = request.JSON?.command
def deviceId = request.JSON?.deviceId
log.debug "postGarage ${deviceId}, ${command}"

if (command && deviceId) {
def whichGarage = contacts.find { it.displayName == deviceId }
if (!whichGarage) {
return respondWithStatus(404, "Device '${deviceId}' not found.")
} else {
whichGarage."$command"()
}
}
return respondWithSuccess()
}

def garageHandler(evt) {
def widgetId = state.widgets.contact[evt.displayName]
notifyWidget(widgetId, ["state": evt.value])
}


//
// Meters
//
Expand Down
52 changes: 52 additions & 0 deletions widgets/stgarage/stgarage.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
class Dashing.Stgarage extends Dashing.ClickableWidget
constructor: ->
super
@queryState()

@accessor 'state',
get: -> @_state ? 'open'
set: (key, value) -> @_state = value

@accessor 'icon',
get: -> 'car'
set: Batman.Property.defaultAccessor.set

@accessor 'icon-style', ->
if @get('state') == 'open' then icon = 'icon-open'
if @get('state') == 'closed' then icon = 'icon-closed'
if @get('state') == 'opening' then icon = 'icon-opening'
if @get('state') == 'closing' then icon = 'icon-closing'
return icon

toggleState: ->
newState = if @get('state') == 'open' then 'close' else 'open'
@set 'state', newState
return newState

queryState: ->
$.get '/smartthings/dispatch',
widgetId: @get('id'),
deviceType: 'garage',
deviceId: @get('device')
(data) =>
json = JSON.parse data
@set 'state', json.state

postState: ->
newState = @toggleState()
$.post '/smartthings/dispatch',
deviceType: 'garage',
deviceId: @get('device'),
command: newState,
(data) =>
json = JSON.parse data
if json.error != 0
@toggleState()

ready: ->

onData: (data) ->

onClick: (event) ->
@postState()

3 changes: 3 additions & 0 deletions widgets/stgarage/stgarage.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<h1 class="title" data-bind="title"></h1>

<h2 data-bind-class="icon-style"><i data-bind-class="icon | prepend 'fa fa-'"></i></h2>
24 changes: 24 additions & 0 deletions widgets/stgarage/stgarage.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// ----------------------------------------------------------------------------
// Widget-stgarage styles
// ----------------------------------------------------------------------------
.widget-stgarage {

.title {
color: #fff;
}

.icon-open {
color: #ff00aa;
}
.icon-opening {
color: #ffff00;
}
.icon-closing {
color: #ffff00;
}

.icon-closed {
color: #888888;
}

}