Permalink
Browse files

sync with OZW r488 value notification new behaviour

  • Loading branch information...
1 parent 56e75a5 commit 7e5d6f76ee91077f81e8821e1a51fcdbcd84b530 Elias Karakoulakis committed Mar 1, 2012
View
@@ -29,17 +29,16 @@
module Ansible
# STOMP Server URL
- STOMP_URL = 'stomp://192.168.0.51'
+ STOMP_URL = 'stomp://localhost'
#
# KNX subsystem configuration
#
module KNX
- # KNX eibd URL
- #KNX_URL = "local:/tmp/eib"
+ # KNX eibd server URL (not the actual KNX interface URL!)
+ KNX_URL = "local:/tmp/eib"
#KNX_URL = "ip:localhost"
- KNX_URL = "ip:192.168.0.100"
###################
# KNX MONITOR TOPIC:
@@ -70,14 +69,14 @@ module ZWave
# header =>
# body =>
#ZWAVE_COMMAND_TOPIC = "/queue/knx/command"
-
+
+ #################
# OpenZWave Thrift Server URL
- #THRIFT_URL = 'thrift://localhost'
- THRIFT_URL = 'thrift://192.168.0.100'
+ THRIFT_URL = 'thrift://localhost'
+ #THRIFT_URL = 'thrift://192.168.0.100'
ThriftPort = 9090
- # HomeID is discovered automatically
- # HomeID = 0x00006258
+
end
end
View
@@ -34,8 +34,8 @@ def link
switch = @hashmap[:switch]
status = @hashmap[:switch_status]
master = @hashmap[:master_control]
- if [switch, master].find{|v| not v.is_a?AnsibleValue}
- raise "#{self}.link: must supply AnsibleValues for :master_control and:switch!"
+ unless [switch, master].select{ |v| not v.is_a? AnsibleValue }.empty?
+ raise "#{self}.link: must supply AnsibleValues for :master_control and :switch!"
end
# map switch value updates to master_control
switch.add_callback(:onUpdate, self) { |sender, cb, args|
@@ -47,16 +47,19 @@ def link
master.set(newval)
}
# also update status value, if defined
- master.add_callback(:onUpdate, self) { |sender, cb, args|
- # convert value domains
- cv = sender.as_canonical_value
- newval = master.to_protocol_value(cv)
- #
- status = @hashmap[:switch_status]
- puts " updating on/off status value (#{status}) new val=#{newval}!"
- status.set(newval)
- } if status.is_a?AnsibleValue
- end
+ if status.is_a?AnsibleValue then
+ puts "...also adding status feedback command #{status}"
+ master.add_callback(:onUpdate, self) { |sender, cb, args|
+ # convert value domains
+ cv = sender.as_canonical_value
+ newval = master.to_protocol_value(cv)
+ #
+ status = @hashmap[:switch_status]
+ puts " updating on/off status value (#{status}) new val=#{newval}!"
+ status.set(newval)
+ }
+ end
+ end #def
end
View
@@ -81,7 +81,7 @@
:master_control => ZWSwitch,
:switch => KNXValue.new("1.001", "1/0/20"),
:switch_status => KNXValue.new("1.001", "1/0/21")
- )
+ ) if ZWSwitch
# map my ACT HomePro Lamp module to KNX
DIMMER = Dimmer.new(
@@ -97,7 +97,7 @@
GARDEN = Switch.new(
:master_control => KNXValue.new("1.001", "1/0/1"),
:switch => ZWSwitch
- )
+ ) if ZWSwitch
KOUZINA1 = Switch.new(
:master_control => ZWKouzina[0],
@@ -108,6 +108,7 @@
KOUZINA2 = Switch.new(
:master_control => ZWKouzina[1],
:switch => KNXValue.new("1.001", "1/0/62"),
+ #:switch => KNXValue.new("1.001", "5/0/2"), # fancy radar
:switch_status => KNXValue.new("1.001", "1/0/63")
)
@@ -41,7 +41,6 @@ def write_operation
#
def as_canonical_value()
- puts 'zwave_bool: as_canonical'
return (
case
when [TrueClass, FalseClass].include?(current_value.class) then current_value
@@ -50,12 +49,11 @@ def as_canonical_value()
)
end
- #
+ # map any ruby value to boolean
def to_protocol_value(new_val)
- puts 'zwave_bool: to_protocol'
return (
case
- when new_value.is_a?(Fixnum) then (new_value > 0)
+ when [Fixnum].include?(new_val.class) then (new_val > 0)
when [TrueClass, FalseClass].include?(new_val.class) then new_val
when new_val.nil? then false
else true
@@ -65,6 +63,7 @@ def to_protocol_value(new_val)
# return a human-readable representation of a ZWave frame
def explain
+ puts "cv = #{@current_value}"
return(@current_value? "ON":"OFF")
end
end
@@ -32,10 +32,12 @@ module ValueType_List
# define type-specific OZW::Manager API calls
def read_operation
+ raise 'FIXME'
return :GetValueListItems
end
def write_operation
+ raise 'FIXME'
return :SetValueListSelection
end
@@ -41,16 +41,14 @@ def write_operation
#
def as_canonical_value()
puts 'TODO:: zwave_string: as_canonical'
- return (current_value > 0)
+ return (current_value)
end
#
def to_protocol_value(new_val)
puts 'TODO:: zwave_string: to_protocol'
result = nil
- if [TrueClass, FalseClass].include?(new_val.class)
- result = new_val ? 1 : 0
- end
+ result = new_val.to_s if [TrueClass, FalseClass].include?(new_val.class)
end
# return a human-readable representation of a ZWave frame
View
@@ -158,14 +158,14 @@ def manager_send(meth, *args)
result = manager.method(meth).call(*args)
rescue Thrift::TransportException => e
@thrift_ok = false
- puts "Thrift transport exception: retrying in 1 sec..."
- puts "... meth=#{meth.inspect}, callers=\n\t" + caller.join("\n\t")
+ puts "Thrift transport exception, in method #{meth.inspect}"
+ puts "--------------------------, callers=\n\t\t" + caller[0..2].join("\n\t\t")
sleep(1)
retry
rescue Exception => e
- @thrift_ok = false
- puts "Other exception: #{e}"
- puts "... meth=#{meth.inspect}, callers=\n\t" + caller.join("\n\t")
+ @thrift_ok = false
+ puts "OpenZWave exception: #{e}, in method #{meth.inspect}"
+ puts "--------------------, callers=\n\t\t" + caller[0..2].join("\n\t\t")
end
}
return(result)
@@ -253,12 +253,17 @@ def notification_ValueChanged(nodeId, byte, value)
# reported by OpenZWave is unchanged. Thus we need to poll the
# device using :RequestNodeDynamic, wait for NodeQueriesComplete
# then re-get the value
- trigger_value_monitor(value)
+ #trigger_value_monitor(value)
+ #
+ # as of r471 ValueChanged behaves correctly
+ AnsibleValue[:_nodeId => nodeId, :_gerne => 1].each { |v|
+ v.get
+ }
end
# A node value has been refreshed from the Z-Wave network.
def notification_ValueRefreshed(nodeId, byte, value)
- puts "Value #{value} refreshed!!!"
+ #value.get unless value.nil?
end
# The associations for the node have changed. The application
@@ -297,7 +302,7 @@ def notification_NodeProtocolInfo(nodeId, byte, value)
# One of the node names has changed (name, manufacturer, product).
def notification_NodeNaming(nodeId, byte, value)
- ptus 'TODO'
+ puts 'TODO'
end
# A node has triggered an event. This is commonly caused when a node
@@ -346,13 +351,13 @@ def notification_MsgComplete(nodeId, byte, value)
# The queries on a node that are essential to its operation have
# been completed. The node can now handle incoming messages.
def notification_EssentialNodeQueriesComplete(nodeId, byte, value)
- puts "==> marking node #{nodeId} as refreshed"
#OpenZWave::RefreshedNodes[nodeId] = true
end
# All the initialisation queries on a node have been completed.
def notification_NodeQueriesComplete(nodeId, byte, value)
# node monitor phase 2:
+=begin
@ValueMonitorMutex.synchronize do
sleep(2)
AnsibleValue[:_nodeId => nodeId].each { |val|
@@ -363,6 +368,7 @@ def notification_NodeQueriesComplete(nodeId, byte, value)
fire_callback(:onMonitorStop)
puts "==> trigger change monitor ENDED<=="
end
+=end
end
# All awake nodes have been queried, so client application can
@@ -399,7 +405,8 @@ def controller_state(idx)
# TODO: remove all AnsibleValues upon completion of
- #
+=begin
+DEPRECATED since OZW rev.477
# Zwave value notification system only informs us about a _manual_
# operation of a ZWave node using a ValueChanged notification.
# We need to monitor that node in order to get the actual device status.
@@ -420,7 +427,7 @@ def trigger_value_monitor(nodeId)
end # unless
end # do
end
-
+=end
end #class
end
View
@@ -153,7 +153,8 @@ def read_value()
def write_value(new_val)
return(false) unless respond_to? :write_operation
if @@transceiver.manager_send(write_operation, self, new_val) then
- update(new_val)
+ # value can also be updated by ValueChanged notification
+ update(new_val)
return(true)
else
return(false)

0 comments on commit 7e5d6f7

Please sign in to comment.