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,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
|
+
$LOAD_PATH.push File.join(File.dirname(__FILE__),"trigger_switch_d")
|
19
|
+
require "config"
|
20
|
+
require "daylight"
|
21
|
+
require "action"
|
22
|
+
require "schedule"
|
23
|
+
require "switch"
|
24
|
+
require "trigger_switch_d_helper"
|
25
|
+
require "ipc"
|
26
|
+
require "application"
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
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 << File.join(File.dirname(__FILE__),".." ,"lib" )
|
19
|
+
require 'spec'
|
20
|
+
require 'tellstick'
|
21
|
+
require 'trigger_switch_d'
|
22
|
+
TriggerSwitchD::ConfigFactory.new
|
@@ -0,0 +1,57 @@
|
|
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__),"..","..","spec_helper")
|
19
|
+
|
20
|
+
# "S$k$k $kk$ $k+"
|
21
|
+
# "S$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$kk$$kk$$kk$$}+"
|
22
|
+
# "S$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$kk$$kk$$k$k$}+"
|
23
|
+
# "S$kk$$k$k$k$k$k$k$kk$$k$k$k$k$k$k$k$k$kk$$kk$$kk$$}+"
|
24
|
+
# "S$kk$$k$k$k$k$k$k$kk$$k$k$k$k$k$k$k$k$kk$$kk$$k$k$}+"
|
25
|
+
|
26
|
+
module Tellstick
|
27
|
+
describe Tellstick do
|
28
|
+
context "switch uses nexa code switch protocol" do
|
29
|
+
before(:each) do
|
30
|
+
@messages = StringIO.new
|
31
|
+
end
|
32
|
+
it "should turn on switch with house and unit code" do
|
33
|
+
::Tellstick.create(@messages,"nexa").turn_on("A",1)
|
34
|
+
@messages.string.split("\n").should include("S$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$kk$$kk$$kk$$}+")
|
35
|
+
end
|
36
|
+
it "should turn off switch with house and unit code" do
|
37
|
+
::Tellstick.create(@messages,"nexa").turn_off("A",1)
|
38
|
+
@messages.string.split("\n").should include("S$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$kk$$kk$$k$k$}+")
|
39
|
+
end
|
40
|
+
it "should turn on switch with house and unit code" do
|
41
|
+
::Tellstick.create(@messages,"nexa").turn_on("B",2)
|
42
|
+
@messages.string.split("\n").should include("S$kk$$k$k$k$k$k$k$kk$$k$k$k$k$k$k$k$k$kk$$kk$$kk$$}+")
|
43
|
+
end
|
44
|
+
it "should turn off switch with house and unit code" do
|
45
|
+
::Tellstick.create(@messages,"nexa").turn_off("B",2)
|
46
|
+
@messages.string.split("\n").should include("S$kk$$k$k$k$k$k$k$kk$$k$k$k$k$k$k$k$k$kk$$kk$$k$k$}+")
|
47
|
+
end
|
48
|
+
describe "house code is a number instead of letter" do
|
49
|
+
it "should turn on switch with house and unit code" do
|
50
|
+
::Tellstick.create(@messages,"nexa").turn_on("2",2)
|
51
|
+
@messages.string.split("\n").should include("S$kk$$k$k$k$k$k$k$kk$$k$k$k$k$k$k$k$k$kk$$kk$$kk$$}+")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,61 @@
|
|
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__),"..","..","spec_helper")
|
19
|
+
|
20
|
+
module Tellstick
|
21
|
+
describe Tellstick do
|
22
|
+
context "switch uses proove protocol" do
|
23
|
+
before(:each) do
|
24
|
+
@messages = StringIO.new
|
25
|
+
end
|
26
|
+
it "should turn on switch with house and unit code" do
|
27
|
+
::Tellstick.create(@messages,"proove").turn_on("A",1)
|
28
|
+
@messages.string.split("\n").should include("R\005T\177\377\030\001\204\232\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\210\252\212\212\212\212+")
|
29
|
+
end
|
30
|
+
it "should turn off switch with house and unit code" do
|
31
|
+
::Tellstick.create(@messages,"proove").turn_off("A",1)
|
32
|
+
@messages.string.split("\n").should include("R\005T\177\377\030\001\204\232\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212+")
|
33
|
+
end
|
34
|
+
it "should turn on switch with house and unit code" do
|
35
|
+
::Tellstick.create(@messages,"proove").turn_on("B",2)
|
36
|
+
@messages.string.split("\n").should include("R\005T\177\377\030\001\204\232\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\210\252\210\252\212\212\210\252+")
|
37
|
+
end
|
38
|
+
it "should turn off switch with house and unit code" do
|
39
|
+
::Tellstick.create(@messages,"proove").turn_off("B",2)
|
40
|
+
@messages.string.split("\n").should include("R\005T\177\377\030\001\204\232\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\210\252\212\212\212\212\210\252+")
|
41
|
+
end
|
42
|
+
it "should teach switch with house and unit code" do
|
43
|
+
::Tellstick.create(@messages,"proove").teach("A",1)
|
44
|
+
@messages.string.split("\n").length.should == 5
|
45
|
+
@messages.string.split("\n").should include("R\002T\177\377\030\001\204\232\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\210\252\212\212\212\212+")
|
46
|
+
end
|
47
|
+
it "should teach switch with house and unit code" do
|
48
|
+
::Tellstick.create(@messages,"proove").teach("B",2)
|
49
|
+
@messages.string.split("\n").length.should == 5
|
50
|
+
@messages.string.split("\n").should include("R\002T\177\377\030\001\204\232\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\210\252\210\252\212\212\210\252+")
|
51
|
+
end
|
52
|
+
describe "house code is a number instead of letter" do
|
53
|
+
it "should turn on switch with house and unit code" do
|
54
|
+
::Tellstick.create(@messages,"proove").turn_on("17",1)
|
55
|
+
@messages.string.split("\n").should include("R\005T\177\377\030\001\204\232\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\212\210\252\210\252\212\212\212\212+")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,56 @@
|
|
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__),"..","..","spec_helper")
|
19
|
+
|
20
|
+
# "S.e.e.ee..ee..ee..e.e.ee..ee..ee..ee..ee..ee..ee..e+"
|
21
|
+
# "S.ee..e.e.ee..ee..ee..e.e.ee..ee..ee..ee..ee..ee..e+"
|
22
|
+
# "S.e.e.ee..ee..ee..e.e.ee..ee..ee..ee..ee..ee..e.e.e+"
|
23
|
+
# "S.ee..e.e.ee..ee..ee..e.e.ee..ee..ee..ee..ee..e.e.e+"
|
24
|
+
|
25
|
+
module Tellstick
|
26
|
+
describe Tellstick do
|
27
|
+
context "switch uses rising sun protocol" do
|
28
|
+
before(:each) do
|
29
|
+
@messages = StringIO.new
|
30
|
+
end
|
31
|
+
it "should turn on switch with house and unit code" do
|
32
|
+
::Tellstick.create(@messages,"rising_sun").turn_on("A",1)
|
33
|
+
@messages.string.split("\n").should include("S.e.e.ee..ee..ee..e.e.ee..ee..ee..ee..ee..ee..ee..e+")
|
34
|
+
end
|
35
|
+
it "should turn off switch with house and unit code" do
|
36
|
+
::Tellstick.create(@messages,"rising_sun").turn_off("A",1)
|
37
|
+
@messages.string.split("\n").should include("S.e.e.ee..ee..ee..e.e.ee..ee..ee..ee..ee..ee..e.e.e+")
|
38
|
+
end
|
39
|
+
it "should turn on switch with house and unit code" do
|
40
|
+
::Tellstick.create(@messages,"rising_sun").turn_on("B",2)
|
41
|
+
@messages.string.split("\n").should include("S.ee..e.e.ee..ee..ee..e.e.ee..ee..ee..ee..ee..ee..e+")
|
42
|
+
end
|
43
|
+
it "should turn off switch with house and unit code" do
|
44
|
+
::Tellstick.create(@messages,"rising_sun").turn_off("B",2)
|
45
|
+
@messages.string.split("\n").should include("S.ee..e.e.ee..ee..ee..e.e.ee..ee..ee..ee..ee..e.e.e+")
|
46
|
+
end
|
47
|
+
describe "house code is a number instead of letter" do
|
48
|
+
it "should turn on switch with house and unit code" do
|
49
|
+
::Tellstick.create(@messages,"rising_sun").turn_on("2",2)
|
50
|
+
@messages.string.split("\n").should include("S.ee..e.e.ee..ee..ee..e.e.ee..ee..ee..ee..ee..ee..e+")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,57 @@
|
|
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__),"..","..","spec_helper")
|
19
|
+
|
20
|
+
# "S$k$k $kk$ $k+"
|
21
|
+
# "S$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$kk$$kk$$kk$$}+"
|
22
|
+
# "S$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$}+"
|
23
|
+
# "S$kk$$k$k$k$k$k$k$kk$$k$k$k$k$k$k$k$k$kk$$kk$$kk$$}+"
|
24
|
+
# "S$kk$$k$k$k$k$k$k$kk$$k$k$k$k$k$k$k$k$k$k$k$k$k$k$}+"
|
25
|
+
|
26
|
+
module Tellstick
|
27
|
+
describe Tellstick do
|
28
|
+
context "switch uses waveman code switch protocol" do
|
29
|
+
before(:each) do
|
30
|
+
@messages = StringIO.new
|
31
|
+
end
|
32
|
+
it "should turn on switch with house and unit code" do
|
33
|
+
::Tellstick.create(@messages,"waveman").turn_on("A",1)
|
34
|
+
@messages.string.split("\n").should include("S$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$kk$$kk$$kk$$}+")
|
35
|
+
end
|
36
|
+
it "should turn off switch with house and unit code" do
|
37
|
+
::Tellstick.create(@messages,"waveman").turn_off("A",1)
|
38
|
+
@messages.string.split("\n").should include("S$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$k$}+")
|
39
|
+
end
|
40
|
+
it "should turn on switch with house and unit code" do
|
41
|
+
::Tellstick.create(@messages,"waveman").turn_on("B",2)
|
42
|
+
@messages.string.split("\n").should include("S$kk$$k$k$k$k$k$k$kk$$k$k$k$k$k$k$k$k$kk$$kk$$kk$$}+")
|
43
|
+
end
|
44
|
+
it "should turn off switch with house and unit code" do
|
45
|
+
::Tellstick.create(@messages,"waveman").turn_off("B",2)
|
46
|
+
@messages.string.split("\n").should include("S$kk$$k$k$k$k$k$k$kk$$k$k$k$k$k$k$k$k$k$k$k$k$k$k$}+")
|
47
|
+
end
|
48
|
+
describe "house code is a number instead of letter" do
|
49
|
+
it "should turn on switch with house and unit code" do
|
50
|
+
::Tellstick.create(@messages,"waveman").turn_on("2",2)
|
51
|
+
@messages.string.split("\n").should include("S$kk$$k$k$k$k$k$k$kk$$k$k$k$k$k$k$k$k$kk$$kk$$kk$$}+")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,31 @@
|
|
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__),"..","spec_helper")
|
19
|
+
|
20
|
+
module Tellstick
|
21
|
+
describe TellstickIO do
|
22
|
+
it "writes commands to usb dongle" do
|
23
|
+
dongle = TellstickIO.new
|
24
|
+
dongle.puts("S+")
|
25
|
+
dongle.gets.should include("+S")
|
26
|
+
dongle.puts("T+")
|
27
|
+
dongle.gets.should include("+T")
|
28
|
+
dongle.close
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,86 @@
|
|
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__),"..","spec_helper")
|
19
|
+
|
20
|
+
module Tellstick
|
21
|
+
describe Tellstick do
|
22
|
+
before(:each) do
|
23
|
+
@messages = StringIO.new
|
24
|
+
end
|
25
|
+
it "should create a tellstick" do
|
26
|
+
@messages.stub("connected?").and_return(true)
|
27
|
+
@messages.should_receive("connected?").and_return(true)
|
28
|
+
::Tellstick.create(@messages).should_not == nil
|
29
|
+
end
|
30
|
+
context "usb dongle is connected" do
|
31
|
+
before(:each) do
|
32
|
+
@messages.stub("connected?").and_return(true)
|
33
|
+
end
|
34
|
+
it "should know if usb dongle is connected" do
|
35
|
+
@messages.connected?.should == true
|
36
|
+
end
|
37
|
+
it "should turn on switch with house and unit code" do
|
38
|
+
@messages.should_receive("connected?").and_return(true)
|
39
|
+
::Tellstick.create(@messages).turn_on("A",1)
|
40
|
+
@messages.string.split("\n").should include("Strömbrytare A1 tänd")
|
41
|
+
end
|
42
|
+
it "should turn off switch with house and unit code" do
|
43
|
+
@messages.should_receive("connected?").and_return(true)
|
44
|
+
::Tellstick.create(@messages).turn_off("D",3)
|
45
|
+
@messages.string.split("\n").should include("Strömbrytare D3 släckt")
|
46
|
+
end
|
47
|
+
describe "house code is a number instead of letter" do
|
48
|
+
it "should turn on switch with house and unit code" do
|
49
|
+
@messages.should_receive("connected?").and_return(true)
|
50
|
+
::Tellstick.create(@messages).turn_on(3,5)
|
51
|
+
@messages.string.split("\n").should include("Strömbrytare 35 tänd")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context "usb dongle is not connected" do
|
57
|
+
before(:each) do
|
58
|
+
@messages.stub("connected?").and_return(false)
|
59
|
+
end
|
60
|
+
it "should know if usb dongle is connected" do
|
61
|
+
@messages.connected?.should == false
|
62
|
+
end
|
63
|
+
it "should tell us to connect usb dongle" do
|
64
|
+
@messages.should_receive("connected?").and_return(false)
|
65
|
+
::Tellstick.create(@messages).turn_off("D",3)
|
66
|
+
@messages.string.should include("Koppla in usb stickan först")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context "output does not have connected? method" do
|
71
|
+
it "assumes output is connected" do
|
72
|
+
output = StringIO.new
|
73
|
+
::Tellstick.create(output).turn_off("D",3)
|
74
|
+
output.string.split("\n").should include("Strömbrytare D3 släckt")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context "protocol name does not exist" do
|
79
|
+
it "assumes protocol is NullProtocol" do
|
80
|
+
output = StringIO.new
|
81
|
+
::Tellstick.create(output,"undefined_protocol").turn_off("D",3)
|
82
|
+
output.string.split("\n").should include("Protokollet finns inte")
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,144 @@
|
|
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__),"..","spec_helper")
|
19
|
+
require File.join(File.dirname(__FILE__),'trigger_switch_d_spec_helpers')
|
20
|
+
|
21
|
+
module TriggerSwitchD
|
22
|
+
|
23
|
+
describe "Application" do
|
24
|
+
before(:each) do
|
25
|
+
@file = StringIO.new
|
26
|
+
@file.puts <<-EOS
|
27
|
+
Config.geo_position = {:north => 54.57525, :west => -12.94125}
|
28
|
+
Config.log_path = "log"
|
29
|
+
Config.db_path = "db"
|
30
|
+
Config.dsl_path = "config"
|
31
|
+
#Config.log_object = :file
|
32
|
+
Config.log_object = :spec
|
33
|
+
Config.output = :spec
|
34
|
+
Config.unix_socket_path = "/tmp"
|
35
|
+
EOS
|
36
|
+
@file.seek(0)
|
37
|
+
com_thread = mock("com_thread")
|
38
|
+
com_thread.stub!(:[]).with("received").and_return("a","stop")
|
39
|
+
IPC.stub!(:create).with(an_instance_of(String)).and_return(com_thread)
|
40
|
+
@date = Date.new(2009,12,14)
|
41
|
+
@environment = Config.default_environment
|
42
|
+
SwitchFactory.new(["house_code", "unit_code", "model_name"])
|
43
|
+
@devices = {"sovrum" => [Switch.new(:house_code => "B", :unit_code => "4", :model_name => "plain_text")],
|
44
|
+
"källare" => [Switch.new(:house_code => "D", :unit_code => "3", :model_name => "plain_text")]}
|
45
|
+
@schedule = Schedule.create
|
46
|
+
@empty_schedule = Schedule.create
|
47
|
+
@schedule.schedule_action(Action.new("tänd källare klockan 14:00",@devices,@environment,@date))
|
48
|
+
TriggerSwitchD::Schedule.stub!(:create).with(no_args).and_return(@schedule)
|
49
|
+
com_thread.stub!(:[]=)
|
50
|
+
TriggerSwitchD::stub!(:load_devices).and_return(@devices)
|
51
|
+
TriggerSwitchD::stub!(:load_scheduled_actions)
|
52
|
+
Kernel.stub!(:sleep)
|
53
|
+
@app = Application.new(@file)
|
54
|
+
db_file = StringIO.new
|
55
|
+
db_file.stub!(:close)
|
56
|
+
File.stub!(:open).with(a_kind_of(String),"r").and_return(db_file)
|
57
|
+
end
|
58
|
+
|
59
|
+
context "when starting" do
|
60
|
+
it "should load the environment" do
|
61
|
+
Application.new(@file)
|
62
|
+
Config.log_object.string.should include("Environment prepared")
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should start the IPC server thread" do
|
66
|
+
com_thread = IPC.create("")
|
67
|
+
IPC.should_receive(:create).with(an_instance_of(String)).and_return(com_thread)
|
68
|
+
@app.start
|
69
|
+
Config.log_object.string.should include("IPC started")
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should load schedule and devices" do
|
73
|
+
TriggerSwitchD::should_receive(:load_devices).with(duck_type(:readlines)).and_return(@devices)
|
74
|
+
TriggerSwitchD::should_receive(:load_scheduled_actions).with(duck_type(:readlines),duck_type(:by_name,:cronological),@devices,anything)
|
75
|
+
Config.log_object.should_receive(:flush).once
|
76
|
+
@app.start
|
77
|
+
TriggerSwitchD::verify_log_includes(/Loaded (\d) devices and \d actions/u,1,["2"])
|
78
|
+
TriggerSwitchD::verify_log_includes(/Loaded \d devices and (\d) actions/u,1,["1"])
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should handle empty string as command" do
|
82
|
+
com_thread = IPC.create("")
|
83
|
+
com_thread.stub!(:[]).and_return("","stop")
|
84
|
+
com_thread.stub!(:[]=).with("anything").and_return(com_thread["received"])
|
85
|
+
Proc.new { @app.start }.should_not raise_error
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context "while running" do
|
90
|
+
before(:each) do
|
91
|
+
@com_thread = IPC.create("")
|
92
|
+
@com_thread.stub!(:run).with(no_args)
|
93
|
+
end
|
94
|
+
it "should stop on command from client" do
|
95
|
+
@com_thread.stub!(:[]).and_return("anything","stop")
|
96
|
+
@app.start
|
97
|
+
Config.log_object.string.scan(/Received stop via IPC/).length.should == 1
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should return a device list on command from client" do
|
101
|
+
@com_thread.stub!(:[]).with("received").and_return("anything","anything","list_devices","stop")
|
102
|
+
@com_thread.should_receive(:[]=).with("response",@devices.to_yaml)
|
103
|
+
@com_thread.should_receive(:[]=).twice.with("received","anything")
|
104
|
+
@com_thread.should_receive(:run).with(no_args)
|
105
|
+
Config.log_object.should_receive(:flush).twice
|
106
|
+
@app.start
|
107
|
+
TriggerSwitchD::verify_log_includes(/Received (\w+) via IPC/u,2,["list_devices","stop"])
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should return a schedule on command from client" do
|
111
|
+
@com_thread.stub!(:[]).with("received").and_return("list_schedule","stop")
|
112
|
+
@com_thread.should_receive(:[]=).with("response",@schedule.by_name.keys.to_yaml)
|
113
|
+
@app.start
|
114
|
+
TriggerSwitchD::verify_log_includes(/Received (\w+) via IPC/u,2,["list_schedule","stop"])
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should execute schedule" do
|
118
|
+
@schedule.schedule_action(Action.new("tänd sovrum klockan 07:00",@devices,@environment,@date))
|
119
|
+
@com_thread.stub!(:[]).with("received").and_return("a","b","c","stop")
|
120
|
+
Time.stub!(:new).and_return(Time.parse("2009.12.14 07:00:00"),Time.parse("2009.12.14 14:00:00"))
|
121
|
+
Config.log_object.should_receive(:flush).exactly(3).times
|
122
|
+
Kernel.should_receive(:sleep).twice
|
123
|
+
@app.start
|
124
|
+
@schedule.cronological.length.should == 0
|
125
|
+
TriggerSwitchD::verify_log_includes(/Executed \d+ action\(s\) at (\d\d:\d\d)/u,2,["07:00","14:00"])
|
126
|
+
TriggerSwitchD::verify_log_includes(/Executed (\d+) action\(s\) at \d\d:\d\d/u,2,["1"])
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should reload db just after midnight localtime" do
|
130
|
+
TriggerSwitchD::Schedule.stub!(:create).with(no_args).and_return(@empty_schedule,@schedule)
|
131
|
+
@com_thread.stub!(:[]).with("received").and_return("a","b","c","stop")
|
132
|
+
Time.stub!(:new).and_return(Time.parse("2009.12.14 07:00:00"),Time.parse("2009.12.15 00:00:01"))
|
133
|
+
@app.start
|
134
|
+
TriggerSwitchD::verify_log_includes(/Loaded (\d) devices and \d actions/u,2,["2"])
|
135
|
+
TriggerSwitchD::verify_log_includes(/Loaded \d devices and (\d) actions/u,2,["0","1"])
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should ignore empty string from IPC" do
|
139
|
+
@com_thread.stub!(:[]).with("received").and_return("anything","","anything","stop")
|
140
|
+
Proc.new {@app.start}.should_not raise_error
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
@@ -0,0 +1,94 @@
|
|
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__),"..","spec_helper")
|
19
|
+
|
20
|
+
module TriggerSwitchD
|
21
|
+
describe "Config" do
|
22
|
+
before(:each) do
|
23
|
+
file = StringIO.new
|
24
|
+
file.puts <<-EOS
|
25
|
+
Config.geo_position = {:north => 54.57525, :west => -12.94125}
|
26
|
+
Config.log_path = "log"
|
27
|
+
Config.db_path = "db"
|
28
|
+
Config.dsl_path = "config"
|
29
|
+
Config.unix_socket_path = "/tmp"
|
30
|
+
Config.log_object = :spec
|
31
|
+
Config.output = :spec
|
32
|
+
EOS
|
33
|
+
file.seek(0)
|
34
|
+
ConfigFactory.new(file)
|
35
|
+
end
|
36
|
+
it "should respond to geo_position" do
|
37
|
+
Config.geo_position.should == {:north => 54.57525, :west => -12.94125}
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should respond to log_path" do
|
41
|
+
Config.log_path.should == "log/tsd.log"
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should respond to db_path" do
|
45
|
+
Config.db_path.should == ["db/devices","db/scheduled_actions"]
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should respond to dsl_path" do
|
49
|
+
Config.dsl_path.should == "config/lookup.dsl"
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should respond to unix_socket_path" do
|
53
|
+
Config.unix_socket_path.should == "/tmp/com.adhocskill.trigger_switch_d"
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should respond to log_object" do
|
57
|
+
Config.log_object.should be_kind_of(StringIO)
|
58
|
+
Config.log_object = :file
|
59
|
+
Config.log_object.should be_kind_of(File)
|
60
|
+
Config.log_object.path.should == Config.log_path
|
61
|
+
Config.log_object = :development
|
62
|
+
Config.log_object.should be_kind_of(IO)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should respond to output" do
|
66
|
+
Config.output.should be_kind_of(StringIO)
|
67
|
+
Config.output = :development
|
68
|
+
Config.output.should be_kind_of(IO)
|
69
|
+
Config.output = :tellstick
|
70
|
+
Config.output.should be_kind_of(Tellstick::TellstickIO)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should respond to environment" do
|
74
|
+
file = StringIO.new
|
75
|
+
file.puts <<-EOS
|
76
|
+
---
|
77
|
+
släck: deactivate
|
78
|
+
klockan: at
|
79
|
+
solnedgång: sunset
|
80
|
+
vid: at
|
81
|
+
soluppgång: sunrise
|
82
|
+
tänd: activate
|
83
|
+
|
84
|
+
EOS
|
85
|
+
file.seek(0)
|
86
|
+
File.stub!(:open).with(Config.dsl_path,"r").and_return(file)
|
87
|
+
Config.environment.should == {:lookup => {"tänd" => "activate", "släck" => "deactivate",
|
88
|
+
"soluppgång" => "sunrise", "solnedgång" => "sunset",
|
89
|
+
"klockan" => "at", "vid" => "at"},
|
90
|
+
:at_location => {:north => 54.57525, :west => -12.94125}}
|
91
|
+
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|