iremocon 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +69 -0
- data/Rakefile +2 -0
- data/iremocon.gemspec +19 -0
- data/lib/iremocon.rb +71 -0
- data/lib/iremocon/version.rb +3 -0
- data/spec/iremocon_spec.rb +121 -0
- data/spec/spec_helper.rb +2 -0
- metadata +69 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Ryo NAKAMURA
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# Iremocon
|
2
|
+
Iremocon is a gem for managing [iRemocon](http://i-remocon.com/) through telnet.
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
|
6
|
+
```
|
7
|
+
$ gem install iremocon
|
8
|
+
```
|
9
|
+
|
10
|
+
## Usage
|
11
|
+
iRemocon has following commands.
|
12
|
+
|
13
|
+
* au 接続確認用
|
14
|
+
* is 赤外線発信
|
15
|
+
* ic リモコン学習開始
|
16
|
+
* cc リモコン学習中止
|
17
|
+
* tm タイマーセット
|
18
|
+
* tl タイマー一覧取得
|
19
|
+
* td タイマー解除
|
20
|
+
* ts 現在時刻設定
|
21
|
+
* tg 現在時刻取得
|
22
|
+
* vr ファームバージョン番号の取得
|
23
|
+
|
24
|
+
You can call it as an instance method of Iremocon class.
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
require "iremocon"
|
28
|
+
|
29
|
+
iremocon = Iremocon.new("192.168.0.2")
|
30
|
+
|
31
|
+
iremocon.au
|
32
|
+
#=> send "*au"
|
33
|
+
|
34
|
+
iremocon.is(1)
|
35
|
+
#=> send "*is;1"
|
36
|
+
|
37
|
+
iremocon.ic(1)
|
38
|
+
#=> send "*ic;1"
|
39
|
+
|
40
|
+
iremocon.cc
|
41
|
+
#=> send "*cc"
|
42
|
+
|
43
|
+
iremocon.tm(1, 946652400, 60)
|
44
|
+
#=> send "*tm;1;946652400;60"
|
45
|
+
|
46
|
+
iremocon.tm(1, Time.local(2000), 60)
|
47
|
+
#=> send "*tm;1;946652400;60"
|
48
|
+
|
49
|
+
iremocon.tm(1, Time.local(2000))
|
50
|
+
#=> send "*tm;1;946652400;0"
|
51
|
+
|
52
|
+
iremocon.tl
|
53
|
+
#=> send "*tl"
|
54
|
+
|
55
|
+
iremocon.td(1)
|
56
|
+
#=> send "*td;1"
|
57
|
+
|
58
|
+
iremocon.ts(946652400)
|
59
|
+
#=> send "*ts;946652400"
|
60
|
+
|
61
|
+
iremocon.ts(Time.local(2000))
|
62
|
+
#=> send "*ts;946652400"
|
63
|
+
|
64
|
+
iremocon.tg
|
65
|
+
#=> send "*tg"
|
66
|
+
|
67
|
+
iremocon.vr
|
68
|
+
#=> send "*vr"
|
69
|
+
```
|
data/Rakefile
ADDED
data/iremocon.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/iremocon/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Ryo NAKAMURA"]
|
6
|
+
gem.email = ["ryo-nakamura@cookpad.com"]
|
7
|
+
gem.description = "Iremocon is a gem for managing iRemocon through telnet"
|
8
|
+
gem.summary = "iRemocon manager"
|
9
|
+
gem.homepage = "https://github.com/r7kamura/iremocon"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "iremocon"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Iremocon::VERSION
|
17
|
+
|
18
|
+
gem.add_development_dependency "rspec"
|
19
|
+
end
|
data/lib/iremocon.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
require "iremocon/version"
|
2
|
+
require "net/telnet"
|
3
|
+
|
4
|
+
class Iremocon
|
5
|
+
attr_reader :host, :port, :telnet
|
6
|
+
|
7
|
+
def initialize(host, port = 51013)
|
8
|
+
@host = host
|
9
|
+
@port = port
|
10
|
+
connect
|
11
|
+
end
|
12
|
+
|
13
|
+
def au
|
14
|
+
command("au")
|
15
|
+
end
|
16
|
+
|
17
|
+
def is(channel)
|
18
|
+
command("is", channel)
|
19
|
+
end
|
20
|
+
|
21
|
+
def ic(channel)
|
22
|
+
command("ic", channel)
|
23
|
+
end
|
24
|
+
|
25
|
+
def cc
|
26
|
+
command("cc")
|
27
|
+
end
|
28
|
+
|
29
|
+
def tm(channel, time, interval = 0)
|
30
|
+
command("tm", channel, time.to_i, interval)
|
31
|
+
end
|
32
|
+
|
33
|
+
def tl
|
34
|
+
command("tl")
|
35
|
+
end
|
36
|
+
|
37
|
+
def td(timer_id)
|
38
|
+
command("td", timer_id)
|
39
|
+
end
|
40
|
+
|
41
|
+
def ts(time)
|
42
|
+
command("ts", time.to_i)
|
43
|
+
end
|
44
|
+
|
45
|
+
def tg
|
46
|
+
command("tg")
|
47
|
+
end
|
48
|
+
|
49
|
+
def vr
|
50
|
+
command("vr")
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def connect
|
56
|
+
@telnet = Net::Telnet.new("Host" => @host, "Port" => @port)
|
57
|
+
rescue Errno::ECONNREFUSED
|
58
|
+
raise ConnectionError.new("Connection failed - #{@host}:#{@port}")
|
59
|
+
end
|
60
|
+
|
61
|
+
def command(name, *args)
|
62
|
+
str = ["*#{name}", *args].compact.join(";")
|
63
|
+
puts catch(:exit) {
|
64
|
+
@telnet.cmd(str) { |res| throw :exit, res }
|
65
|
+
}
|
66
|
+
rescue Timeout::Error
|
67
|
+
puts "Timeout - 10sec"
|
68
|
+
end
|
69
|
+
|
70
|
+
class ConnectionError < StandardError; end
|
71
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Iremocon do
|
4
|
+
let!(:server) do
|
5
|
+
TCPServer.new("127.0.0.1", 50000)
|
6
|
+
end
|
7
|
+
|
8
|
+
let!(:client) do
|
9
|
+
Iremocon.new("127.0.0.1", 50000)
|
10
|
+
end
|
11
|
+
|
12
|
+
before do
|
13
|
+
client.stub(:puts) # To silence a command result
|
14
|
+
end
|
15
|
+
|
16
|
+
after do
|
17
|
+
server.close
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#new" do
|
21
|
+
context "when connection succeeded" do
|
22
|
+
it "should connect to tcp server by Net::Telnet client" do
|
23
|
+
client.telnet.should be_a(Net::Telnet)
|
24
|
+
client.telnet.close
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "when connection failed" do
|
29
|
+
it do
|
30
|
+
expect do
|
31
|
+
Iremocon.new("127.0.0.1", 60000)
|
32
|
+
end.to raise_error(Iremocon::ConnectionError)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "#au" do
|
38
|
+
it "should send *au" do
|
39
|
+
client.telnet.should_receive(:cmd).with("*au")
|
40
|
+
client.au
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "#is" do
|
45
|
+
it "should send *is;<channel>" do
|
46
|
+
client.telnet.should_receive(:cmd).with("*is;1")
|
47
|
+
client.is(1)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "#ic" do
|
52
|
+
it "should send *ic;<channel>" do
|
53
|
+
client.telnet.should_receive(:cmd).with("*ic;1")
|
54
|
+
client.ic(1)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "#cc" do
|
59
|
+
it "should send *cc" do
|
60
|
+
client.telnet.should_receive(:cmd).with("*cc")
|
61
|
+
client.cc
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "#tm" do
|
66
|
+
it "should send *tm;<channel>;<time>;<interval>" do
|
67
|
+
client.telnet.should_receive(:cmd).with("*tm;1;946652400;60")
|
68
|
+
client.tm(1, 946652400, 60)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should convert time to epoch time" do
|
72
|
+
client.telnet.should_receive(:cmd).with("*tm;1;946652400;60")
|
73
|
+
client.tm(1, Time.local(2000), 60)
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should complement interval with 0 as default" do
|
77
|
+
client.telnet.should_receive(:cmd).with("*tm;1;946652400;0")
|
78
|
+
client.tm(1, Time.local(2000))
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "#tl" do
|
83
|
+
it "should send *tl" do
|
84
|
+
client.telnet.should_receive(:cmd).with("*tl")
|
85
|
+
client.tl
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "#td" do
|
90
|
+
it "should send *td;<timer_id>" do
|
91
|
+
client.telnet.should_receive(:cmd).with("*td;1")
|
92
|
+
client.td(1)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe "#ts" do
|
97
|
+
it "should send *ts;<time>" do
|
98
|
+
client.telnet.should_receive(:cmd).with("*ts;946652400")
|
99
|
+
client.ts(946652400)
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should convert time to epoch time" do
|
103
|
+
client.telnet.should_receive(:cmd).with("*ts;946652400")
|
104
|
+
client.ts(Time.local(2000))
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe "#tg" do
|
109
|
+
it "should send *tg" do
|
110
|
+
client.telnet.should_receive(:cmd).with("*tg")
|
111
|
+
client.tg
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe "#vr" do
|
116
|
+
it "should send *vr" do
|
117
|
+
client.telnet.should_receive(:cmd).with("*vr")
|
118
|
+
client.vr
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: iremocon
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ryo NAKAMURA
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-06 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &70106172484540 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70106172484540
|
25
|
+
description: Iremocon is a gem for managing iRemocon through telnet
|
26
|
+
email:
|
27
|
+
- ryo-nakamura@cookpad.com
|
28
|
+
executables: []
|
29
|
+
extensions: []
|
30
|
+
extra_rdoc_files: []
|
31
|
+
files:
|
32
|
+
- .gitignore
|
33
|
+
- Gemfile
|
34
|
+
- LICENSE
|
35
|
+
- README.md
|
36
|
+
- Rakefile
|
37
|
+
- iremocon.gemspec
|
38
|
+
- lib/iremocon.rb
|
39
|
+
- lib/iremocon/version.rb
|
40
|
+
- spec/iremocon_spec.rb
|
41
|
+
- spec/spec_helper.rb
|
42
|
+
homepage: https://github.com/r7kamura/iremocon
|
43
|
+
licenses: []
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ! '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
requirements: []
|
61
|
+
rubyforge_project:
|
62
|
+
rubygems_version: 1.8.15
|
63
|
+
signing_key:
|
64
|
+
specification_version: 3
|
65
|
+
summary: iRemocon manager
|
66
|
+
test_files:
|
67
|
+
- spec/iremocon_spec.rb
|
68
|
+
- spec/spec_helper.rb
|
69
|
+
has_rdoc:
|