trigger_switch_d 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +2 -2
- data/bin/teach +6 -3
- data/bin/tsd +1 -1
- data/bin/turn_off +6 -3
- data/bin/turn_on +6 -3
- data/lib/tellstick.rb +1 -2
- data/lib/tellstick/proxy_io.rb +58 -0
- data/lib/trigger_switch_d.rb +1 -0
- data/lib/trigger_switch_d/config.rb +7 -3
- data/spec/tellstick/{tellstick_io_spec.rb → proxy_io_spec.rb} +12 -9
- data/spec/trigger_switch_d/application_spec.rb +3 -0
- data/spec/trigger_switch_d/config_spec.rb +61 -1
- data/trigger_switch_d.gemspec +2 -2
- metadata +8 -8
- data/lib/tellstick/tellstick_io.rb +0 -80
data/README.rdoc
CHANGED
@@ -9,8 +9,8 @@ See link:License.txt
|
|
9
9
|
|
10
10
|
Mac OSX
|
11
11
|
USB dongle (such as tellstick from http://www.telldus.se)
|
12
|
-
ruby-
|
13
|
-
|
12
|
+
ruby-serialport (http://ruby-serialport.rubyforge.org/)
|
13
|
+
VCP USB drivers (available at http://ftdichip.com)
|
14
14
|
|
15
15
|
==Description
|
16
16
|
Scheduled (tsd) is run as a daemon without any need for user interaction.
|
data/bin/teach
CHANGED
@@ -34,11 +34,14 @@
|
|
34
34
|
|
35
35
|
$LOAD_PATH.push File.join(File.dirname(__FILE__),".." ,"lib" )
|
36
36
|
require 'tellstick'
|
37
|
+
require 'trigger_switch_d'
|
37
38
|
|
38
39
|
#code to run tellstick app
|
39
|
-
|
40
|
-
|
40
|
+
File.open(TriggerSwitchD::ConfigFactory::ENV_PATH,"r") do |config_file|
|
41
|
+
TriggerSwitchD::ConfigFactory.new(config_file)
|
42
|
+
end
|
43
|
+
stick = Tellstick::create(TriggerSwitchD::Config.output,ARGV[2])
|
41
44
|
stick.teach(ARGV[0],ARGV[1])
|
42
|
-
output.close
|
45
|
+
TriggerSwitchD::Config.output.close
|
43
46
|
|
44
47
|
|
data/bin/tsd
CHANGED
data/bin/turn_off
CHANGED
@@ -31,12 +31,15 @@
|
|
31
31
|
|
32
32
|
$LOAD_PATH.push File.join(File.dirname(__FILE__),".." ,"lib" )
|
33
33
|
require 'tellstick'
|
34
|
+
require 'trigger_switch_d'
|
34
35
|
|
35
36
|
#code to run tellstick app
|
36
|
-
|
37
|
-
|
37
|
+
File.open(TriggerSwitchD::ConfigFactory::ENV_PATH,"r") do |config_file|
|
38
|
+
TriggerSwitchD::ConfigFactory.new(config_file)
|
39
|
+
end
|
40
|
+
stick = Tellstick::create(TriggerSwitchD::Config.output,ARGV[2])
|
38
41
|
stick.turn_off(ARGV[0],ARGV[1])
|
39
|
-
output.close
|
42
|
+
TriggerSwitchD::Config.output.close
|
40
43
|
|
41
44
|
|
42
45
|
|
data/bin/turn_on
CHANGED
@@ -31,9 +31,12 @@
|
|
31
31
|
|
32
32
|
$LOAD_PATH.push File.join(File.dirname(__FILE__),".." ,"lib" )
|
33
33
|
require 'tellstick'
|
34
|
+
require 'trigger_switch_d'
|
34
35
|
|
35
36
|
#code to run tellstick app
|
36
|
-
|
37
|
-
|
37
|
+
File.open(TriggerSwitchD::ConfigFactory::ENV_PATH,"r") do |config_file|
|
38
|
+
TriggerSwitchD::ConfigFactory.new(config_file)
|
39
|
+
end
|
40
|
+
stick = Tellstick::create(TriggerSwitchD::Config.output,ARGV[2])
|
38
41
|
stick.turn_on(ARGV[0],ARGV[1])
|
39
|
-
output.close
|
42
|
+
TriggerSwitchD::Config.output.close
|
data/lib/tellstick.rb
CHANGED
@@ -0,0 +1,58 @@
|
|
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 Tellstick
|
18
|
+
|
19
|
+
class ProxyIO #:nodoc:all
|
20
|
+
public
|
21
|
+
def initialize(klass,*args)
|
22
|
+
@init_args = args
|
23
|
+
@class_to_proxy = klass
|
24
|
+
@tio = nil
|
25
|
+
open
|
26
|
+
end
|
27
|
+
def open
|
28
|
+
return unless @tio == nil
|
29
|
+
if (@init_args.empty?)
|
30
|
+
@tio = @class_to_proxy.new
|
31
|
+
else
|
32
|
+
@tio = @class_to_proxy.new(@init_args[0],@init_args[1])
|
33
|
+
@init_args[2].call(@tio)
|
34
|
+
end
|
35
|
+
if @tio.methods.include?("connected?")
|
36
|
+
def self.connected?
|
37
|
+
open
|
38
|
+
@tio.connected?
|
39
|
+
end
|
40
|
+
end
|
41
|
+
return if @tio.private_methods.include?("open")
|
42
|
+
@tio.open
|
43
|
+
end
|
44
|
+
def close
|
45
|
+
@tio.close unless @tio == nil
|
46
|
+
@tio = nil
|
47
|
+
end
|
48
|
+
def puts(input)
|
49
|
+
open
|
50
|
+
@tio.puts(input)
|
51
|
+
end
|
52
|
+
def gets
|
53
|
+
open
|
54
|
+
@tio.gets
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
data/lib/trigger_switch_d.rb
CHANGED
@@ -13,10 +13,11 @@
|
|
13
13
|
#
|
14
14
|
# You should have received a copy of the GNU General Public License
|
15
15
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
-
|
16
|
+
require "serialport"
|
17
17
|
|
18
18
|
module TriggerSwitchD
|
19
19
|
module ConfigFactory
|
20
|
+
ENV_PATH = "config/environment.rb"
|
20
21
|
|
21
22
|
#Creates the Config class from the config/config.rb file
|
22
23
|
#See samples/config.rb for more documentation
|
@@ -25,6 +26,7 @@ module TriggerSwitchD
|
|
25
26
|
attributes = env.map do |attribute|
|
26
27
|
attribute.scan(/Config.([\w_]+) =/).flatten[0]
|
27
28
|
end
|
29
|
+
attributes.compact!
|
28
30
|
cls = <<-EOS
|
29
31
|
class Config
|
30
32
|
#{attributes.map {|name| "def self.#{name}=(value); #{append_filenames(name)}; end"}.join("\n")}
|
@@ -62,8 +64,10 @@ module TriggerSwitchD
|
|
62
64
|
end
|
63
65
|
|
64
66
|
def self.set_type(name)
|
65
|
-
types = {"log_object" => "{:spec => StringIO.new, :development => STDOUT,
|
66
|
-
|
67
|
+
types = {"log_object" => "{:spec => StringIO.new, :development => STDOUT,
|
68
|
+
:file => File.open(\"#log_path}\",\"a+\")}",
|
69
|
+
"output" => "Hash.new(STDOUT).merge({:spec => StringIO.new, :development => STDOUT,
|
70
|
+
:vcp => Tellstick::ProxyIO.new(SerialPort,Config.vcp_port,4800,Proc.new { |sp| sp.puts(\"~^M~AT S7=45 S0=0 L1 V1 X4 &c1 E1 Q0^M\"); sp.puts(\"S+\"); sp.gets })})"}
|
67
71
|
return "@#{name}=value" unless types.keys.include? name
|
68
72
|
"@#{name}=#{types[name]}[value]".gsub("log_path","{log_path")
|
69
73
|
end
|
@@ -18,14 +18,17 @@
|
|
18
18
|
require File.join(File.dirname(__FILE__),"..","spec_helper")
|
19
19
|
|
20
20
|
module Tellstick
|
21
|
-
describe
|
22
|
-
it "
|
23
|
-
dongle =
|
24
|
-
dongle.
|
25
|
-
dongle.gets.
|
26
|
-
dongle.
|
27
|
-
|
28
|
-
|
29
|
-
|
21
|
+
describe ProxyIO do
|
22
|
+
it "should respond to puts, gets when there is no TellstickIO instance" do
|
23
|
+
dongle = StringIO.new
|
24
|
+
dongle.stub!(:new).and_return(dongle)
|
25
|
+
dongle.stub!(:gets).and_return("bla")
|
26
|
+
dongle.stub!(:close)
|
27
|
+
proxy = ProxyIO.new(StringIO)
|
28
|
+
proxy.close
|
29
|
+
Proc.new { proxy.puts "bla" }.should_not raise_error(NoMethodError)
|
30
|
+
proxy.close
|
31
|
+
Proc.new { proxy.gets }.should_not raise_error(NoMethodError)
|
32
|
+
end
|
30
33
|
end
|
31
34
|
end
|
@@ -22,12 +22,15 @@ module TriggerSwitchD
|
|
22
22
|
|
23
23
|
describe "Application" do
|
24
24
|
before(:each) do
|
25
|
+
mock_sp = StringIO.new
|
26
|
+
SerialPort.stub!(:new).and_return(mock_sp)
|
25
27
|
@file = StringIO.new
|
26
28
|
@file.puts <<-EOS
|
27
29
|
Config.geo_position = {:north => 54.57525, :west => -12.94125}
|
28
30
|
Config.log_path = "log"
|
29
31
|
Config.db_path = "db"
|
30
32
|
Config.dsl_path = "config"
|
33
|
+
Config.vcp_port = "/dev/tty.usbserial-xxxxxxxx"
|
31
34
|
#Config.log_object = :file
|
32
35
|
Config.log_object = :spec
|
33
36
|
Config.output = :spec
|
@@ -20,12 +20,18 @@ require File.join(File.dirname(__FILE__),"..","spec_helper")
|
|
20
20
|
module TriggerSwitchD
|
21
21
|
describe "Config" do
|
22
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)
|
23
28
|
file = StringIO.new
|
24
29
|
file.puts <<-EOS
|
25
30
|
Config.geo_position = {:north => 54.57525, :west => -12.94125}
|
26
31
|
Config.log_path = "log"
|
27
32
|
Config.db_path = "db"
|
28
33
|
Config.dsl_path = "config"
|
34
|
+
Config.vcp_port = "/dev/tty.usbserial-xxxxxxxx"
|
29
35
|
Config.unix_socket_path = "/tmp"
|
30
36
|
Config.log_object = :spec
|
31
37
|
Config.output = :spec
|
@@ -67,7 +73,10 @@ module TriggerSwitchD
|
|
67
73
|
Config.output = :development
|
68
74
|
Config.output.should be_kind_of(IO)
|
69
75
|
Config.output = :tellstick
|
70
|
-
Config.output.should
|
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)
|
71
80
|
end
|
72
81
|
|
73
82
|
it "should respond to environment" do
|
@@ -90,5 +99,56 @@ EOS
|
|
90
99
|
:at_location => {:north => 54.57525, :west => -12.94125}}
|
91
100
|
|
92
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
|
93
153
|
end
|
94
154
|
end
|
data/trigger_switch_d.gemspec
CHANGED
@@ -18,7 +18,7 @@
|
|
18
18
|
require 'rubygems'
|
19
19
|
SPEC = Gem::Specification.new do |s|
|
20
20
|
s.name = "trigger_switch_d"
|
21
|
-
s.version = "0.1.
|
21
|
+
s.version = "0.1.1"
|
22
22
|
s.author = "Pontus Strömdahl"
|
23
23
|
s.email = "pontus.stromdahl@adhocskill.com"
|
24
24
|
s.homepage = "http://www.adhocskill.com/"
|
@@ -39,5 +39,5 @@ SPEC = Gem::Specification.new do |s|
|
|
39
39
|
s.require_path = "lib"
|
40
40
|
s.has_rdoc = true
|
41
41
|
s.extra_rdoc_files = ["README.rdoc"]
|
42
|
-
s.add_dependency("
|
42
|
+
s.add_dependency("serialport", ">= 0.8.0")
|
43
43
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- "Pontus Str\xC3\xB6mdahl"
|
@@ -14,11 +14,11 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-03-
|
17
|
+
date: 2010-03-29 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
|
-
name:
|
21
|
+
name: serialport
|
22
22
|
prerelease: false
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
@@ -26,9 +26,9 @@ dependencies:
|
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
segments:
|
28
28
|
- 0
|
29
|
+
- 8
|
29
30
|
- 0
|
30
|
-
|
31
|
-
version: 0.0.1
|
31
|
+
version: 0.8.0
|
32
32
|
type: :runtime
|
33
33
|
version_requirements: *id001
|
34
34
|
description: " Schedule remote triggered switches and dimmers to activate/deactivate the lights in your home.\n\n Type your schedule in plain text and have an USB connected tellstick send the appropriate commands,\n\n according to your schedule.\n"
|
@@ -116,8 +116,8 @@ files:
|
|
116
116
|
- lib/tellstick/protocol/protocol_loader.rb
|
117
117
|
- lib/tellstick/protocol/rising_sun.rb
|
118
118
|
- lib/tellstick/protocol/waveman.rb
|
119
|
+
- lib/tellstick/proxy_io.rb
|
119
120
|
- lib/tellstick/tellstick.rb
|
120
|
-
- lib/tellstick/tellstick_io.rb
|
121
121
|
- lib/tellstick.rb
|
122
122
|
- lib/trigger_switch_d/action.rb
|
123
123
|
- lib/trigger_switch_d/application.rb
|
@@ -133,7 +133,7 @@ files:
|
|
133
133
|
- spec/tellstick/protocol/proove_spec.rb
|
134
134
|
- spec/tellstick/protocol/rising_sun_spec.rb
|
135
135
|
- spec/tellstick/protocol/waveman_spec.rb
|
136
|
-
- spec/tellstick/
|
136
|
+
- spec/tellstick/proxy_io_spec.rb
|
137
137
|
- spec/tellstick/tellstick_spec.rb
|
138
138
|
- spec/trigger_switch_d/application_spec.rb
|
139
139
|
- spec/trigger_switch_d/config_spec.rb
|
@@ -1,80 +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
|
-
require "ftd2xx"
|
20
|
-
require "pp"
|
21
|
-
|
22
|
-
module Tellstick
|
23
|
-
|
24
|
-
#IO stream associated with the tellstick
|
25
|
-
class TellstickIO
|
26
|
-
def initialize
|
27
|
-
open
|
28
|
-
end
|
29
|
-
|
30
|
-
#writes input string to tellstick
|
31
|
-
def puts(input)
|
32
|
-
input.scan(/.{1,8}/).each do |str|
|
33
|
-
Ftd2xx.write(@handle,str)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
#reads string from tellstick
|
38
|
-
def gets
|
39
|
-
reply = ""
|
40
|
-
bytes_read = 1
|
41
|
-
c = " "
|
42
|
-
while (bytes_read != 0) and (c != "\n")
|
43
|
-
c = " "
|
44
|
-
bytes_read = Ftd2xx.read(@handle,c)
|
45
|
-
reply << c
|
46
|
-
end
|
47
|
-
reply
|
48
|
-
end
|
49
|
-
|
50
|
-
#close tellstick stream
|
51
|
-
def close
|
52
|
-
Ftd2xx.ft_close(@handle)
|
53
|
-
@handle = nil
|
54
|
-
end
|
55
|
-
|
56
|
-
#opens tellstick stream
|
57
|
-
def open
|
58
|
-
Ftd2xx.ft_set_vidpid(0x1781,0x0c30)
|
59
|
-
device_index = Ftd2xx.create_device_info_list - 1
|
60
|
-
@handle = Ftd2xx.open(device_index)
|
61
|
-
Ftd2xx.ft_set_baud_rate(@handle,4800)
|
62
|
-
Ftd2xx.ft_set_timeouts(@handle,5000,0)
|
63
|
-
if @handle == nil
|
64
|
-
def puts(input);end
|
65
|
-
def gets;end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
#true if connected
|
70
|
-
def connected?
|
71
|
-
close
|
72
|
-
open
|
73
|
-
puts("S+")
|
74
|
-
answer = gets
|
75
|
-
close
|
76
|
-
open
|
77
|
-
answer == "+S\r\n"
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|