Any idea what I’m doing wrong with the ‘halock’?
widgets/halock/halock.coffee
class Dashing.Halock extends Dashing.ClickableWidget
constructor: ->
super
@queryState()
@accessor 'state',
get: -> @_state ? 'unlocked'
set: (key, value) -> @_state = value
@accessor 'icon',
get: -> if @get('state') == 'unlocked' then 'unlock-alt' else 'lock'
set: Batman.Property.defaultAccessor.set
@accessor 'icon-style', ->
if @get('state') == 'locked' then 'icon-locked' else 'icon-unlocked'
toggleState: ->
newState = if @get('state') == 'locked' then 'unlock' else 'lock'
@set 'state', newState
return newState
queryState: ->
$.get '/homeassistant/lock',
widgetId: @get('id'),
deviceType: 'lock',
deviceId: @get('device')
(data) =>
json = JSON.parse data
@set 'state', json.state
postState: ->
newState = @toggleState()
$.post '/homeassistant/lock',
deviceType: 'lock',
deviceId: @get('device'),
command: newState,
(data) =>
json = JSON.parse data
if json.error != 0
@toggleState()
ready: ->
onData: (data) ->
onClick: (event) ->
@postState()
widgets/halock/halock.scss
// ----------------------------------------------------------------------------
// Widget styles
// ----------------------------------------------------------------------------
.widget-halock {
background-color: #444 !important;
.title {
color: #fff;
}
.icon-unlocked {
color: #ff00aa;
}
.icon-locked {
color: #fff;
}
}
widgets/halock/halock.html
<h1 class="title" data-bind="title"></h1>
<h2 data-bind-class="icon-style"><i data-bind-class="icon | prepend 'fa fa-'"></i></h2>
jobs/homeassistant.rb
get '/homeassistant/lock' do
response = ha_api("states/lock." + params["widgetId"], "get")
return JSON.generate({"state" => response["state"]})
end
post '/homeassistant/lock' do
entity_id = "lock." + params["widgetId"]
command = "lock"
if params["command"] == "unlock"
command = "unlock"
else
command = "lock"
end
ha_api("services/lock/" + command, "post", {"entity_id" => entity_id})
return respondWithSuccess()
end
hapush/hapush.py
def dashboard_update(widget_id, type, state):
try:
.....
elif type == "lock":
values = {"state": state['state']}
logger.info("lock." + widget_id + " -> " + state['state'])
call_ha(widget_id, values)
......
views = {
"Hadevicetracker": "device_tracker",
"Hagarage": "garage_door",
"Halock": "lock",
......
Here is the log file and the error that I’m confident coincides with when I click the widget:
2016-07-08 22:36:18 - TypeError - no implicit conversion of nil into String:
/var/opt/hadashboard/jobs/homeassistant.rb:66:in `+'
/var/opt/hadashboard/jobs/homeassistant.rb:66:in `block in <top (required)>'
/var/lib/gems/2.1.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:1611:in `call'
/var/lib/gems/2.1.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:1611:in `block in compile!'
/var/lib/gems/2.1.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:975:in `[]'
/var/lib/gems/2.1.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:975:in `block (3 levels) in route!'
/var/lib/gems/2.1.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:994:in `route_eval'
/var/lib/gems/2.1.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:975:in `block (2 levels) in route!'
/var/lib/gems/2.1.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:1015:in `block in process_route'
/var/lib/gems/2.1.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:1013:in `catch'
/var/lib/gems/2.1.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:1013:in `process_route'
/var/lib/gems/2.1.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:973:in `block in route!'
/var/lib/gems/2.1.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:972:in `each'
/var/lib/gems/2.1.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:972:in `route!'
/var/lib/gems/2.1.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:1085:in `block in dispatch!'
/var/lib/gems/2.1.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:1067:in `block in invoke'
/var/lib/gems/2.1.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:1067:in `catch'
/var/lib/gems/2.1.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:1067:in `invoke'
/var/lib/gems/2.1.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:1082:in `dispatch!'
/var/lib/gems/2.1.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:907:in `block in call!'
/var/lib/gems/2.1.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:1067:in `block in invoke'
/var/lib/gems/2.1.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:1067:in `catch'
/var/lib/gems/2.1.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:1067:in `invoke'
/var/lib/gems/2.1.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:907:in `call!'
/var/lib/gems/2.1.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:895:in `call'
/var/lib/gems/2.1.0/gems/rack-protection-1.5.3/lib/rack/protection/xss_header.rb:18:in `call'
/var/lib/gems/2.1.0/gems/rack-protection-1.5.3/lib/rack/protection/path_traversal.rb:16:in `call'
/var/lib/gems/2.1.0/gems/rack-protection-1.5.3/lib/rack/protection/json_csrf.rb:18:in `call'
/var/lib/gems/2.1.0/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
/var/lib/gems/2.1.0/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
/var/lib/gems/2.1.0/gems/rack-protection-1.5.3/lib/rack/protection/frame_options.rb:31:in `call'
/var/lib/gems/2.1.0/gems/rack-1.5.5/lib/rack/logger.rb:15:in `call'
/var/lib/gems/2.1.0/gems/rack-1.5.5/lib/rack/commonlogger.rb:33:in `call'
/var/lib/gems/2.1.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:219:in `call'
/var/lib/gems/2.1.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:212:in `call'
/var/lib/gems/2.1.0/gems/rack-1.5.5/lib/rack/head.rb:11:in `call'
/var/lib/gems/2.1.0/gems/rack-1.5.5/lib/rack/methodoverride.rb:21:in `call'
/var/lib/gems/2.1.0/gems/sinatra-1.4.7/lib/sinatra/show_exceptions.rb:25:in `call'
/var/lib/gems/2.1.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:182:in `call'
/var/lib/gems/2.1.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:2013:in `call'
/var/lib/gems/2.1.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:1487:in `block in call'
/var/lib/gems/2.1.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:1787:in `synchronize'
/var/lib/gems/2.1.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:1487:in `call'
/var/lib/gems/2.1.0/gems/rack-1.5.5/lib/rack/urlmap.rb:65:in `block in call'
/var/lib/gems/2.1.0/gems/rack-1.5.5/lib/rack/urlmap.rb:50:in `each'
/var/lib/gems/2.1.0/gems/rack-1.5.5/lib/rack/urlmap.rb:50:in `call'
/var/lib/gems/2.1.0/gems/thin-1.6.4/lib/thin/connection.rb:86:in `block in pre_process'
/var/lib/gems/2.1.0/gems/thin-1.6.4/lib/thin/connection.rb:84:in `catch'
/var/lib/gems/2.1.0/gems/thin-1.6.4/lib/thin/connection.rb:84:in `pre_process'
/var/lib/gems/2.1.0/gems/thin-1.6.4/lib/thin/connection.rb:53:in `process'
/var/lib/gems/2.1.0/gems/thin-1.6.4/lib/thin/connection.rb:39:in `receive_data'
/var/lib/gems/2.1.0/gems/eventmachine-1.2.0.1/lib/eventmachine.rb:194:in `run_machine'
/var/lib/gems/2.1.0/gems/eventmachine-1.2.0.1/lib/eventmachine.rb:194:in `run'
/var/lib/gems/2.1.0/gems/thin-1.6.4/lib/thin/backends/base.rb:73:in `start'
/var/lib/gems/2.1.0/gems/thin-1.6.4/lib/thin/server.rb:162:in `start'
/var/lib/gems/2.1.0/gems/thin-1.6.4/lib/thin/controllers/controller.rb:87:in `start'
/var/lib/gems/2.1.0/gems/thin-1.6.4/lib/thin/runner.rb:200:in `run_command'
/var/lib/gems/2.1.0/gems/thin-1.6.4/lib/thin/runner.rb:156:in `run!'
/var/lib/gems/2.1.0/gems/thin-1.6.4/bin/thin:6:in `<top (required)>'
/usr/local/bin/thin:23:in `load'
/usr/local/bin/thin:23:in `<top (required)>'
/var/lib/gems/2.1.0/gems/bundler-1.12.5/lib/bundler/cli/exec.rb:63:in `load'
/var/lib/gems/2.1.0/gems/bundler-1.12.5/lib/bundler/cli/exec.rb:63:in `kernel_load'
/var/lib/gems/2.1.0/gems/bundler-1.12.5/lib/bundler/cli/exec.rb:24:in `run'
/var/lib/gems/2.1.0/gems/bundler-1.12.5/lib/bundler/cli.rb:304:in `exec'
/var/lib/gems/2.1.0/gems/bundler-1.12.5/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/var/lib/gems/2.1.0/gems/bundler-1.12.5/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
/var/lib/gems/2.1.0/gems/bundler-1.12.5/lib/bundler/vendor/thor/lib/thor.rb:359:in `dispatch'
/var/lib/gems/2.1.0/gems/bundler-1.12.5/lib/bundler/vendor/thor/lib/thor/base.rb:440:in `start'
/var/lib/gems/2.1.0/gems/bundler-1.12.5/lib/bundler/cli.rb:11:in `start'
/var/lib/gems/2.1.0/gems/bundler-1.12.5/exe/bundle:27:in `block in <top (required)>'
/var/lib/gems/2.1.0/gems/bundler-1.12.5/lib/bundler/friendly_errors.rb:98:in `with_friendly_errors'
/var/lib/gems/2.1.0/gems/bundler-1.12.5/exe/bundle:19:in `<top (required)>'
/usr/local/bin/bundle:23:in `load'
/usr/local/bin/bundle:23:in `<main>'
And this is line 66 in homeassistant.rb:
response = ha_api("states/lock." + params["widgetId"], "get")