trigger_switch_d 0.1.0
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/COPYING.txt +674 -0
- data/LICENSE.txt +54 -0
- data/README.rdoc +106 -0
- data/bin/teach +44 -0
- data/bin/tsd +68 -0
- data/bin/turn_off +42 -0
- data/bin/turn_on +39 -0
- data/doc/classes/Tellstick/Tellstick.html +117 -0
- data/doc/classes/Tellstick/TellstickIO.html +265 -0
- data/doc/classes/Tellstick/TellstickIO.src/M000020.html +18 -0
- data/doc/classes/Tellstick/TellstickIO.src/M000021.html +20 -0
- data/doc/classes/Tellstick/TellstickIO.src/M000022.html +26 -0
- data/doc/classes/Tellstick/TellstickIO.src/M000023.html +19 -0
- data/doc/classes/Tellstick/TellstickIO.src/M000024.html +26 -0
- data/doc/classes/Tellstick/TellstickIO.src/M000025.html +16 -0
- data/doc/classes/Tellstick/TellstickIO.src/M000026.html +16 -0
- data/doc/classes/Tellstick/TellstickIO.src/M000027.html +24 -0
- data/doc/classes/Tellstick.html +204 -0
- data/doc/classes/Tellstick.src/M000019.html +25 -0
- data/doc/classes/TriggerSwitchD/Action.html +165 -0
- data/doc/classes/TriggerSwitchD/Action.src/M000015.html +28 -0
- data/doc/classes/TriggerSwitchD/Action.src/M000016.html +18 -0
- data/doc/classes/TriggerSwitchD/Application.html +203 -0
- data/doc/classes/TriggerSwitchD/Application.src/M000017.html +21 -0
- data/doc/classes/TriggerSwitchD/Application.src/M000018.html +40 -0
- data/doc/classes/TriggerSwitchD/ConfigFactory/Config.html +127 -0
- data/doc/classes/TriggerSwitchD/ConfigFactory/Config.src/M000014.html +23 -0
- data/doc/classes/TriggerSwitchD/ConfigFactory.html +141 -0
- data/doc/classes/TriggerSwitchD/ConfigFactory.src/M000013.html +24 -0
- data/doc/classes/TriggerSwitchD/IPC.html +134 -0
- data/doc/classes/TriggerSwitchD/IPC.src/M000012.html +32 -0
- data/doc/classes/TriggerSwitchD/Schedule/InstanceMethods.html +242 -0
- data/doc/classes/TriggerSwitchD/Schedule/InstanceMethods.src/M000005.html +19 -0
- data/doc/classes/TriggerSwitchD/Schedule/InstanceMethods.src/M000006.html +18 -0
- data/doc/classes/TriggerSwitchD/Schedule/InstanceMethods.src/M000007.html +23 -0
- data/doc/classes/TriggerSwitchD/Schedule/InstanceMethods.src/M000008.html +19 -0
- data/doc/classes/TriggerSwitchD/Schedule/InstanceMethods.src/M000009.html +19 -0
- data/doc/classes/TriggerSwitchD/Schedule/InstanceMethods.src/M000010.html +18 -0
- data/doc/classes/TriggerSwitchD/Schedule/InstanceMethods.src/M000011.html +18 -0
- data/doc/classes/TriggerSwitchD/Schedule.html +147 -0
- data/doc/classes/TriggerSwitchD/Schedule.src/M000004.html +19 -0
- data/doc/classes/TriggerSwitchD/SwitchFactory.html +135 -0
- data/doc/classes/TriggerSwitchD/SwitchFactory.src/M000003.html +20 -0
- data/doc/classes/TriggerSwitchD.html +212 -0
- data/doc/classes/TriggerSwitchD.src/M000001.html +22 -0
- data/doc/classes/TriggerSwitchD.src/M000002.html +27 -0
- data/doc/created.rid +1 -0
- data/doc/files/lib/tellstick/protocol/nexa_rb.html +126 -0
- data/doc/files/lib/tellstick/protocol/not_connected_rb.html +126 -0
- data/doc/files/lib/tellstick/protocol/null_protocol_rb.html +126 -0
- data/doc/files/lib/tellstick/protocol/plain_text_rb.html +126 -0
- data/doc/files/lib/tellstick/protocol/proove_rb.html +126 -0
- data/doc/files/lib/tellstick/protocol/protocol_loader_rb.html +126 -0
- data/doc/files/lib/tellstick/protocol/rising_sun_rb.html +126 -0
- data/doc/files/lib/tellstick/protocol/waveman_rb.html +126 -0
- data/doc/files/lib/tellstick/tellstick_io_rb.html +135 -0
- data/doc/files/lib/tellstick/tellstick_rb.html +135 -0
- data/doc/files/lib/tellstick_rb.html +134 -0
- data/doc/files/lib/trigger_switch_d/action_rb.html +126 -0
- data/doc/files/lib/trigger_switch_d/application_rb.html +136 -0
- data/doc/files/lib/trigger_switch_d/config_rb.html +126 -0
- data/doc/files/lib/trigger_switch_d/daylight_rb.html +126 -0
- data/doc/files/lib/trigger_switch_d/ipc_rb.html +126 -0
- data/doc/files/lib/trigger_switch_d/schedule_rb.html +126 -0
- data/doc/files/lib/trigger_switch_d/switch_rb.html +126 -0
- data/doc/files/lib/trigger_switch_d/trigger_switch_d_helper_rb.html +126 -0
- data/doc/files/lib/trigger_switch_d_rb.html +140 -0
- data/doc/fr_class_index.html +38 -0
- data/doc/fr_file_index.html +46 -0
- data/doc/fr_method_index.html +53 -0
- data/doc/index.html +24 -0
- data/features/execute_schedule.feature +20 -0
- data/features/group_aliases.feature +31 -0
- data/features/handle_switches.feature +36 -0
- data/features/listen_for_client_call.feature +23 -0
- data/features/persistent_schedule.feature +70 -0
- data/features/proove_protocol.feature +20 -0
- data/features/schedule.feature +25 -0
- data/features/simple_string_protocol.feature +35 -0
- data/features/step_definitions/execute_schedule_steps.rb +16 -0
- data/features/step_definitions/group_aliases_steps.rb +24 -0
- data/features/step_definitions/handle_switches_steps.rb +21 -0
- data/features/step_definitions/listen_for_client_call_steps.rb +34 -0
- data/features/step_definitions/persistent_schedule_steps.rb +18 -0
- data/features/step_definitions/proove_protocol_steps.rb +3 -0
- data/features/step_definitions/schedule_steps.rb +9 -0
- data/features/step_definitions/shared_steps.rb +75 -0
- data/features/step_definitions/simple_string_protocol_steps.rb +3 -0
- data/features/step_definitions/sunrise_steps.rb +22 -0
- data/features/step_definitions/tellstick_connected_steps.rb +21 -0
- data/features/sunrise.feature +22 -0
- data/features/sunset.feature +22 -0
- data/features/support/action_helpers.rb +10 -0
- data/features/support/env.rb +7 -0
- data/features/support/listen_for_client_call_helper.rb +71 -0
- data/features/support/proove_helpers.rb +6 -0
- data/features/support/sunrise_helper.rb +8 -0
- data/features/tellstick_connected.feature +14 -0
- data/lib/tellstick/protocol/nexa.rb +48 -0
- data/lib/tellstick/protocol/not_connected.rb +42 -0
- data/lib/tellstick/protocol/null_protocol.rb +41 -0
- data/lib/tellstick/protocol/plain_text.rb +35 -0
- data/lib/tellstick/protocol/proove.rb +83 -0
- data/lib/tellstick/protocol/protocol_loader.rb +26 -0
- data/lib/tellstick/protocol/rising_sun.rb +42 -0
- data/lib/tellstick/protocol/waveman.rb +29 -0
- data/lib/tellstick/tellstick.rb +73 -0
- data/lib/tellstick/tellstick_io.rb +80 -0
- data/lib/tellstick.rb +20 -0
- data/lib/trigger_switch_d/action.rb +83 -0
- data/lib/trigger_switch_d/application.rb +89 -0
- data/lib/trigger_switch_d/config.rb +83 -0
- data/lib/trigger_switch_d/daylight.rb +114 -0
- data/lib/trigger_switch_d/ipc.rb +39 -0
- data/lib/trigger_switch_d/schedule.rb +95 -0
- data/lib/trigger_switch_d/switch.rb +37 -0
- data/lib/trigger_switch_d/trigger_switch_d_helper.rb +44 -0
- data/lib/trigger_switch_d.rb +26 -0
- data/spec/spec_helper.rb +22 -0
- data/spec/tellstick/protocol/nexa_spec.rb +57 -0
- data/spec/tellstick/protocol/proove_spec.rb +61 -0
- data/spec/tellstick/protocol/rising_sun_spec.rb +56 -0
- data/spec/tellstick/protocol/waveman_spec.rb +57 -0
- data/spec/tellstick/tellstick_io_spec.rb +31 -0
- data/spec/tellstick/tellstick_spec.rb +86 -0
- data/spec/trigger_switch_d/application_spec.rb +144 -0
- data/spec/trigger_switch_d/config_spec.rb +94 -0
- data/spec/trigger_switch_d/daylight_spec.rb +39 -0
- data/spec/trigger_switch_d/ipc_spec.rb +119 -0
- data/spec/trigger_switch_d/schedule_spec.rb +103 -0
- data/spec/trigger_switch_d/trigger_switch_d_spec_helpers.rb +24 -0
- data/trigger_switch_d.gemspec +43 -0
- metadata +206 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
Givet /^att usb stickan inte är inkopplad$/ do
|
2
|
+
message = StringIO.new
|
3
|
+
def message.connected?; false;end
|
4
|
+
message.connected?.should == false
|
5
|
+
end
|
6
|
+
|
7
|
+
Givet /^jag har skapat en tellstick$/ do
|
8
|
+
message = StringIO.new
|
9
|
+
def message.connected?; false;end
|
10
|
+
Tellstick::create(message)
|
11
|
+
end
|
12
|
+
|
13
|
+
När /^jag (.+) en strömbrytare (.+) (.+)$/ do |kommando,hus,enhet|
|
14
|
+
@message = StringIO.new
|
15
|
+
def @message.connected?; false;end
|
16
|
+
dongle(@message).send(actions[kommando[0..-3]],hus,enhet)
|
17
|
+
end
|
18
|
+
|
19
|
+
Så /^skall jag se meddelandet "([^\"]*)"$/ do |meddelande|
|
20
|
+
@message.string.gsub("\n","").should include(meddelande)
|
21
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#language: se
|
2
|
+
Egenskap: Sunrise
|
3
|
+
För att kunna, var jag än är, ställa min väckarklocka att ringa precis innan solen går upp
|
4
|
+
Som en solbeivrare
|
5
|
+
Vill jag kunna räkna ut tiden för soluppgång
|
6
|
+
|
7
|
+
@implemented
|
8
|
+
Abstrakt Scenario: soluppgång på den plats jag är
|
9
|
+
Givet att aktuellt datum är "<datum>"
|
10
|
+
Och att jag är på latitud "<latitude>"
|
11
|
+
Och att jag är på longitud "<longitude>"
|
12
|
+
När jag beräknar soluppgång
|
13
|
+
Så skall se "<soluppgång>"
|
14
|
+
|
15
|
+
Exempel:
|
16
|
+
| datum | latitude | longitude | soluppgång |
|
17
|
+
| 20100505 | 55:36.6N | 12:59.7Ö | 05:18 |
|
18
|
+
| 20100830 | 57:42.6N | 11:58.08Ö | 06:09 |
|
19
|
+
| 20091214 | 60:40.68N | 17:8.52Ö | 08:55 |
|
20
|
+
|
21
|
+
|
22
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#language: se
|
2
|
+
Egenskap: Sunset
|
3
|
+
För att kunna, var jag än är, tända ytterbelysningen precis innan solen går ned
|
4
|
+
Som en kvälls människa
|
5
|
+
Vill jag kunna räkna ut tiden för solnedgång
|
6
|
+
|
7
|
+
@implemented
|
8
|
+
Abstrakt Scenario: solnedgång på den plats jag är
|
9
|
+
Givet att aktuellt datum är "<datum>"
|
10
|
+
Och att jag är på latitud "<latitude>"
|
11
|
+
Och att jag är på longitud "<longitude>"
|
12
|
+
När jag beräknar solnedgång
|
13
|
+
Så skall se "<solnedgång>"
|
14
|
+
|
15
|
+
Exempel:
|
16
|
+
| datum | latitude | longitude | solnedgång |
|
17
|
+
| 20100505 | 55:36.6N | 12:59.7Ö | 20:53 |
|
18
|
+
| 20100830 | 57:42.6N | 11:58.08Ö | 20:19 |
|
19
|
+
| 20091214 | 60:40.68N | 17:8.52Ö | 14:39 |
|
20
|
+
|
21
|
+
|
22
|
+
|
@@ -0,0 +1,7 @@
|
|
1
|
+
$LOAD_PATH << File.join(File.dirname(__FILE__),".." ,".." ,"lib" )
|
2
|
+
require 'cucumber/formatter/unicode'
|
3
|
+
require 'tellstick'
|
4
|
+
require 'trigger_switch_d'
|
5
|
+
require 'socket'
|
6
|
+
TriggerSwitchD::ConfigFactory.new
|
7
|
+
TriggerSwitchD::SwitchFactory.new(["house_code","unit_code","model_name"])
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module ListenForClientCallHelper
|
2
|
+
def devices_filename
|
3
|
+
"db/devices"
|
4
|
+
end
|
5
|
+
|
6
|
+
def schedule_filename
|
7
|
+
"db/scheduled_actions"
|
8
|
+
end
|
9
|
+
|
10
|
+
def config_filename
|
11
|
+
"config/config.rb"
|
12
|
+
end
|
13
|
+
|
14
|
+
def prepare_devices(device_name,device1,device2)
|
15
|
+
__recreate_db_dir__
|
16
|
+
dev = []
|
17
|
+
dev = __load_existing_devices__ if File.exist? devices_filename
|
18
|
+
new_switches = [device1,device2].map do |device|
|
19
|
+
device.split(",").flatten
|
20
|
+
end.map do |device|
|
21
|
+
{"house_code" => device[0], "unit_code" => device[1], "model_name" => device[2]}
|
22
|
+
end
|
23
|
+
dev << {"name" => device_name, "switches" => new_switches}
|
24
|
+
file = File.open(devices_filename,"w+")
|
25
|
+
YAML::dump(dev,file)
|
26
|
+
file.close
|
27
|
+
end
|
28
|
+
|
29
|
+
def prepare_config
|
30
|
+
file = File.open(config_filename,"w+")
|
31
|
+
file.puts <<-EOS
|
32
|
+
Config.geo_position = {:north => 54.57525, :west => -12.94125}
|
33
|
+
Config.log_path = "log"
|
34
|
+
Config.db_path = "db"
|
35
|
+
Config.dsl_path = "config"
|
36
|
+
#Config.log_object = :file
|
37
|
+
Config.log_object = :spec
|
38
|
+
Config.output = :spec
|
39
|
+
Config.unix_socket_path = "/tmp"
|
40
|
+
EOS
|
41
|
+
file.close
|
42
|
+
end
|
43
|
+
|
44
|
+
def prepare_schedule(action)
|
45
|
+
__recreate_db_dir__
|
46
|
+
actions = ["#{action}\n"]
|
47
|
+
file = File.open(schedule_filename,"a+")
|
48
|
+
file.write(actions)
|
49
|
+
file.close
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def __recreate_db_dir__
|
55
|
+
Dir.mkdir("db") unless File.directory? "db"
|
56
|
+
end
|
57
|
+
|
58
|
+
def __load_existing_devices__
|
59
|
+
file = File.open(devices_filename,"r")
|
60
|
+
devices = TriggerSwitchD::load_devices(file)
|
61
|
+
file.close
|
62
|
+
devices.map do |device|
|
63
|
+
switches = device[1].map do |switch|
|
64
|
+
{"house_code" => switch.house_code, "unit_code" => switch.unit_code, "model_name" => switch.model_name}
|
65
|
+
end
|
66
|
+
{"name" => device[0], "switches" => switches}
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
World(ListenForClientCallHelper)
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#language: se
|
2
|
+
Egenskap: Om tellstick är inkopplad eller inte
|
3
|
+
|
4
|
+
För att usb stickan skall kunna skicka signaler till strömbrytare
|
5
|
+
Som en användare av usb stickan
|
6
|
+
Vill jag veta om usb stickan är inkopplad eller inte
|
7
|
+
|
8
|
+
@implemented
|
9
|
+
Scenario: är tellstick inkopplad
|
10
|
+
Givet att usb stickan inte är inkopplad
|
11
|
+
Och jag har skapat en tellstick
|
12
|
+
När jag tänder en strömbrytare A 1
|
13
|
+
När jag släcker en strömbrytare B 7
|
14
|
+
Så skall jag se meddelandet "Koppla in usb stickan först"
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# TriggerSwitchD, executes commands to activate/deactive remote switches.
|
2
|
+
# (c) Copyright 2010 Pontus Strömdahl, AdhocSkill.
|
3
|
+
#
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
|
17
|
+
|
18
|
+
require File.join(File.dirname(__FILE__),"protocol_loader")
|
19
|
+
|
20
|
+
module Tellstick
|
21
|
+
module Nexa #:nodoc:
|
22
|
+
include ProtocolLoader
|
23
|
+
def turn_on(house,unit)
|
24
|
+
output.puts "S#{codify(house)}#{codify(unit.to_s)}$k$k$kk$$kk$$kk$$}+"
|
25
|
+
end
|
26
|
+
def turn_off(house,unit)
|
27
|
+
output.puts "S#{codify(house)}#{codify(unit.to_s)}$k$k$kk$$kk$$k$k$}+"
|
28
|
+
end
|
29
|
+
def teach(house,unit)
|
30
|
+
turn_on(house,unit)
|
31
|
+
end
|
32
|
+
def output
|
33
|
+
@output
|
34
|
+
end
|
35
|
+
private
|
36
|
+
def codify(code)
|
37
|
+
tmp_code = ((code =~ /[1234]/) == 0) ? code.to_i - 1: 0
|
38
|
+
tmp_code = code[0]-"A"[0] if ((code =~ /[A-D]/) == 0)
|
39
|
+
tmp_code = code[0]-"a"[0] if ((code =~ /[a-d]/) == 0)
|
40
|
+
result = ["$k$k", "$k$k", "$k$k", "$k$k"]
|
41
|
+
(0..result.length-1).each do |bit|
|
42
|
+
result[result.length-1-bit] = "$kk$" if (tmp_code & 1) == 1
|
43
|
+
tmp_code >>= 1
|
44
|
+
end
|
45
|
+
result.reverse
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# TriggerSwitchD, executes commands to activate/deactive remote switches.
|
2
|
+
# (c) Copyright 2010 Pontus Strömdahl, AdhocSkill.
|
3
|
+
#
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
|
17
|
+
|
18
|
+
module Tellstick
|
19
|
+
module NotConnected #:nodoc:
|
20
|
+
|
21
|
+
def turn_on(house,unit)
|
22
|
+
[output,STDOUT].each {|o| o.puts attention }
|
23
|
+
end
|
24
|
+
|
25
|
+
def turn_off(house,unit)
|
26
|
+
[output,STDOUT].each {|o| o.puts attention }
|
27
|
+
end
|
28
|
+
|
29
|
+
def teach(house,unit)
|
30
|
+
[output,STDOUT].each {|o| o.puts attention }
|
31
|
+
end
|
32
|
+
|
33
|
+
def output
|
34
|
+
@output
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
def attention
|
39
|
+
"Koppla in usb stickan först"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# TriggerSwitchD, executes commands to activate/deactive remote switches.
|
2
|
+
# (c) Copyright 2010 Pontus Strömdahl, AdhocSkill.
|
3
|
+
#
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
|
17
|
+
|
18
|
+
module Tellstick
|
19
|
+
module NullProtocol #:nodoc:
|
20
|
+
def turn_on(house,unit)
|
21
|
+
[output,STDOUT].each {|o| o.puts attention }
|
22
|
+
end
|
23
|
+
|
24
|
+
def turn_off(house,unit)
|
25
|
+
[output,STDOUT].each {|o| o.puts attention }
|
26
|
+
end
|
27
|
+
|
28
|
+
def teach(house,unit)
|
29
|
+
[output,STDOUT].each {|o| o.puts attention }
|
30
|
+
end
|
31
|
+
|
32
|
+
def output
|
33
|
+
@output
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
def attention
|
38
|
+
"Protokollet finns inte"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# TriggerSwitchD, executes commands to activate/deactive remote switches.
|
2
|
+
# (c) Copyright 2010 Pontus Strömdahl, AdhocSkill.
|
3
|
+
#
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
|
17
|
+
|
18
|
+
require File.join(File.dirname(__FILE__),"protocol_loader")
|
19
|
+
|
20
|
+
module Tellstick
|
21
|
+
module PlainText #:nodoc:
|
22
|
+
include ProtocolLoader
|
23
|
+
def turn_on(house,unit)
|
24
|
+
output.puts "Strömbrytare #{house}#{unit} tänd"
|
25
|
+
end
|
26
|
+
|
27
|
+
def turn_off(house,unit)
|
28
|
+
output.puts "Strömbrytare #{house}#{unit} släckt"
|
29
|
+
end
|
30
|
+
|
31
|
+
def output
|
32
|
+
@output
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# TriggerSwitchD, executes commands to activate/deactive remote switches.
|
2
|
+
# (c) Copyright 2010 Pontus Strömdahl, AdhocSkill.
|
3
|
+
#
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
|
17
|
+
|
18
|
+
require File.join(File.dirname(__FILE__),"protocol_loader")
|
19
|
+
|
20
|
+
module Tellstick
|
21
|
+
module Proove #:nodoc:
|
22
|
+
include ProtocolLoader
|
23
|
+
def turn_on(house,unit)
|
24
|
+
output.puts build_command_string(house,unit,true)
|
25
|
+
end
|
26
|
+
|
27
|
+
def turn_off(house,unit)
|
28
|
+
output.puts build_command_string(house,unit,false)
|
29
|
+
end
|
30
|
+
|
31
|
+
def teach(house,unit)
|
32
|
+
(1..5).each do |i|
|
33
|
+
output.puts build_command_string(house,unit,true,2)
|
34
|
+
output.gets
|
35
|
+
sleep 0.2
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def output
|
40
|
+
@output
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
def part_for(code,number_of_bits)
|
45
|
+
result = ""
|
46
|
+
(0..number_of_bits).each do |i|
|
47
|
+
result << (((code & 1) << (number_of_bits - i) == 1)? "10" : "01")
|
48
|
+
end
|
49
|
+
result
|
50
|
+
end
|
51
|
+
|
52
|
+
def translate(code_part)
|
53
|
+
result = ""
|
54
|
+
code = 9
|
55
|
+
code_part.scan(/./).each_with_index do |c,i|
|
56
|
+
code <<= 4
|
57
|
+
if c == "1"
|
58
|
+
code |= 8
|
59
|
+
else
|
60
|
+
code |= 10
|
61
|
+
end
|
62
|
+
if (i % 2 == 0)
|
63
|
+
result << code.chr
|
64
|
+
code = 0
|
65
|
+
end
|
66
|
+
end
|
67
|
+
result
|
68
|
+
end
|
69
|
+
|
70
|
+
def build_command_string(house,unit,on,number_repeat=5)
|
71
|
+
house_code = ((house =~ /\d+/) == 0) ? house.to_i : 0
|
72
|
+
house_code = house[0]-"A"[0] if ((house =~ /[A-Z]/) == 0)
|
73
|
+
house_code = house[0]-"a"[0] if ((house =~ /[a-z]/) == 0)
|
74
|
+
unit_code = unit.to_i - 1
|
75
|
+
|
76
|
+
on_off = on ? "10" : "01"
|
77
|
+
|
78
|
+
signal_part = "#{part_for(house_code,25)}01#{on_off}#{part_for(unit_code,3)}0"
|
79
|
+
|
80
|
+
"R#{number_repeat.chr}T\177\377\030\001\204#{translate(signal_part)}+"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# TriggerSwitchD, executes commands to activate/deactive remote switches.
|
2
|
+
# (c) Copyright 2010 Pontus Strömdahl, AdhocSkill.
|
3
|
+
#
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
|
17
|
+
|
18
|
+
module Tellstick
|
19
|
+
module ProtocolLoader #:nodoc:
|
20
|
+
def self.included(klass)
|
21
|
+
p = klass
|
22
|
+
key = p.name.gsub("Tellstick::","").split(/(?=[A-Z])/).map{|w| w.downcase}.join("_")
|
23
|
+
$protocol[key] = p
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# TriggerSwitchD, executes commands to activate/deactive remote switches.
|
2
|
+
# (c) Copyright 2010 Pontus Strömdahl, AdhocSkill.
|
3
|
+
#
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
|
17
|
+
|
18
|
+
require File.join(File.dirname(__FILE__),"protocol_loader")
|
19
|
+
|
20
|
+
module Tellstick
|
21
|
+
module RisingSun #:nodoc:
|
22
|
+
include ProtocolLoader
|
23
|
+
def turn_on(house,unit)
|
24
|
+
output.puts "S.e#{codify(house)}#{codify(unit.to_s)}e..ee..ee..ee..e+"
|
25
|
+
end
|
26
|
+
def turn_off(house,unit)
|
27
|
+
output.puts "S.e#{codify(house)}#{codify(unit.to_s)}e..ee..ee..e.e.e+"
|
28
|
+
end
|
29
|
+
def output
|
30
|
+
@output
|
31
|
+
end
|
32
|
+
private
|
33
|
+
def codify(code)
|
34
|
+
tmp_code = ((code =~ /[1234]/) == 0) ? code.to_i - 1: 0
|
35
|
+
tmp_code = code[0]-"A"[0] if ((code =~ /[A-D]/) == 0)
|
36
|
+
tmp_code = code[0]-"a"[0] if ((code =~ /[a-d]/) == 0)
|
37
|
+
result = ["e..e", "e..e", "e..e", "e..e"]
|
38
|
+
result[tmp_code] = ".e.e"
|
39
|
+
result
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# TriggerSwitchD, executes commands to activate/deactive remote switches.
|
2
|
+
# (c) Copyright 2010 Pontus Strömdahl, AdhocSkill.
|
3
|
+
#
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
|
17
|
+
|
18
|
+
require File.join(File.dirname(__FILE__),"protocol_loader")
|
19
|
+
require File.join(File.dirname(__FILE__),"nexa")
|
20
|
+
|
21
|
+
module Tellstick
|
22
|
+
module Waveman #:nodoc:
|
23
|
+
include Nexa
|
24
|
+
include ProtocolLoader
|
25
|
+
def turn_off(house,unit)
|
26
|
+
output.puts "S#{codify(house)}#{codify(unit.to_s)}$k$k$k$k$k$k$k$k$}+"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# TriggerSwitchD, executes commands to activate/deactive remote switches.
|
2
|
+
# (c) Copyright 2010 Pontus Strömdahl, AdhocSkill.
|
3
|
+
#
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
|
17
|
+
|
18
|
+
$LOAD_PATH.push File.join(File.dirname(__FILE__),"protocol")
|
19
|
+
require "null_protocol"
|
20
|
+
require "not_connected"
|
21
|
+
require "protocol_loader"
|
22
|
+
|
23
|
+
# The Tellstick module represents the virtual equivalent of the
|
24
|
+
# hardware usb dongle. Use #create with TellstickIO.new as the output
|
25
|
+
|
26
|
+
module Tellstick
|
27
|
+
|
28
|
+
#takes any kind of IO, but specifically TellstickIO, as output
|
29
|
+
#and the name of the transmission protocol. It returns an
|
30
|
+
#instance of Tellstick.
|
31
|
+
#
|
32
|
+
#The protocol is mixed into Tellstick with the methods:
|
33
|
+
#* turn_on
|
34
|
+
#* turn_off
|
35
|
+
#* teach <i>(if the protocol supports it)</i>
|
36
|
+
def create(output,protocol_name="plain_text")
|
37
|
+
protocol = load(protocol_name)
|
38
|
+
dongle = Tellstick.new(output)
|
39
|
+
if connection_not_needed_for(output) or output.connected?
|
40
|
+
dongle.extend protocol
|
41
|
+
else
|
42
|
+
dongle.extend NotConnected
|
43
|
+
end
|
44
|
+
dongle
|
45
|
+
end
|
46
|
+
module_function :create
|
47
|
+
|
48
|
+
# use create to instasiate
|
49
|
+
class Tellstick
|
50
|
+
def initialize(output) #:nodoc:
|
51
|
+
@output = output
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
def self.connection_not_needed_for(output)
|
57
|
+
not output.methods.include?("connected?")
|
58
|
+
end
|
59
|
+
def self.load(name)
|
60
|
+
$protocol ||= {}
|
61
|
+
protocol = $protocol[name]
|
62
|
+
if protocol == nil
|
63
|
+
filename = File.join(File.dirname(__FILE__),"protocol",name)
|
64
|
+
if File.exists?("#{filename}.rb")
|
65
|
+
require filename
|
66
|
+
protocol = $protocol[name]
|
67
|
+
else
|
68
|
+
protocol = NullProtocol
|
69
|
+
end
|
70
|
+
end
|
71
|
+
protocol
|
72
|
+
end
|
73
|
+
end
|