trigger_switch_d 0.1.1 → 0.1.2

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.
Files changed (137) hide show
  1. data/README.rdoc +74 -57
  2. data/bin/ts_setup +68 -0
  3. data/bin/{teach → ts_teach} +1 -1
  4. data/bin/{turn_off → ts_turn_off} +1 -1
  5. data/bin/{turn_on → ts_turn_on} +1 -1
  6. data/bin/tsd +1 -1
  7. data/config/environment.rb.sample +42 -0
  8. data/config/lookup.dsl +7 -0
  9. data/lib/tellstick/code_converter.rb +56 -0
  10. data/lib/tellstick/protocol/nexa.rb +25 -10
  11. data/lib/tellstick/protocol/not_connected.rb +6 -14
  12. data/lib/tellstick/protocol/null_protocol.rb +6 -14
  13. data/lib/tellstick/protocol/proove.rb +60 -35
  14. data/lib/tellstick/protocol/protocol_loader.rb +2 -3
  15. data/lib/tellstick/protocol/rising_sun.rb +8 -4
  16. data/lib/tellstick/proxy_io.rb +32 -14
  17. data/lib/tellstick/tellstick.rb +4 -12
  18. data/lib/trigger_switch_d/action.rb +54 -19
  19. data/lib/trigger_switch_d/application.rb +77 -34
  20. data/lib/trigger_switch_d/config.rb +85 -35
  21. data/lib/trigger_switch_d/daylight.rb +135 -52
  22. data/lib/trigger_switch_d/ipc.rb +44 -12
  23. data/lib/trigger_switch_d/schedule.rb +20 -13
  24. data/lib/trigger_switch_d/switch.rb +6 -0
  25. data/lib/trigger_switch_d/trigger_switch_d_helper.rb +14 -13
  26. data/samples/devices +14 -0
  27. data/samples/devices.rising_sun +6 -0
  28. data/samples/environment.rb +44 -0
  29. data/samples/lookup.dsl +7 -0
  30. data/samples/scheduled_actions +6 -0
  31. data/samples/scheduled_actions.rising_sun +4 -0
  32. metadata +41 -116
  33. data/doc/classes/Tellstick/Tellstick.html +0 -117
  34. data/doc/classes/Tellstick/TellstickIO.html +0 -265
  35. data/doc/classes/Tellstick/TellstickIO.src/M000020.html +0 -18
  36. data/doc/classes/Tellstick/TellstickIO.src/M000021.html +0 -20
  37. data/doc/classes/Tellstick/TellstickIO.src/M000022.html +0 -26
  38. data/doc/classes/Tellstick/TellstickIO.src/M000023.html +0 -19
  39. data/doc/classes/Tellstick/TellstickIO.src/M000024.html +0 -26
  40. data/doc/classes/Tellstick/TellstickIO.src/M000025.html +0 -16
  41. data/doc/classes/Tellstick/TellstickIO.src/M000026.html +0 -16
  42. data/doc/classes/Tellstick/TellstickIO.src/M000027.html +0 -24
  43. data/doc/classes/Tellstick.html +0 -204
  44. data/doc/classes/Tellstick.src/M000019.html +0 -25
  45. data/doc/classes/TriggerSwitchD/Action.html +0 -165
  46. data/doc/classes/TriggerSwitchD/Action.src/M000015.html +0 -28
  47. data/doc/classes/TriggerSwitchD/Action.src/M000016.html +0 -18
  48. data/doc/classes/TriggerSwitchD/Application.html +0 -203
  49. data/doc/classes/TriggerSwitchD/Application.src/M000017.html +0 -21
  50. data/doc/classes/TriggerSwitchD/Application.src/M000018.html +0 -40
  51. data/doc/classes/TriggerSwitchD/ConfigFactory/Config.html +0 -127
  52. data/doc/classes/TriggerSwitchD/ConfigFactory/Config.src/M000014.html +0 -23
  53. data/doc/classes/TriggerSwitchD/ConfigFactory.html +0 -141
  54. data/doc/classes/TriggerSwitchD/ConfigFactory.src/M000013.html +0 -24
  55. data/doc/classes/TriggerSwitchD/IPC.html +0 -134
  56. data/doc/classes/TriggerSwitchD/IPC.src/M000012.html +0 -32
  57. data/doc/classes/TriggerSwitchD/Schedule/InstanceMethods.html +0 -242
  58. data/doc/classes/TriggerSwitchD/Schedule/InstanceMethods.src/M000005.html +0 -19
  59. data/doc/classes/TriggerSwitchD/Schedule/InstanceMethods.src/M000006.html +0 -18
  60. data/doc/classes/TriggerSwitchD/Schedule/InstanceMethods.src/M000007.html +0 -23
  61. data/doc/classes/TriggerSwitchD/Schedule/InstanceMethods.src/M000008.html +0 -19
  62. data/doc/classes/TriggerSwitchD/Schedule/InstanceMethods.src/M000009.html +0 -19
  63. data/doc/classes/TriggerSwitchD/Schedule/InstanceMethods.src/M000010.html +0 -18
  64. data/doc/classes/TriggerSwitchD/Schedule/InstanceMethods.src/M000011.html +0 -18
  65. data/doc/classes/TriggerSwitchD/Schedule.html +0 -147
  66. data/doc/classes/TriggerSwitchD/Schedule.src/M000004.html +0 -19
  67. data/doc/classes/TriggerSwitchD/SwitchFactory.html +0 -135
  68. data/doc/classes/TriggerSwitchD/SwitchFactory.src/M000003.html +0 -20
  69. data/doc/classes/TriggerSwitchD.html +0 -212
  70. data/doc/classes/TriggerSwitchD.src/M000001.html +0 -22
  71. data/doc/classes/TriggerSwitchD.src/M000002.html +0 -27
  72. data/doc/created.rid +0 -1
  73. data/doc/files/lib/tellstick/protocol/nexa_rb.html +0 -126
  74. data/doc/files/lib/tellstick/protocol/not_connected_rb.html +0 -126
  75. data/doc/files/lib/tellstick/protocol/null_protocol_rb.html +0 -126
  76. data/doc/files/lib/tellstick/protocol/plain_text_rb.html +0 -126
  77. data/doc/files/lib/tellstick/protocol/proove_rb.html +0 -126
  78. data/doc/files/lib/tellstick/protocol/protocol_loader_rb.html +0 -126
  79. data/doc/files/lib/tellstick/protocol/rising_sun_rb.html +0 -126
  80. data/doc/files/lib/tellstick/protocol/waveman_rb.html +0 -126
  81. data/doc/files/lib/tellstick/tellstick_io_rb.html +0 -135
  82. data/doc/files/lib/tellstick/tellstick_rb.html +0 -135
  83. data/doc/files/lib/tellstick_rb.html +0 -134
  84. data/doc/files/lib/trigger_switch_d/action_rb.html +0 -126
  85. data/doc/files/lib/trigger_switch_d/application_rb.html +0 -136
  86. data/doc/files/lib/trigger_switch_d/config_rb.html +0 -126
  87. data/doc/files/lib/trigger_switch_d/daylight_rb.html +0 -126
  88. data/doc/files/lib/trigger_switch_d/ipc_rb.html +0 -126
  89. data/doc/files/lib/trigger_switch_d/schedule_rb.html +0 -126
  90. data/doc/files/lib/trigger_switch_d/switch_rb.html +0 -126
  91. data/doc/files/lib/trigger_switch_d/trigger_switch_d_helper_rb.html +0 -126
  92. data/doc/files/lib/trigger_switch_d_rb.html +0 -140
  93. data/doc/fr_class_index.html +0 -38
  94. data/doc/fr_file_index.html +0 -46
  95. data/doc/fr_method_index.html +0 -53
  96. data/doc/index.html +0 -24
  97. data/features/execute_schedule.feature +0 -20
  98. data/features/group_aliases.feature +0 -31
  99. data/features/handle_switches.feature +0 -36
  100. data/features/listen_for_client_call.feature +0 -23
  101. data/features/persistent_schedule.feature +0 -70
  102. data/features/proove_protocol.feature +0 -20
  103. data/features/schedule.feature +0 -25
  104. data/features/simple_string_protocol.feature +0 -35
  105. data/features/step_definitions/execute_schedule_steps.rb +0 -16
  106. data/features/step_definitions/group_aliases_steps.rb +0 -24
  107. data/features/step_definitions/handle_switches_steps.rb +0 -21
  108. data/features/step_definitions/listen_for_client_call_steps.rb +0 -34
  109. data/features/step_definitions/persistent_schedule_steps.rb +0 -18
  110. data/features/step_definitions/proove_protocol_steps.rb +0 -3
  111. data/features/step_definitions/schedule_steps.rb +0 -9
  112. data/features/step_definitions/shared_steps.rb +0 -75
  113. data/features/step_definitions/simple_string_protocol_steps.rb +0 -3
  114. data/features/step_definitions/sunrise_steps.rb +0 -22
  115. data/features/step_definitions/tellstick_connected_steps.rb +0 -21
  116. data/features/sunrise.feature +0 -22
  117. data/features/sunset.feature +0 -22
  118. data/features/support/action_helpers.rb +0 -10
  119. data/features/support/env.rb +0 -7
  120. data/features/support/listen_for_client_call_helper.rb +0 -71
  121. data/features/support/proove_helpers.rb +0 -6
  122. data/features/support/sunrise_helper.rb +0 -8
  123. data/features/tellstick_connected.feature +0 -14
  124. data/spec/spec_helper.rb +0 -22
  125. data/spec/tellstick/protocol/nexa_spec.rb +0 -57
  126. data/spec/tellstick/protocol/proove_spec.rb +0 -61
  127. data/spec/tellstick/protocol/rising_sun_spec.rb +0 -56
  128. data/spec/tellstick/protocol/waveman_spec.rb +0 -57
  129. data/spec/tellstick/proxy_io_spec.rb +0 -34
  130. data/spec/tellstick/tellstick_spec.rb +0 -86
  131. data/spec/trigger_switch_d/application_spec.rb +0 -147
  132. data/spec/trigger_switch_d/config_spec.rb +0 -154
  133. data/spec/trigger_switch_d/daylight_spec.rb +0 -39
  134. data/spec/trigger_switch_d/ipc_spec.rb +0 -119
  135. data/spec/trigger_switch_d/schedule_spec.rb +0 -103
  136. data/spec/trigger_switch_d/trigger_switch_d_spec_helpers.rb +0 -24
  137. data/trigger_switch_d.gemspec +0 -43
@@ -1,147 +0,0 @@
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
- mock_sp = StringIO.new
26
- SerialPort.stub!(:new).and_return(mock_sp)
27
- @file = StringIO.new
28
- @file.puts <<-EOS
29
- Config.geo_position = {:north => 54.57525, :west => -12.94125}
30
- Config.log_path = "log"
31
- Config.db_path = "db"
32
- Config.dsl_path = "config"
33
- Config.vcp_port = "/dev/tty.usbserial-xxxxxxxx"
34
- #Config.log_object = :file
35
- Config.log_object = :spec
36
- Config.output = :spec
37
- Config.unix_socket_path = "/tmp"
38
- EOS
39
- @file.seek(0)
40
- com_thread = mock("com_thread")
41
- com_thread.stub!(:[]).with("received").and_return("a","stop")
42
- IPC.stub!(:create).with(an_instance_of(String)).and_return(com_thread)
43
- @date = Date.new(2009,12,14)
44
- @environment = Config.default_environment
45
- SwitchFactory.new(["house_code", "unit_code", "model_name"])
46
- @devices = {"sovrum" => [Switch.new(:house_code => "B", :unit_code => "4", :model_name => "plain_text")],
47
- "källare" => [Switch.new(:house_code => "D", :unit_code => "3", :model_name => "plain_text")]}
48
- @schedule = Schedule.create
49
- @empty_schedule = Schedule.create
50
- @schedule.schedule_action(Action.new("tänd källare klockan 14:00",@devices,@environment,@date))
51
- TriggerSwitchD::Schedule.stub!(:create).with(no_args).and_return(@schedule)
52
- com_thread.stub!(:[]=)
53
- TriggerSwitchD::stub!(:load_devices).and_return(@devices)
54
- TriggerSwitchD::stub!(:load_scheduled_actions)
55
- Kernel.stub!(:sleep)
56
- @app = Application.new(@file)
57
- db_file = StringIO.new
58
- db_file.stub!(:close)
59
- File.stub!(:open).with(a_kind_of(String),"r").and_return(db_file)
60
- end
61
-
62
- context "when starting" do
63
- it "should load the environment" do
64
- Application.new(@file)
65
- Config.log_object.string.should include("Environment prepared")
66
- end
67
-
68
- it "should start the IPC server thread" do
69
- com_thread = IPC.create("")
70
- IPC.should_receive(:create).with(an_instance_of(String)).and_return(com_thread)
71
- @app.start
72
- Config.log_object.string.should include("IPC started")
73
- end
74
-
75
- it "should load schedule and devices" do
76
- TriggerSwitchD::should_receive(:load_devices).with(duck_type(:readlines)).and_return(@devices)
77
- TriggerSwitchD::should_receive(:load_scheduled_actions).with(duck_type(:readlines),duck_type(:by_name,:cronological),@devices,anything)
78
- Config.log_object.should_receive(:flush).once
79
- @app.start
80
- TriggerSwitchD::verify_log_includes(/Loaded (\d) devices and \d actions/u,1,["2"])
81
- TriggerSwitchD::verify_log_includes(/Loaded \d devices and (\d) actions/u,1,["1"])
82
- end
83
-
84
- it "should handle empty string as command" do
85
- com_thread = IPC.create("")
86
- com_thread.stub!(:[]).and_return("","stop")
87
- com_thread.stub!(:[]=).with("anything").and_return(com_thread["received"])
88
- Proc.new { @app.start }.should_not raise_error
89
- end
90
- end
91
-
92
- context "while running" do
93
- before(:each) do
94
- @com_thread = IPC.create("")
95
- @com_thread.stub!(:run).with(no_args)
96
- end
97
- it "should stop on command from client" do
98
- @com_thread.stub!(:[]).and_return("anything","stop")
99
- @app.start
100
- Config.log_object.string.scan(/Received stop via IPC/).length.should == 1
101
- end
102
-
103
- it "should return a device list on command from client" do
104
- @com_thread.stub!(:[]).with("received").and_return("anything","anything","list_devices","stop")
105
- @com_thread.should_receive(:[]=).with("response",@devices.to_yaml)
106
- @com_thread.should_receive(:[]=).twice.with("received","anything")
107
- @com_thread.should_receive(:run).with(no_args)
108
- Config.log_object.should_receive(:flush).twice
109
- @app.start
110
- TriggerSwitchD::verify_log_includes(/Received (\w+) via IPC/u,2,["list_devices","stop"])
111
- end
112
-
113
- it "should return a schedule on command from client" do
114
- @com_thread.stub!(:[]).with("received").and_return("list_schedule","stop")
115
- @com_thread.should_receive(:[]=).with("response",@schedule.by_name.keys.to_yaml)
116
- @app.start
117
- TriggerSwitchD::verify_log_includes(/Received (\w+) via IPC/u,2,["list_schedule","stop"])
118
- end
119
-
120
- it "should execute schedule" do
121
- @schedule.schedule_action(Action.new("tänd sovrum klockan 07:00",@devices,@environment,@date))
122
- @com_thread.stub!(:[]).with("received").and_return("a","b","c","stop")
123
- Time.stub!(:new).and_return(Time.parse("2009.12.14 07:00:00"),Time.parse("2009.12.14 14:00:00"))
124
- Config.log_object.should_receive(:flush).exactly(3).times
125
- Kernel.should_receive(:sleep).twice
126
- @app.start
127
- @schedule.cronological.length.should == 0
128
- TriggerSwitchD::verify_log_includes(/Executed \d+ action\(s\) at (\d\d:\d\d)/u,2,["07:00","14:00"])
129
- TriggerSwitchD::verify_log_includes(/Executed (\d+) action\(s\) at \d\d:\d\d/u,2,["1"])
130
- end
131
-
132
- it "should reload db just after midnight localtime" do
133
- TriggerSwitchD::Schedule.stub!(:create).with(no_args).and_return(@empty_schedule,@schedule)
134
- @com_thread.stub!(:[]).with("received").and_return("a","b","c","stop")
135
- Time.stub!(:new).and_return(Time.parse("2009.12.14 07:00:00"),Time.parse("2009.12.15 00:00:01"))
136
- @app.start
137
- TriggerSwitchD::verify_log_includes(/Loaded (\d) devices and \d actions/u,2,["2"])
138
- TriggerSwitchD::verify_log_includes(/Loaded \d devices and (\d) actions/u,2,["0","1"])
139
- end
140
-
141
- it "should ignore empty string from IPC" do
142
- @com_thread.stub!(:[]).with("received").and_return("anything","","anything","stop")
143
- Proc.new {@app.start}.should_not raise_error
144
- end
145
- end
146
- end
147
- end
@@ -1,154 +0,0 @@
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
- @sio = mock("SerialPort")
24
- @sio.stub!(:open)
25
- @sio.stub!(:puts)
26
- @sio.stub!(:gets)
27
- SerialPort.stub!(:new).and_return(@sio)
28
- file = StringIO.new
29
- file.puts <<-EOS
30
- Config.geo_position = {:north => 54.57525, :west => -12.94125}
31
- Config.log_path = "log"
32
- Config.db_path = "db"
33
- Config.dsl_path = "config"
34
- Config.vcp_port = "/dev/tty.usbserial-xxxxxxxx"
35
- Config.unix_socket_path = "/tmp"
36
- Config.log_object = :spec
37
- Config.output = :spec
38
- EOS
39
- file.seek(0)
40
- ConfigFactory.new(file)
41
- end
42
- it "should respond to geo_position" do
43
- Config.geo_position.should == {:north => 54.57525, :west => -12.94125}
44
- end
45
-
46
- it "should respond to log_path" do
47
- Config.log_path.should == "log/tsd.log"
48
- end
49
-
50
- it "should respond to db_path" do
51
- Config.db_path.should == ["db/devices","db/scheduled_actions"]
52
- end
53
-
54
- it "should respond to dsl_path" do
55
- Config.dsl_path.should == "config/lookup.dsl"
56
- end
57
-
58
- it "should respond to unix_socket_path" do
59
- Config.unix_socket_path.should == "/tmp/com.adhocskill.trigger_switch_d"
60
- end
61
-
62
- it "should respond to log_object" do
63
- Config.log_object.should be_kind_of(StringIO)
64
- Config.log_object = :file
65
- Config.log_object.should be_kind_of(File)
66
- Config.log_object.path.should == Config.log_path
67
- Config.log_object = :development
68
- Config.log_object.should be_kind_of(IO)
69
- end
70
-
71
- it "should respond to output" do
72
- Config.output.should be_kind_of(StringIO)
73
- Config.output = :development
74
- Config.output.should be_kind_of(IO)
75
- Config.output = :tellstick
76
- Config.output.should == STDOUT
77
- SerialPort.should_receive(:new).and_return(@sio)
78
- Config.output = :vcp
79
- Config.output.should be_kind_of(Tellstick::ProxyIO)
80
- end
81
-
82
- it "should respond to environment" do
83
- file = StringIO.new
84
- file.puts <<-EOS
85
- ---
86
- släck: deactivate
87
- klockan: at
88
- solnedgång: sunset
89
- vid: at
90
- soluppgång: sunrise
91
- tänd: activate
92
-
93
- EOS
94
- file.seek(0)
95
- File.stub!(:open).with(Config.dsl_path,"r").and_return(file)
96
- Config.environment.should == {:lookup => {"tänd" => "activate", "släck" => "deactivate",
97
- "soluppgång" => "sunrise", "solnedgång" => "sunset",
98
- "klockan" => "at", "vid" => "at"},
99
- :at_location => {:north => 54.57525, :west => -12.94125}}
100
-
101
- end
102
-
103
- it "should handle empty line in config file" do
104
- file = StringIO.new
105
- file.puts <<-EOS
106
- # TriggerSwitchD, executes commands to activate/deactive remote switches.
107
- # (c) Copyright 2010 Pontus Strömdahl, AdhocSkill.
108
- #
109
- # This program is free software: you can redistribute it and/or modify
110
- # it under the terms of the GNU General Public License as published by
111
- # the Free Software Foundation, either version 3 of the License, or
112
- # (at your option) any later version.
113
- #
114
- # This program is distributed in the hope that it will be useful,
115
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
116
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
117
- # GNU General Public License for more details.
118
- #
119
- # You should have received a copy of the GNU General Public License
120
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
121
-
122
-
123
- #longitude and latitude for Malmö, Sweden. decimal form
124
- Config.geo_position = {:north => 54.57525, :west => -12.94125}
125
-
126
- #Paths: base for files tsd.log, devices, scheduled_actions and lookup.dsl (leave alone if uncertain)
127
- Config.log_path = "log"
128
- Config.db_path = "db"
129
- Config.dsl_path = "config"
130
-
131
- #Log: can be one of :file, :development or :spec (:spec is for the rspecs, ie don't use)
132
- # when log_object is set to :file, the log is written to tsd.log (log_path + /tsd.log)
133
- # when log_object is set to :development the log is written to STDOUT, useful for debugging
134
- # Config.log_object = :file
135
- Config.log_object = :development
136
- # Config.log_object = :spec
137
-
138
- #Output: can be one of :development, :tellstick or :spec (:spec is for the rspecs, ie don't use)
139
- # when output is set to :development output is written to STDOUT, useful for debugging
140
- # when output is set to :tellstick output is sent to the usb port that has a tellstick
141
- # (see www.teldus.se for more information)
142
- # Config.output = :tellstick
143
- Config.output = :development
144
- # Config.output = :spec
145
-
146
- #Unix socket: (leave alone if uncertain)
147
- Config.unix_socket_path = "/tmp"
148
-
149
- EOS
150
- file.seek(0)
151
- Proc.new { ConfigFactory.new(file) }.should_not raise_error
152
- end
153
- end
154
- end
@@ -1,39 +0,0 @@
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
- describe Daylight do
21
- before(:each) do
22
- year = 2009
23
- month = 12
24
- day = 14
25
- @date = Date.new(year,month,day)
26
- latitude = 60.678
27
- longitude = 17.142
28
- @at_location = {:north => latitude, :west => -longitude}
29
- end
30
- it "calculates the sunrise for a location and date" do
31
- time = @date.extend(Daylight).sunrise(@at_location).localtime
32
- "#{0 if time.hour < 10}#{time.hour}:#{0 if time.min < 10}#{time.min}".should == "08:55"
33
- end
34
-
35
- it "calculates the sunset for a location and date" do
36
- time = @date.extend(Daylight).sunset(@at_location).localtime
37
- "#{0 if time.hour < 10}#{time.hour}:#{0 if time.min < 10}#{time.min}".should == "14:39"
38
- end
39
- end
@@ -1,119 +0,0 @@
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
- require File.join(File.dirname(__FILE__),"..","spec_helper")
18
-
19
- module TriggerSwitchD
20
-
21
- describe "IPC" do
22
- before(:each) do
23
- mock_listen_sock = mock("UNIXSocket")
24
- mock_sock = mock("UNIXSocket")
25
- mock_listen_sock.stub!(:recvfrom).with(anything).and_return(["", ["AF_UNIX", ""]])
26
- mock_sock.stub!(:accept).and_return(mock_listen_sock)
27
- UNIXServer.stub!(:open).with(a_kind_of(String)).and_return(mock_sock)
28
- end
29
-
30
- it "should respond to []" do
31
- IPC.create("some_path")["received"].should == ""
32
- end
33
-
34
- it "should respond to []=" do
35
- ipc = IPC.create("some_path")
36
- ipc["response"] = "..."
37
- ipc["response"].should == "..."
38
- end
39
-
40
- it "should receive a message" do
41
- message = "a message"
42
- mock_listen_sock = mock("UNIXSocket")
43
- mock_sock = mock("UNIXSocket")
44
- mock_listen_sock.stub!(:recvfrom).with(anything).and_return([message, ["AF_UNIX", ""]])
45
- mock_sock.stub!(:accept).and_return(mock_listen_sock)
46
- UNIXServer.stub!(:open).with(a_kind_of(String)).and_return(mock_sock)
47
-
48
- ipc = IPC.create("some_path")
49
- ipc["received"].should == message
50
- end
51
-
52
- it "should send a message" do
53
- message = "a message"
54
- mock_accepted_sock = mock("UNIXSocket")
55
- mock_accepted_sock.stub!(:recvfrom).with(anything).and_return([message, ["AF_UNIX", ""]])
56
- mock_accepted_sock.stub!(:send).with(a_kind_of(String),0)
57
-
58
- mock_sock = mock("UNIXSocket")
59
- mock_sock.stub!(:accept).and_return(mock_accepted_sock)
60
- UNIXServer.stub!(:open).with(a_kind_of(String)).and_return(mock_sock)
61
- mock_accepted_sock.should_receive(:send).with(message,0)
62
-
63
- ipc = IPC.create("some_path")
64
- ipc["response"] = message
65
- ipc.run
66
- end
67
-
68
- it "should continually respond to received messages" do
69
- messages = {"devices" => "first", "schedule" => "second"}
70
- mock_accepted_sock = mock("UNIXSocket")
71
- mock_accepted_sock.stub!(:recvfrom).with(anything).and_return(["devices", ["AF_UNIX", ""]],
72
- ["schedule", ["AF_UNIX", ""]],
73
- ["stop", ["AF_UNIX", ""]])
74
-
75
- mock_sock = mock("UNIXSocket")
76
- mock_sock.stub!(:accept).and_return(mock_accepted_sock)
77
- UNIXServer.stub!(:open).with(a_kind_of(String)).and_return(mock_sock)
78
- mock_accepted_sock.should_receive(:send).with(messages["devices"],0).ordered
79
- mock_accepted_sock.should_receive(:send).with(messages["schedule"],0).ordered
80
-
81
- ipc = IPC.create("some_path")
82
- ipc["response"] = messages[ipc["received"]]
83
- ipc.run
84
- ipc["response"] = messages[ipc["received"]]
85
- ipc.run
86
- end
87
-
88
- context "client is about to disconnect" do
89
- it "should respond to bye" do
90
- message = "bye"
91
- mock_accepted_sock = mock("UNIXSocket")
92
- mock_accepted_sock.stub!(:recvfrom).with(anything).and_return([message, ["AF_UNIX", ""]])
93
- mock_accepted_sock.stub!(:send).with(a_kind_of(String),0)
94
-
95
- mock_sock = mock("UNIXSocket")
96
- mock_sock.stub!(:accept).and_return(mock_accepted_sock)
97
- UNIXServer.stub!(:open).with(a_kind_of(String)).and_return(mock_sock)
98
- mock_accepted_sock.should_receive(:send).with(message,0)
99
- mock_sock.should_receive(:accept).twice
100
-
101
- ipc = IPC.create("some_path")
102
- end
103
- it "should respond to empty string" do
104
- message = ""
105
- mock_accepted_sock = mock("UNIXSocket")
106
- mock_accepted_sock.stub!(:recvfrom).with(anything).and_return([message, ["AF_UNIX", ""]])
107
- mock_accepted_sock.stub!(:send).with(a_kind_of(String),0)
108
-
109
- mock_sock = mock("UNIXSocket")
110
- mock_sock.stub!(:accept).and_return(mock_accepted_sock)
111
- UNIXServer.stub!(:open).with(a_kind_of(String)).and_return(mock_sock)
112
- mock_accepted_sock.should_not_receive(:send).with(message,0)
113
- mock_sock.should_receive(:accept).twice
114
-
115
- ipc = IPC.create("some_path")
116
- end
117
- end
118
- end
119
- end
@@ -1,103 +0,0 @@
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
- require File.join(File.dirname(__FILE__),"..","spec_helper")
18
-
19
- module TriggerSwitchD
20
-
21
- describe "Schedule" do
22
- before(:each) do
23
- year = 2009
24
- month = 12
25
- day = 14
26
- @date = Date.new(year,month,day)
27
- latitude = 60.678
28
- longitude = 17.142
29
- @environment = Config.default_environment
30
- @environment[:at_location] = {:north => latitude, :west => -longitude}
31
- SwitchFactory.new(["house_code", "unit_code", "model_name"])
32
- @devices = {"sovrum" => [Switch.new(:house_code => "4", :unit_code => "4", :model_name => "plain_text")],
33
- "källare" => [Switch.new(:house_code => "4", :unit_code => "4", :model_name => "plain_text")]}
34
-
35
- end
36
- it "should respond to schedule_action" do
37
- Schedule.create.schedule_action(Action.new("tänd källare klockan 14:00",@devices,@environment,@date)).should_not be_nil
38
- end
39
-
40
- it "should respond to find" do
41
- schedule = Schedule.create
42
- schedule.schedule_action(Action.new("tänd källare klockan 14:10",@devices,@environment,@date))
43
- name = "tänd källare klockan 14:10"
44
- event = schedule.find(name)
45
- event.should_not be_nil
46
- event.to_s.should include(name)
47
- end
48
-
49
- it "should respond to delete" do
50
- schedule = Schedule.create
51
- schedule.schedule_action(Action.new("släck sovrum klockan 14:15",@devices,@environment,@date))
52
- name = "släck sovrum klockan 14:15"
53
- schedule.find(name).should_not be_nil
54
- schedule.delete(name).should_not be_nil
55
- schedule.find(name).should be_nil
56
- end
57
-
58
- it "should respond to execute" do
59
- schedule = Schedule.create
60
- output = StringIO.new
61
- schedule.schedule_action(Action.new("tänd sovrum klockan 14:45",@devices,@environment,@date))
62
- name = "tänd sovrum klockan 14:45"
63
- schedule.find(name).should_not be_nil
64
- schedule.execute("14:45",output)
65
- schedule.find(name).should be_nil
66
- output.string.should include("Strömbrytare 44 tänd")
67
- end
68
-
69
- context "action scheduled at sunrise" do
70
- it "should respond to execute" do
71
- schedule = Schedule.create
72
- output = StringIO.new
73
- action = Action.new("tänd sovrum vid soluppgång",@devices,@environment,@date)
74
- schedule.schedule_action(action)
75
- schedule.find(action.to_s).should_not be_nil
76
- schedule.execute("08:55",output)
77
- schedule.find(action.to_s).should be_nil
78
- output.string.should include("Strömbrytare 44 tänd")
79
- end
80
- end
81
-
82
- it "should not execute action if action deleted" do
83
- schedule = Schedule.create
84
- output = StringIO.new
85
- schedule.schedule_action(Action.new("tänd sovrum klockan 14:45",@devices,@environment,@date))
86
- name = "tänd sovrum klockan 14:45"
87
- schedule.find(name).should_not be_nil
88
- schedule.delete(name)
89
- schedule.find(name).should be_nil
90
- schedule.execute("14:45",output)
91
- output.string.should_not include("Strömbrytare 44 tänd")
92
- end
93
-
94
- it "finds next action by hour and minute" do
95
- schedule = Schedule.create
96
- schedule.schedule_action(Action.new("tänd källare klockan 15:15",@devices,@environment,@date))
97
- schedule.schedule_action(Action.new("tänd källare klockan 14:00",@devices,@environment,@date))
98
- schedule.next_action_at("13:59").should == "14:00"
99
- schedule.next_action_at("14:00").should == "15:15"
100
- schedule.next_action_at("15:15").should == "23:59:59"
101
- end
102
- end
103
- end
@@ -1,24 +0,0 @@
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
- module TriggerSwitchD
18
- def self.verify_log_includes(pattern,count,expected)
19
- in_log = Config.log_object.string.scan(pattern).flatten
20
- in_log.length.should == count
21
- in_log.select {|str| expected.include? str}.length.should == count
22
- end
23
-
24
- end
@@ -1,43 +0,0 @@
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 'rubygems'
19
- SPEC = Gem::Specification.new do |s|
20
- s.name = "trigger_switch_d"
21
- s.version = "0.1.1"
22
- s.author = "Pontus Strömdahl"
23
- s.email = "pontus.stromdahl@adhocskill.com"
24
- s.homepage = "http://www.adhocskill.com/"
25
- s.platform = Gem::Platform::RUBY
26
- s.summary = "Daemon to execute schedule for remote devices"
27
- s.description = <<-EOS
28
- Schedule remote triggered switches and dimmers to activate/deactivate the lights in your home.\n
29
- Type your schedule in plain text and have an USB connected tellstick send the appropriate commands,\n
30
- according to your schedule.
31
- EOS
32
-
33
- candidates = Dir.glob("{bin,doc,lib,spec,features}/**/*")
34
- candidates += ["LICENSE.txt","README.rdoc","COPYING.txt","trigger_switch_d.gemspec"]
35
- s.files = candidates.delete_if do |item|
36
- item.include?("CVS") || item.include?("rdoc") ||
37
- item.include?("devices") || item.include?("scheduled_actions")
38
- end
39
- s.require_path = "lib"
40
- s.has_rdoc = true
41
- s.extra_rdoc_files = ["README.rdoc"]
42
- s.add_dependency("serialport", ">= 0.8.0")
43
- end