Skip to content

Commit

Permalink
Align with rel.645 OpenZWave Driver.h enums
Browse files Browse the repository at this point in the history
  • Loading branch information
ekarak committed Mar 9, 2013
1 parent 7e5d6f7 commit 5d4b2f4
Show file tree
Hide file tree
Showing 13 changed files with 180 additions and 239 deletions.
4 changes: 2 additions & 2 deletions ansible_callback.rb
Expand Up @@ -108,7 +108,7 @@ def fire_callback(event, target=nil, *args)
if defined?(@callbacks) and @callbacks.is_a?Hash then if defined?(@callbacks) and @callbacks.is_a?Hash then
[@callbacks[event], @callbacks[:default]].each { |hsh| [@callbacks[event], @callbacks[:default]].each { |hsh|
if hsh.is_a?Hash then if hsh.is_a?Hash then
puts "#{self}.fire_callback, event #{event}: about to fire: #{hsh.inspect}" #puts "#{self}.fire_callback, event #{event}: about to fire: #{hsh.inspect}"
if target.nil? then if target.nil? then
# add all targets to the list of procs to call # add all targets to the list of procs to call
# including the default # including the default
Expand All @@ -124,7 +124,7 @@ def fire_callback(event, target=nil, *args)
# time to fire callbacks # time to fire callbacks
cb_procs.flatten.compact.each { |cb_proc| cb_procs.flatten.compact.each { |cb_proc|
raise "ooops, found a #{cb_proc.class} stored as a callback!" unless cb_proc.is_a?Proc raise "ooops, found a #{cb_proc.class} stored as a callback!" unless cb_proc.is_a?Proc
puts "firing #{event} callback, args: #{args.inspect}" # puts "firing #{event} callback, args: #{args.inspect}"
cb_proc.call(self, event.to_s, *args) cb_proc.call(self, event.to_s, *args)
} }
end end
Expand Down
28 changes: 22 additions & 6 deletions ansible_value.rb
Expand Up @@ -33,24 +33,40 @@ module AnsibleValue


include AnsibleCallback include AnsibleCallback


# every AnsibleValue has a previous and a current value. Note that previous_value
# is nil until the second call to set()
attr_reader :previous_value, :current_value attr_reader :previous_value, :current_value

# timestamp of last value update
attr_reader :last_update attr_reader :last_update

# generic hash of flags
attr_reader :flags attr_reader :flags


# return true if a value's instance variable (whose symbol is iv_symbol) matches a filter value (as a regexp) # returns true if a value's internal state matches using a hashmap, where each
# e.g. value.matches?(:name => /elias/, :telephone => /210/) # - key: is a symbol (the name of an instance variable)
def matches?(hash) # - value: is a Regexp (instance varriable matches regexp)
raise "#{self.class}: AnsibleValue.match? single argument must be a hash.." unless hash.is_a?Hash # OR an Array (instance var is contained in array)
# OR a Range (instance var in included in the range)
# OR a plain object (instance var == object)
# e.g. value.matches?(:name => /son$/, :age => 21..30)
# return true if a value's :name ends in son (Ericsson) and is aged between 21 and 30
# it is used to implement a simplistic O(n) AnsibleValue searching facility
def matches?(filtermap)
raise "#{self.class}: AnsibleValue.match? single argument must be a Hash!" unless filtermap.is_a?Hash
result = true result = true
hash.each { |iv_symbol, filter| filtermap.each { |iv_symbol, filter|
raise "#{self.class}: AnsibleValue.match?(hash)'s keys must be Symbols.." unless iv_symbol.is_a?Symbol raise "#{self.class}: Keys of AnsibleValue.match?(filtermap) must be Symbols!" unless iv_symbol.is_a?Symbol
if respond_to?(iv_symbol) and (val = instance_eval(iv_symbol.to_s)) then if respond_to?(iv_symbol) and (val = instance_eval(iv_symbol.to_s)) then
#puts "match.val(#{iv_symbol}) == #{val.inspect}" if $DEBUG #puts "match.val(#{iv_symbol}) == #{val.inspect}" if $DEBUG
result = result & case filter result = result & case filter
# if the filter is a regular expression, use it to match the instance value # if the filter is a regular expression, use it to match the instance value
when Regexp then filter.match(val.to_s) when Regexp then filter.match(val.to_s)
# if the filter is an array, use set intersection # if the filter is an array, use set intersection
when Array then (filter & val).length > 0 when Array then (filter & val).length > 0
# if the filter is a Range, use range inclusion
when Range then (filter === val)
# otherwise use plain equality
else filter == val else filter == val
end end
else else
Expand Down
8 changes: 8 additions & 0 deletions config.rb
Expand Up @@ -92,3 +92,11 @@ module OpenZWave
$:.push("/home/ekarak/ozw/Thrift4OZW/gen-rb") $:.push("/home/ekarak/ozw/Thrift4OZW/gen-rb")


end end

# from http://snippets.dzone.com/posts/show/2785
module Kernel
private
def this_method_name
caller[0] =~ /`([^']*)'/ and $1
end
end
2 changes: 1 addition & 1 deletion devices/ansible_dimmer.rb
Expand Up @@ -22,7 +22,7 @@
http://en.wikipedia.org/wiki/GNU_Lesser_General_Public_License http://en.wikipedia.org/wiki/GNU_Lesser_General_Public_License
=end =end


require 'ansible_device' require 'devices/ansible_switch'


module Ansible module Ansible


Expand Down
2 changes: 0 additions & 2 deletions devices/ansible_switch.rb
Expand Up @@ -22,8 +22,6 @@
http://en.wikipedia.org/wiki/GNU_Lesser_General_Public_License http://en.wikipedia.org/wiki/GNU_Lesser_General_Public_License
=end =end


require 'ansible_device'

module Ansible module Ansible


# #
Expand Down
76 changes: 0 additions & 76 deletions knx/knx_eistypes.rb

This file was deleted.

1 change: 1 addition & 0 deletions test1.rb
Expand Up @@ -39,6 +39,7 @@
sleep(3) sleep(3)


S = AnsibleValue[:_nodeId => 2, :_genre => 1] S = AnsibleValue[:_nodeId => 2, :_genre => 1]
AD = AnsibleValue[:_nodeId => 3, :_genre => 1]
D = AnsibleValue[:_nodeId => 5, :_genre => 1] D = AnsibleValue[:_nodeId => 5, :_genre => 1]
K = AnsibleValue[:_nodeId => 6, :_genre => 1] K = AnsibleValue[:_nodeId => 6, :_genre => 1]


Expand Down
2 changes: 1 addition & 1 deletion test2.rb
Expand Up @@ -31,7 +31,7 @@


require 'config' require 'config'


KNX = Ansible::KNX::KNX_Transceiver.new(Ansible::KNX_URL) KNX = Ansible::KNX::KNX_Transceiver.new(Ansible::KNX::KNX_URL)
# monitor all KNX activity # monitor all KNX activity
KNX.add_callback(:onKNXtelegram) { | sender, cb, frame | KNX.add_callback(:onKNXtelegram) { | sender, cb, frame |
if frame.dst_addr < 4048 then if frame.dst_addr < 4048 then
Expand Down
14 changes: 7 additions & 7 deletions test3.rb
Expand Up @@ -64,7 +64,7 @@
:_nodeId => 2, :_nodeId => 2,
:_genre => OpenZWave::RemoteValueGenre::ValueGenre_Basic][0] :_genre => OpenZWave::RemoteValueGenre::ValueGenre_Basic][0]
ZWDimmer = AnsibleValue[ ZWDimmer = AnsibleValue[
:_nodeId => 5, :_nodeId => 3,
:_genre => OpenZWave::RemoteValueGenre::ValueGenre_User, :_genre => OpenZWave::RemoteValueGenre::ValueGenre_User,
:_commandClassId => 38, #SWITCH_MULTILEVEL :_commandClassId => 38, #SWITCH_MULTILEVEL
:_valueIndex => 0][0] :_valueIndex => 0][0]
Expand All @@ -85,12 +85,12 @@


# map my ACT HomePro Lamp module to KNX # map my ACT HomePro Lamp module to KNX
DIMMER = Dimmer.new( DIMMER = Dimmer.new(
:master_control => ZWDimmer, :master_control => ZWDimmer, # ZWave node 3
:switch => KNXValue.new("1.001", "1/0/40"), :switch => KNXValue.new("1.001", "1/0/30"),
:switch_status => KNXValue.new("1.001", "1/0/41"), :switch_status => KNXValue.new("1.001", "1/0/31"),
:dimming => KNXValue.new('5.001', "1/0/42"), :dimming => KNXValue.new('5.001', "1/0/32"),
:dimming_status => KNXValue.new('5.001', "1/0/43"), :dimming_status => KNXValue.new('5.001', "1/0/33"),
:scene => KNXValue.new('18.001', "1/0/44") :scene => KNXValue.new('18.001', "1/0/34")
) )


# map my garden lights to ZWave # map my garden lights to ZWave
Expand Down
4 changes: 3 additions & 1 deletion transceiver.rb
Expand Up @@ -57,7 +57,9 @@ def run
def stop() def stop()
@thread.stop @thread.stop
end end


attr_reader :all_devices

end end


end end
29 changes: 20 additions & 9 deletions zwave/types/valuetype_list.rb
Expand Up @@ -32,30 +32,41 @@ module ValueType_List


# define type-specific OZW::Manager API calls # define type-specific OZW::Manager API calls
def read_operation def read_operation
raise 'FIXME' init_value_list
return :GetValueListItems return :GetValueListSelection_Int32
end end


def write_operation def write_operation
raise 'FIXME' init_value_list
return :SetValueListSelection return :SetValueListSelection
end end


# #
def as_canonical_value() def as_canonical_value()
puts 'TODO' init_value_list
selection_index = manager_send(:GetValueListSelection, self)
selection = @value_list[selection_index]
raise "Selection index #{selection} out of bounds" unless selection.is_a?String
end end


# # convert string to value list index
def to_protocol_value(new_val) def to_protocol_value(new_val)
result = nil init_value_list
if [TrueClass, FalseClass].include?(new_val.class) raise "ValueType_List: string '#{new_val}' not found in ValueListItems!"
result = new_val ? 1 : 0 return @value_list.index(new_val)
end
end end


# return a human-readable representation of a ZWave frame # return a human-readable representation of a ZWave frame
def explain def explain
init_value_list
@value_list[@current_value]
end

# initialize value list array
def init_value_list
unless @value_list.nil?
@value_list = manager_send(:GetValueListItems, self)
end
end end
end end


Expand Down

0 comments on commit 5d4b2f4

Please sign in to comment.