ansible4ozw 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/ansible.rb +47 -0
- data/lib/ansible/ansible_callback.rb +142 -0
- data/lib/ansible/ansible_device.rb +68 -0
- data/lib/ansible/ansible_value.rb +179 -0
- data/lib/ansible/config.rb +92 -0
- data/lib/ansible/devices/ansible_dimmer.rb +80 -0
- data/lib/ansible/devices/ansible_switch.rb +66 -0
- data/lib/ansible/knx/EIBConnection.rb +2371 -0
- data/lib/ansible/knx/dpt/canonical_1bit.rb +54 -0
- data/lib/ansible/knx/dpt/dpt1.rb +224 -0
- data/lib/ansible/knx/dpt/dpt10.rb +85 -0
- data/lib/ansible/knx/dpt/dpt11.rb +72 -0
- data/lib/ansible/knx/dpt/dpt12.rb +61 -0
- data/lib/ansible/knx/dpt/dpt13.rb +100 -0
- data/lib/ansible/knx/dpt/dpt14.rb +87 -0
- data/lib/ansible/knx/dpt/dpt15.rb +72 -0
- data/lib/ansible/knx/dpt/dpt16.rb +67 -0
- data/lib/ansible/knx/dpt/dpt17.rb +65 -0
- data/lib/ansible/knx/dpt/dpt18.rb +66 -0
- data/lib/ansible/knx/dpt/dpt19.rb +100 -0
- data/lib/ansible/knx/dpt/dpt2.rb +156 -0
- data/lib/ansible/knx/dpt/dpt3.rb +104 -0
- data/lib/ansible/knx/dpt/dpt4.rb +75 -0
- data/lib/ansible/knx/dpt/dpt5.rb +124 -0
- data/lib/ansible/knx/dpt/dpt6.rb +73 -0
- data/lib/ansible/knx/dpt/dpt7.rb +146 -0
- data/lib/ansible/knx/dpt/dpt8.rb +118 -0
- data/lib/ansible/knx/dpt/dpt9.rb +204 -0
- data/lib/ansible/knx/dpt/tests/test_dpt10.rb +45 -0
- data/lib/ansible/knx/dpt/tests/test_dpt9.rb +60 -0
- data/lib/ansible/knx/hexdump.rb +113 -0
- data/lib/ansible/knx/knx_dpt.rb +58 -0
- data/lib/ansible/knx/knx_dpt_scalar.rb +62 -0
- data/lib/ansible/knx/knx_eistypes.rb +76 -0
- data/lib/ansible/knx/knx_protocol.rb +99 -0
- data/lib/ansible/knx/knx_scene.rb +48 -0
- data/lib/ansible/knx/knx_tools.rb +76 -0
- data/lib/ansible/knx/knx_transceiver.rb +237 -0
- data/lib/ansible/knx/knx_value.rb +327 -0
- data/lib/ansible/openzwave/ozw_constants.rb +11 -0
- data/lib/ansible/openzwave/ozw_headers.rb +80 -0
- data/lib/ansible/openzwave/ozw_remote_manager.rb +7615 -0
- data/lib/ansible/openzwave/ozw_types.rb +406 -0
- data/lib/ansible/orbiter_proxy.rb +12 -0
- data/lib/ansible/transceiver.rb +63 -0
- data/lib/ansible/zwave/types/valuetype_bool.rb +74 -0
- data/lib/ansible/zwave/types/valuetype_button.rb +63 -0
- data/lib/ansible/zwave/types/valuetype_byte.rb +78 -0
- data/lib/ansible/zwave/types/valuetype_decimal.rb +64 -0
- data/lib/ansible/zwave/types/valuetype_int.rb +63 -0
- data/lib/ansible/zwave/types/valuetype_list.rb +64 -0
- data/lib/ansible/zwave/types/valuetype_short.rb +63 -0
- data/lib/ansible/zwave/types/valuetype_string.rb +61 -0
- data/lib/ansible/zwave/zwave_command_classes.rb +113 -0
- data/lib/ansible/zwave/zwave_node.rb +5 -0
- data/lib/ansible/zwave/zwave_protocol.rb +52 -0
- data/lib/ansible/zwave/zwave_transceiver.rb +435 -0
- data/lib/ansible/zwave/zwave_value.rb +193 -0
- metadata +108 -0
data/lib/ansible.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
=begin
|
2
|
+
Project Ansible - An extensible home automation scripting framework
|
3
|
+
----------------------------------------------------
|
4
|
+
Copyright (c) 2011 Elias Karakoulakis <elias.karakoulakis@gmail.com>
|
5
|
+
|
6
|
+
SOFTWARE NOTICE AND LICENSE
|
7
|
+
|
8
|
+
Project Ansible is free software: you can redistribute it and/or modify
|
9
|
+
it under the terms of the GNU Lesser General Public License as published
|
10
|
+
by the Free Software Foundation, either version 3 of the License,
|
11
|
+
or (at your option) any later version.
|
12
|
+
|
13
|
+
Project Ansible is distributed in the hope that it will be useful,
|
14
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
GNU Lesser General Public License for more details.
|
17
|
+
|
18
|
+
You should have received a copy of the GNU Lesser General Public License
|
19
|
+
along with Project Ansible. If not, see <http://www.gnu.org/licenses/>.
|
20
|
+
|
21
|
+
for more information on the LGPL, see:
|
22
|
+
http://en.wikipedia.org/wiki/GNU_Lesser_General_Public_License
|
23
|
+
=end
|
24
|
+
|
25
|
+
$:.push(File.join(Dir.getwd, 'lib/ansible'))
|
26
|
+
$:.push(File.join(Dir.getwd, 'lib/ansible/devices'))
|
27
|
+
$:.push(File.join(Dir.getwd, 'lib/ansible/knx'))
|
28
|
+
$:.push(File.join(Dir.getwd, 'lib/ansible/openzwave'))
|
29
|
+
$:.push(File.join(Dir.getwd, 'lib/ansible/zwave'))
|
30
|
+
|
31
|
+
require "rubygems"
|
32
|
+
require "bundler/setup"
|
33
|
+
require 'config'
|
34
|
+
|
35
|
+
require 'transceiver'
|
36
|
+
require 'zwave_transceiver'
|
37
|
+
require 'zwave_command_classes'
|
38
|
+
|
39
|
+
require 'knx_transceiver'
|
40
|
+
require 'knx_tools'
|
41
|
+
require 'knx_value'
|
42
|
+
|
43
|
+
require 'ansible_device'
|
44
|
+
|
45
|
+
include Ansible
|
46
|
+
include Ansible::ZWave
|
47
|
+
include Ansible::KNX
|
@@ -0,0 +1,142 @@
|
|
1
|
+
=begin
|
2
|
+
Project Ansible - An extensible home automation scripting framework
|
3
|
+
----------------------------------------------------
|
4
|
+
Copyright (c) 2011 Elias Karakoulakis <elias.karakoulakis@gmail.com>
|
5
|
+
|
6
|
+
SOFTWARE NOTICE AND LICENSE
|
7
|
+
|
8
|
+
Project Ansible is free software: you can redistribute it and/or modify
|
9
|
+
it under the terms of the GNU Lesser General Public License as published
|
10
|
+
by the Free Software Foundation, either version 3 of the License,
|
11
|
+
or (at your option) any later version.
|
12
|
+
|
13
|
+
Project Ansible is distributed in the hope that it will be useful,
|
14
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
GNU Lesser General Public License for more details.
|
17
|
+
|
18
|
+
You should have received a copy of the GNU Lesser General Public License
|
19
|
+
along with Project Ansible. If not, see <http://www.gnu.org/licenses/>.
|
20
|
+
|
21
|
+
for more information on the LGPL, see:
|
22
|
+
http://en.wikipedia.org/wiki/GNU_Lesser_General_Public_License
|
23
|
+
=end
|
24
|
+
|
25
|
+
require 'weakref'
|
26
|
+
|
27
|
+
module Ansible
|
28
|
+
|
29
|
+
#
|
30
|
+
# Callback module for project Ansible
|
31
|
+
#
|
32
|
+
module AnsibleCallback
|
33
|
+
|
34
|
+
|
35
|
+
# callback declaration mechanism.
|
36
|
+
#
|
37
|
+
# ===Arguments:
|
38
|
+
# [event] a Symbol for the event (eg :onChange)
|
39
|
+
# A special case is :default , this callback gets called at all events.
|
40
|
+
# [target] a unique hashable target (so as to register a target-specific callback
|
41
|
+
# for an event) - you can pass any value, if it can be hashed.
|
42
|
+
# TODO: use WeakRef,so that the target can be reclaimed by Ruby's GC
|
43
|
+
# when its fixed on Ruby1.9 (http://bugs.ruby-lang.org/issues/4168)
|
44
|
+
# [cb_body] the Proc to call when a callback is fired.
|
45
|
+
#
|
46
|
+
# the callback Proc block always gets these arguments supplied:
|
47
|
+
# [obj] 1st argument to callback proc is the AnsibleValue instance
|
48
|
+
# which generated the callback
|
49
|
+
# [cb] 2nd argument is the callback symbol (eg :onChange)
|
50
|
+
# Very useful when declaring a default callback
|
51
|
+
# [*args] 3rd and later arguments: event-specific data
|
52
|
+
#
|
53
|
+
# examples:
|
54
|
+
# obj.add_callback(:onChange) { |o| puts "Object #{o} has changed!" }
|
55
|
+
# obj.add_callback(:onChange, 'SPECIAL') { |o| puts "Object #{o} has changed!" }
|
56
|
+
# obj.add_callback(:default) { |o, cb, *args| puts "Object #{o}: callback #{cb}!" }
|
57
|
+
def add_callback(event, target=nil, &cb_body)
|
58
|
+
raise "add_callback: last argument must be a Proc" unless cb_body.is_a?Proc
|
59
|
+
init_callbacks(event)
|
60
|
+
puts "#{self}: Registering #{event} callback" + (target.nil? ? '' : " especially for target #{target}")
|
61
|
+
if target.nil? then
|
62
|
+
@callbacks[event].default = cb_body
|
63
|
+
else
|
64
|
+
@callbacks[event][target] = cb_body
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# remove a callback
|
69
|
+
#
|
70
|
+
# ===Arguments:
|
71
|
+
# [event] a Symbol for the event (eg :onChange)
|
72
|
+
# A special case is :default , this callback gets called at all events.
|
73
|
+
# [target] a unique hashable target - you can pass any value
|
74
|
+
#
|
75
|
+
# ===Examples:
|
76
|
+
# obj.remove_callback(:onUpdate)
|
77
|
+
def remove_callback(event, target=nil)
|
78
|
+
init_callbacks(event)
|
79
|
+
@callbacks[event].delete(target)
|
80
|
+
end
|
81
|
+
|
82
|
+
# callback firing processor.
|
83
|
+
#
|
84
|
+
# Checks if a proc is stored for a ginen event, then calls it
|
85
|
+
# with the object instance as its first argument, the callback symbol
|
86
|
+
# as its second arg, and all other *args appended to the call
|
87
|
+
#
|
88
|
+
# ===Arguments:
|
89
|
+
# [event] a Symbol for the event (eg :onChange)
|
90
|
+
# [target] the unique id of target (so as to fire target-specific callbacks for a specific event)
|
91
|
+
#
|
92
|
+
# ===Notes:
|
93
|
+
# 1) its prohibited to fire the DEFAULT callback programmatically (it will get fired
|
94
|
+
# anyway at ANY event)
|
95
|
+
# 2) if a target_id is given, then try to fire target-specific callbacks. If none is found,
|
96
|
+
# fall-back to the generic callback for this event
|
97
|
+
#
|
98
|
+
# ===Example:
|
99
|
+
# obj.fire_callback(:onChange, 'GROUPADDR', :arg1, :arg2, :arg3)
|
100
|
+
#
|
101
|
+
def fire_callback(event, target=nil, *args)
|
102
|
+
raise "cannot fire DEFAULT callback programmatically!" if event.to_s == "default"
|
103
|
+
#puts "fire_callback called by #{self}.#{event}, args: #{args.inspect}"
|
104
|
+
init_callbacks(event)
|
105
|
+
# array of callback Procs to get called
|
106
|
+
cb_procs = []
|
107
|
+
# first add callbacks for this specific event
|
108
|
+
if defined?(@callbacks) and @callbacks.is_a?Hash then
|
109
|
+
[@callbacks[event], @callbacks[:default]].each { |hsh|
|
110
|
+
if hsh.is_a?Hash then
|
111
|
+
puts "#{self}.fire_callback, event #{event}: about to fire: #{hsh.inspect}"
|
112
|
+
if target.nil? then
|
113
|
+
# add all targets to the list of procs to call
|
114
|
+
# including the default
|
115
|
+
cb_procs << [hsh.values, hsh.default].flatten
|
116
|
+
else
|
117
|
+
# only add target-specific procs to the list
|
118
|
+
cb_procs << hsh[target]
|
119
|
+
end
|
120
|
+
end
|
121
|
+
}
|
122
|
+
end
|
123
|
+
#puts cb_procs.inspect
|
124
|
+
# time to fire callbacks
|
125
|
+
cb_procs.flatten.compact.each { |cb_proc|
|
126
|
+
raise "ooops, found a #{cb_proc.class} stored as a callback!" unless cb_proc.is_a?Proc
|
127
|
+
puts "firing #{event} callback, args: #{args.inspect}"
|
128
|
+
cb_proc.call(self, event.to_s, *args)
|
129
|
+
}
|
130
|
+
end
|
131
|
+
|
132
|
+
private
|
133
|
+
# initialize callback hash for a given event
|
134
|
+
def init_callbacks(event)
|
135
|
+
md = caller[1].match(/`(\w*)'/); clr = md and md[1] or caller[1]
|
136
|
+
raise "#{clr}: no event Symbol supplied!" unless event.is_a?Symbol
|
137
|
+
@callbacks = {} unless defined?(@callbacks) and @callbacks.is_a?Hash
|
138
|
+
@callbacks[event] = {} unless @callbacks[event].is_a?Hash
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
end #module
|
@@ -0,0 +1,68 @@
|
|
1
|
+
=begin
|
2
|
+
Project Ansible - An extensible home automation scripting framework
|
3
|
+
----------------------------------------------------
|
4
|
+
Copyright (c) 2011 Elias Karakoulakis <elias.karakoulakis@gmail.com>
|
5
|
+
|
6
|
+
SOFTWARE NOTICE AND LICENSE
|
7
|
+
|
8
|
+
Project Ansible is free software: you can redistribute it and/or modify
|
9
|
+
it under the terms of the GNU Lesser General Public License as published
|
10
|
+
by the Free Software Foundation, either version 3 of the License,
|
11
|
+
or (at your option) any later version.
|
12
|
+
|
13
|
+
Project Ansible is distributed in the hope that it will be useful,
|
14
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
GNU Lesser General Public License for more details.
|
17
|
+
|
18
|
+
You should have received a copy of the GNU Lesser General Public License
|
19
|
+
along with Project Ansible. If not, see <http://www.gnu.org/licenses/>.
|
20
|
+
|
21
|
+
for more information on the LGPL, see:
|
22
|
+
http://en.wikipedia.org/wiki/GNU_Lesser_General_Public_License
|
23
|
+
=end
|
24
|
+
|
25
|
+
module Ansible
|
26
|
+
|
27
|
+
# root class describing an Ansible Device, i.e. a device controlled
|
28
|
+
# at least by one automation protocol supported by Ansible
|
29
|
+
#
|
30
|
+
# ===Arguments:
|
31
|
+
# [hashmap]
|
32
|
+
# hash consisting of Symbol => AnsibleValue pairs e.g.
|
33
|
+
# {
|
34
|
+
# :onoff => KNXValue.new("1.001", "1/0/20")
|
35
|
+
# }
|
36
|
+
#
|
37
|
+
# ===Example:
|
38
|
+
# obj.fire_callback(:onChange, 'GROUPADDR', :arg1, :arg2, :arg3)
|
39
|
+
#
|
40
|
+
class Device
|
41
|
+
|
42
|
+
# initialize an Ansible Device
|
43
|
+
def initialize(hashmap)
|
44
|
+
# sanity check: check argument validity
|
45
|
+
args_valid = true
|
46
|
+
if hashmap.is_a?Hash then
|
47
|
+
hashmap.each { |k,v|
|
48
|
+
args_valid = args_valid and (k.is_a?Symbol) and (v.is_a?AnsibleValue)
|
49
|
+
}
|
50
|
+
else
|
51
|
+
args_valid = false
|
52
|
+
end
|
53
|
+
raise "#{self.class}.new requires a hash map of Symbol => AnsibleValue!!!" unless args_valid
|
54
|
+
#
|
55
|
+
# store hashmap
|
56
|
+
@hashmap = hashmap
|
57
|
+
# link values
|
58
|
+
link()
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
#
|
65
|
+
# load all known Ansible Device classes
|
66
|
+
Dir["devices/*.rb"].each { |f| load f }
|
67
|
+
|
68
|
+
end
|
@@ -0,0 +1,179 @@
|
|
1
|
+
=begin
|
2
|
+
Project Ansible - An extensible home automation scripting framework
|
3
|
+
----------------------------------------------------
|
4
|
+
Copyright (c) 2011 Elias Karakoulakis <elias.karakoulakis@gmail.com>
|
5
|
+
|
6
|
+
SOFTWARE NOTICE AND LICENSE
|
7
|
+
|
8
|
+
Project Ansible is free software: you can redistribute it and/or modify
|
9
|
+
it under the terms of the GNU Lesser General Public License as published
|
10
|
+
by the Free Software Foundation, either version 3 of the License,
|
11
|
+
or (at your option) any later version.
|
12
|
+
|
13
|
+
Project Ansible is distributed in the hope that it will be useful,
|
14
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
GNU Lesser General Public License for more details.
|
17
|
+
|
18
|
+
You should have received a copy of the GNU Lesser General Public License
|
19
|
+
along with Project Ansible. If not, see <http://www.gnu.org/licenses/>.
|
20
|
+
|
21
|
+
for more information on the LGPL, see:
|
22
|
+
http://en.wikipedia.org/wiki/GNU_Lesser_General_Public_License
|
23
|
+
=end
|
24
|
+
|
25
|
+
require 'ansible_callback'
|
26
|
+
|
27
|
+
module Ansible
|
28
|
+
|
29
|
+
# A base module for Ansible Values, which is the most basic form to declare a
|
30
|
+
# protocol-agnostic control endpoint, be it an input (a button or event), or
|
31
|
+
# an output (a device such as a relay or dimmer)
|
32
|
+
module AnsibleValue
|
33
|
+
|
34
|
+
include AnsibleCallback
|
35
|
+
|
36
|
+
attr_reader :previous_value, :current_value
|
37
|
+
attr_reader :last_update
|
38
|
+
attr_reader :flags
|
39
|
+
|
40
|
+
# return true if a value's instance variable (whose symbol is iv_symbol) matches a filter value (as a regexp)
|
41
|
+
# e.g. value.matches?(:name => /elias/, :telephone => /210/)
|
42
|
+
def matches?(hash)
|
43
|
+
raise "#{self.class}: AnsibleValue.match? single argument must be a hash.." unless hash.is_a?Hash
|
44
|
+
result = true
|
45
|
+
hash.each { |iv_symbol, filter|
|
46
|
+
raise "#{self.class}: AnsibleValue.match?(hash)'s keys must be Symbols.." unless iv_symbol.is_a?Symbol
|
47
|
+
if respond_to?(iv_symbol) and (val = instance_eval(iv_symbol.to_s)) then
|
48
|
+
#puts "match.val(#{iv_symbol}) == #{val.inspect}" if $DEBUG
|
49
|
+
result = result & case filter
|
50
|
+
# if the filter is a regular expression, use it to match the instance value
|
51
|
+
when Regexp then filter.match(val.to_s)
|
52
|
+
# if the filter is an array, use set intersection
|
53
|
+
when Array then (filter & val).length > 0
|
54
|
+
else filter == val
|
55
|
+
end
|
56
|
+
else
|
57
|
+
return false
|
58
|
+
end
|
59
|
+
}
|
60
|
+
return(result)
|
61
|
+
end
|
62
|
+
|
63
|
+
# singleton array of all known Values
|
64
|
+
@@AllValues = []
|
65
|
+
@@AllValuesMutex = Mutex.new
|
66
|
+
|
67
|
+
# lookup an AnsibleValue by a filter hash
|
68
|
+
# returns an array of matching values
|
69
|
+
def AnsibleValue.[](filter_hash)
|
70
|
+
result_set = []
|
71
|
+
@@AllValuesMutex.synchronize {
|
72
|
+
puts "AnsibleValue[] called, filter_hash=#{filter_hash}" if $DEBUG
|
73
|
+
@@AllValues.each { |v|
|
74
|
+
raise "ooops! @@AllValues contains a non-AnsibleValue!" unless v.is_a?(AnsibleValue)
|
75
|
+
if v.matches?(filter_hash) then
|
76
|
+
puts "Found a matching value! #{v}" if $DEBUG
|
77
|
+
result_set << v
|
78
|
+
end
|
79
|
+
}
|
80
|
+
puts "AnsibleValue[] returns=#{result_set}" if $DEBUG
|
81
|
+
}
|
82
|
+
return result_set
|
83
|
+
end
|
84
|
+
|
85
|
+
#
|
86
|
+
# add an AnsibleValue to the singleton @@AllValues
|
87
|
+
# returns the newvalue, or the existing value (using equality test ==), if found
|
88
|
+
def AnsibleValue.insert(newvalue)
|
89
|
+
result = nil
|
90
|
+
@@AllValuesMutex.synchronize {
|
91
|
+
# check if newvalue is already stored in @@AllValues, find it and return it
|
92
|
+
if (result = @@AllValues.find{|val| newvalue == val}).nil? then
|
93
|
+
puts "Adding a new value to @@AllValues (#{newvalue})" if $DEBUG
|
94
|
+
@@AllValues << (result = newvalue)
|
95
|
+
# get initial state
|
96
|
+
newvalue.get
|
97
|
+
end
|
98
|
+
}
|
99
|
+
return(result)
|
100
|
+
end
|
101
|
+
|
102
|
+
#
|
103
|
+
# get a value's current state
|
104
|
+
# returns: the value, if found in eibd's cache or nil otherwise
|
105
|
+
def get
|
106
|
+
return if write_only?
|
107
|
+
#
|
108
|
+
puts "get() called for #{self.inspect} by:\n\t" + caller[1] if $DEBUG
|
109
|
+
#
|
110
|
+
fire_callback(:onBeforeGet)
|
111
|
+
if read_value() then
|
112
|
+
fire_callback(:onAfterGetSuccess)
|
113
|
+
else
|
114
|
+
fire_callback(:onAfterGetFail)
|
115
|
+
#raise "get value failed for #{self}"
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
#
|
120
|
+
# set a value
|
121
|
+
# new_val: the new value, must be ruby-castable to OpenZWave's type system
|
122
|
+
# returns: true on success, raises exception on error
|
123
|
+
#WARNING: a true return value doesn't mean the command actually succeeded,
|
124
|
+
# it only means that it was queued for delivery to the target node
|
125
|
+
def set(new_val)
|
126
|
+
return if read_only?
|
127
|
+
#
|
128
|
+
puts "set() called for #{self.inspect} by:\n\t" + caller[1] if $DEBUG
|
129
|
+
#
|
130
|
+
fire_callback(:onBeforeSet)
|
131
|
+
if write_value(new_val) then
|
132
|
+
fire_callback(:onSetSuccess)
|
133
|
+
else
|
134
|
+
fire_callback(:onSetFail)
|
135
|
+
raise "set value #{self}: call to #{write_operation} failed!!"
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
#
|
140
|
+
# update internal instance variable representing the current state of the value
|
141
|
+
# called by read_value() and write_value()
|
142
|
+
def update(newval)
|
143
|
+
validate_ranges() if respond_to?(:validate_ranges)
|
144
|
+
unless newval == @current_value then
|
145
|
+
@last_update = Time.now
|
146
|
+
puts "+++ updating value #{self}, with #{newval.class}:#{newval.inspect}"
|
147
|
+
|
148
|
+
# previous value was different, update it and fire onUpdate handler
|
149
|
+
@previous_value = @current_value if defined?(@current_value)
|
150
|
+
@current_value = newval
|
151
|
+
# trigger onUpdate callback, if any
|
152
|
+
fire_callback(:onUpdate, nil, newval)
|
153
|
+
end
|
154
|
+
return(@current_value)
|
155
|
+
end
|
156
|
+
|
157
|
+
# GENERICS
|
158
|
+
# --------
|
159
|
+
|
160
|
+
# write value to the protocol
|
161
|
+
def write_value()
|
162
|
+
raise "#{self.class}.write_value() must be overriden!!!"
|
163
|
+
end
|
164
|
+
|
165
|
+
# value convertion from protocol-specific to its canonical form
|
166
|
+
# must be overriden by protocol value subclass
|
167
|
+
def as_canonical_value()
|
168
|
+
raise "#{self.class}.as_canonical_value() must be overriden!!!"
|
169
|
+
end
|
170
|
+
|
171
|
+
# convert a canonical value back to its protocol-specific form
|
172
|
+
# must be overriden by protocol value subclass
|
173
|
+
def to_protocol_value(v)
|
174
|
+
raise "#{self.class}.to_protocol_value() must be overriden!!!"
|
175
|
+
end
|
176
|
+
|
177
|
+
end
|
178
|
+
|
179
|
+
end #module
|
@@ -0,0 +1,92 @@
|
|
1
|
+
=begin
|
2
|
+
Project Ansible - An extensible home automation scripting framework
|
3
|
+
----------------------------------------------------
|
4
|
+
Copyright (c) 2011 Elias Karakoulakis <elias.karakoulakis@gmail.com>
|
5
|
+
|
6
|
+
SOFTWARE NOTICE AND LICENSE
|
7
|
+
|
8
|
+
Project Ansible is free software: you can redistribute it and/or modify
|
9
|
+
it under the terms of the GNU Lesser General Public License as published
|
10
|
+
by the Free Software Foundation, either version 3 of the License,
|
11
|
+
or (at your option) any later version.
|
12
|
+
|
13
|
+
Project Ansible is distributed in the hope that it will be useful,
|
14
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
GNU Lesser General Public License for more details.
|
17
|
+
|
18
|
+
You should have received a copy of the GNU Lesser General Public License
|
19
|
+
along with Project Ansible. If not, see <http://www.gnu.org/licenses/>.
|
20
|
+
|
21
|
+
for more information on the LGPL, see:
|
22
|
+
http://en.wikipedia.org/wiki/GNU_Lesser_General_Public_License
|
23
|
+
=end
|
24
|
+
|
25
|
+
#
|
26
|
+
# global configuration options file
|
27
|
+
#
|
28
|
+
|
29
|
+
module Ansible
|
30
|
+
|
31
|
+
# STOMP Server URL
|
32
|
+
STOMP_URL = 'stomp://192.168.10.14'
|
33
|
+
|
34
|
+
#
|
35
|
+
# KNX subsystem configuration
|
36
|
+
#
|
37
|
+
module KNX
|
38
|
+
|
39
|
+
# KNX eibd server URL (not the actual KNX interface URL!)
|
40
|
+
KNX_URL = "local:/tmp/eib"
|
41
|
+
#KNX_URL = "ip:localhost"
|
42
|
+
|
43
|
+
###################
|
44
|
+
# KNX MONITOR TOPIC:
|
45
|
+
# passes all KNX activity to STOMP
|
46
|
+
# KNX frame headers as defined in knx_protocol.rb
|
47
|
+
KNX_MONITOR_TOPIC = "/queue/knx/monitor"
|
48
|
+
|
49
|
+
#################
|
50
|
+
# KNX COMMAND_TOPIC
|
51
|
+
# header "dest_addr" => KNX destination address (group/phys) in 16-bit unsigned integer format i.e. "1024" meaning "1/0/0" in 3-level fmt
|
52
|
+
# body => the raw APDU for transmission (command flags+data) in Marshal.dump(CGI.escape()) format
|
53
|
+
KNX_COMMAND_TOPIC = "/queue/knx/command"
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
#
|
58
|
+
# ZWave sybsustem configuration
|
59
|
+
#
|
60
|
+
module ZWave
|
61
|
+
|
62
|
+
###################
|
63
|
+
#ZWAVE MONITOR TOPIC:
|
64
|
+
# passes all ZWave activity to STOMP
|
65
|
+
# ZWave frame headers as defined in zwave-protocol.rb
|
66
|
+
ZWAVE_MONITOR_TOPIC = "/queue/zwave/monitor"
|
67
|
+
|
68
|
+
#################
|
69
|
+
# ZWAVE_COMMAND_TOPIC
|
70
|
+
# header =>
|
71
|
+
# body =>
|
72
|
+
#ZWAVE_COMMAND_TOPIC = "/queue/knx/command"
|
73
|
+
|
74
|
+
#################
|
75
|
+
# OpenZWave Thrift Server URL
|
76
|
+
THRIFT_URL = 'thrift://192.168.10.14'
|
77
|
+
#THRIFT_URL = 'thrift://192.168.0.100'
|
78
|
+
|
79
|
+
ThriftPort = 9090
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
#
|
86
|
+
|
87
|
+
module OpenZWave
|
88
|
+
|
89
|
+
# path to OpenZWave source
|
90
|
+
OZW_SRC = "lib/ansible/openzwave/src"
|
91
|
+
|
92
|
+
end
|