iremocon_control 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b72b7f828575729e18e3fe9683a1e14859d4dd25
4
- data.tar.gz: bd5613515ad8f18ce1f2bdb0265b8a132a4c3ade
3
+ metadata.gz: 2c0c54f0840128ef6f2daf0a9282379120df398a
4
+ data.tar.gz: 5914525d2c73291055102a1957675aad40e5ccc9
5
5
  SHA512:
6
- metadata.gz: 31d4f6dad7d563b58aea0c6898db9d17f67630cc1841984f705279f341b5a4e8d7d7ee393a31647a6d51cb4ac218a82dc69e9a87e50bb29c7950fad4a3bcf07d
7
- data.tar.gz: fdcc65784c484624611dab962396dd6f7a95179ede1b6bab79e150e6fc1ab4f3a92ef97065395ac4d60b13974820a0a005a916c9117ccbdfcb1ffdb32807f6a2
6
+ metadata.gz: 0bd816967a3134bdee5fb2294ea1f94bd489ce0e7d5d571dd839e376b34767fc857eec8bc25cb7ec786f7a9eefee875716ae39ee545aa52ef9ac30fa5d80b221
7
+ data.tar.gz: 1ae325f37e38824b9befabffc9f3ecae3ec0d5729fc51419d1a884227f0fbf31557a8016750e5f6afaa6276e069d3e79089924173c98e9ef0f9c9679bf2c08b5
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # IremoconControl
2
2
 
3
- TODO: Write a gem description
3
+ 株式会社Glamoから発売されている学習リモコンiRemoconをRubyから操作するgemです。
4
+ 赤外線送信、赤外線登録、タイマ登録など一通りの機能があります。
4
5
 
5
6
  ## Installation
6
7
 
@@ -18,7 +19,56 @@ Or install it yourself as:
18
19
 
19
20
  ## Usage
20
21
 
21
- TODO: Write usage instructions here
22
+ ### Ruby上からIRemoconを操作する場合
23
+ モジュールをロードします。
24
+
25
+ require 'iremocon_control'
26
+
27
+ IRemoconオブジェクトを作成します。
28
+
29
+ iremocon = IRemoconControl::IRemocon.new '192.168.0.100'
30
+
31
+ IRemoconオブジェクトに対してコマンドを発行します。
32
+
33
+ # リモコンNo.1として登録した赤外線を送信
34
+ iremocon.is 1
35
+
36
+ ### シェル上からIRemoconを操作する場合
37
+ #### 基本的な使い方
38
+ ホスト名とリモコン番号を指定して赤外線を送信
39
+
40
+ $ iremocon -h 192.168.0.100 1
41
+
42
+ #### 設定ファイルの読み込み
43
+ 設定ファイルにiRemoconのホスト名(、ポート番号)を指定することができます。
44
+ 設定はYAML形式で指定します。
45
+
46
+ $ cat iremoconrc
47
+ host: 192.168.0.100
48
+ $ iremocon -f iremoconrc 1
49
+
50
+ ~/.iremoconrcはデフォルトで読み込まれます。
51
+
52
+ $ cat ~/.iremoconrc
53
+ host: 192.168.0.100
54
+ $ iremocon 1
55
+
56
+ #### is(赤外線送信)以外のコマンドの利用
57
+ iremoconとの接続の確認
58
+
59
+ $ iremocon --au
60
+
61
+ iremoconの現在時刻設定(引数 : 設定する時刻のUnixTime)
62
+
63
+ $ iremocon --ts `date '+%s'`
64
+
65
+ iremoconの現在時刻取得
66
+
67
+ $ iremocon --tg
68
+
69
+ iremoconのバージョン番号取得
70
+
71
+ $ iremocon --vr
22
72
 
23
73
  ## Contributing
24
74
 
data/bin/iremocon CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  #encoding: utf-8
3
3
 
4
- require 'iremocon_control'
4
+ require_relative '../lib/iremocon_control.rb'
5
5
  require 'optparse'
6
6
  require 'yaml'
7
7
 
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["yuta84q.ihcarok@gmail.com"]
11
11
  spec.summary = "send commands to iremocon"
12
12
  spec.description = "send commands to iremocon"
13
- spec.homepage = ""
13
+ spec.homepage = "https://github.com/84q/iremocon_control"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
@@ -23,6 +23,22 @@ module IRemoconControl
23
23
  def inspect
24
24
  "[#{@command}-#{@code}] #{@desctiption}"
25
25
  end
26
+
27
+ #
28
+ # IRemoconからの戻り値がエラーか
29
+ #
30
+ def self.error?(reply)
31
+ reply[1] == "err"
32
+ end
33
+
34
+ #
35
+ # IRemoconからのエラーの返す
36
+ #
37
+ def self.get_error(reply)
38
+ cmd = reply[0]
39
+ err_no = reply[2]
40
+ return IRemoconError.new cmd, err_no
41
+ end
26
42
  end
27
43
  end
28
44
 
@@ -1,3 +1,3 @@
1
1
  module IRemoconControl
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -15,6 +15,9 @@ module IRemoconControl
15
15
 
16
16
  #
17
17
  # コンストラクタ
18
+ # @param [String] host IRemoconのホスト名(またはIPアドレス)
19
+ # @param [Integer] port IRemoconのポート番号
20
+ # @param [String,Logger,IO] logger ログの出力先(出力しない場合、nil)
18
21
  #
19
22
  def initialize(host, port=51013, logger:nil)
20
23
  @host = host
@@ -25,6 +28,9 @@ module IRemoconControl
25
28
 
26
29
  #
27
30
  # 接続の確認用コマンド
31
+ # @return [TrueClass] 常にtrue
32
+ # @raise [TelnetConnectionError] 通信エラーが発生した場合
33
+ # @raise [IRemoconError] IRemoconからエラーが帰ってきた場合
28
34
  #
29
35
  def au
30
36
  reply = send_cmd("*au")
@@ -33,6 +39,10 @@ module IRemoconControl
33
39
 
34
40
  #
35
41
  # 赤外線発光用コマンド
42
+ # @param [Integer] remocon_id 発行するリモコンID
43
+ # @return [TrueClass] 常にtrue
44
+ # @raise [TelnetConnectionError] 通信エラーが発生した場合
45
+ # @raise [IRemoconError] IRemoconからエラーが帰ってきた場合
36
46
  #
37
47
  def is(remocon_id)
38
48
  reply = send_cmd("*is", remocon_id)
@@ -41,6 +51,10 @@ module IRemoconControl
41
51
 
42
52
  #
43
53
  # リモコン学習開始用コマンド
54
+ # @param [Integer] remocon_id 学習するリモコンID
55
+ # @return [TrueClass] 常にtrue
56
+ # @raise [TelnetConnectionError] 通信エラーが発生した場合
57
+ # @raise [IRemoconError] IRemoconからエラーが帰ってきた場合
44
58
  #
45
59
  def ic(remocon_id)
46
60
  reply = send_cmd("*ic", remocon_id)
@@ -49,6 +63,9 @@ module IRemoconControl
49
63
 
50
64
  #
51
65
  # リモコン学習中止用コマンド
66
+ # @return [TrueClass] 常にtrue
67
+ # @raise [TelnetConnectionError] 通信エラーが発生した場合
68
+ # @raise [IRemoconError] IRemoconからエラーが帰ってきた場合
52
69
  #
53
70
  def cc
54
71
  reply = send_cmd("*cc")
@@ -57,6 +74,12 @@ module IRemoconControl
57
74
 
58
75
  #
59
76
  # タイマーセット用コマンド
77
+ # @param [Integer] remocon_id タイマーをセットするリモコンID
78
+ # @param [Time] time 次回の日時
79
+ # @param [Time] repeat_interval 繰り返し秒数(繰り返さない場合、0)
80
+ # @return [TrueClass] 常にtrue
81
+ # @raise [TelnetConnectionError] 通信エラーが発生した場合
82
+ # @raise [IRemoconError] IRemoconからエラーが帰ってきた場合
60
83
  #
61
84
  def tm(remocon_id, time, repeat_interval = 0)
62
85
  reply = send_cmd("*tm", remocon_id, time.to_i, repeat_interval)
@@ -65,22 +88,33 @@ module IRemoconControl
65
88
 
66
89
  #
67
90
  # タイマー一覧取得用コマンド
91
+ # @return [Array<IRemoconTimer>] タイマー一覧
92
+ # @raise [TelnetConnectionError] 通信エラーが発生した場合
93
+ # @raise [IRemoconError] IRemoconからエラーが帰ってきた場合
68
94
  #
69
95
  def tl
70
96
  reply = send_cmd("*tl")
71
- reply[3..-1].map(&:to_i).each_slice(4).to_a
97
+ reply[3..-1].map(&:to_i).each_slice(4).map {|timer_id, remocon_id, time, repeat_interval|
98
+ IRemoconTimer.new(timer_id, remocon_id, Time.at(time), repeat_interval);
99
+ }
72
100
  end
73
101
 
74
102
  #
75
103
  # タイマー解除用コマンド
104
+ # @param [Integer] timer_id 解除するタイマーID
105
+ # @return [TrueClass] 常にtrue
106
+ # @raise [TelnetConnectionError] 通信エラーが発生した場合
107
+ # @raise [IRemoconError] IRemoconからエラーが帰ってきた場合
76
108
  #
77
109
  def td(timer_id)
78
110
  reply = send_cmd("*td", timer_id)
79
111
  true
80
112
  end
81
-
113
+
82
114
  #
83
115
  # 現在時刻設定用コマンド
116
+ # @param [Integer] time 現在時刻
117
+ # @return [TrueClass] 常にtrue
84
118
  #
85
119
  def ts(time)
86
120
  reply = send_cmd("*ts", time.to_i)
@@ -89,14 +123,20 @@ module IRemoconControl
89
123
 
90
124
  #
91
125
  # 現在時刻取得用コマンド
126
+ # @return [Time] 現在時刻
127
+ # @raise [TelnetConnectionError] 通信エラーが発生した場合
128
+ # @raise [IRemoconError] IRemoconからエラーが帰ってきた場合
92
129
  #
93
130
  def tg
94
131
  reply = send_cmd("*tg")
95
- reply[2].to_i
132
+ Time.at(reply[2].to_i)
96
133
  end
97
134
 
98
135
  #
99
136
  # ファームバージョン番号の取得用コマンド
137
+ # @return [String] バージョン番号
138
+ # @raise [TelnetConnectionError] 通信エラーが発生した場合
139
+ # @raise [IRemoconError] IRemoconからエラーが帰ってきた場合
100
140
  #
101
141
  def vr
102
142
  reply = send_cmd("*vr")
@@ -109,12 +149,12 @@ module IRemoconControl
109
149
  begin
110
150
  reply = _send_cmd(*cmds)
111
151
  rescue => e
112
- @logger.warn "#{cmds} -> #{e}"
152
+ @logger.error "#{cmds} -> #{e}"
113
153
  raise e
114
154
  end
115
155
 
116
- if error? reply
117
- error = get_error reply
156
+ if IRemoconError.error? reply
157
+ error = IRemoconError.get_error reply
118
158
  @logger.warn "#{cmds} -> #{error}"
119
159
  raise error
120
160
  else
@@ -126,29 +166,35 @@ module IRemoconControl
126
166
  def _send_cmd(*cmds)
127
167
  begin
128
168
  telnet = Net::Telnet.new('Host' => @host, 'Port' => @port)
169
+
170
+ code = ""
171
+ telnet.cmd(cmds.join(";")) do |res|
172
+ code << res;
173
+ break if res =~ /\n$/
174
+ end
175
+
176
+ telnet.close
129
177
  rescue
130
- raise StandardError.new("IRemocon Connection Error - #{@host}:#{port}")
178
+ raise TelnetConnectionError.new("IRemocon Connection Error - #{@host}:#{@port}")
131
179
  end
132
-
133
- code = ""
134
- telnet.cmd(cmds.join(";")) do |res|
135
- code << res;
136
- break if res =~ /\n$/
137
- end
138
-
139
- telnet.close
140
180
  return code.chomp.split(";")
141
181
  end
182
+ end
183
+
184
+ class TelnetConnectionError < StandardError; end
185
+
186
+ class IRemoconTimer
187
+ attr_reader :timer_id, :remocon_id, :time, :repeat_interval
142
188
 
143
- def error?(reply)
144
- reply[1] == "err"
189
+ def initialize(timer_id, remocon_id, time, repeat_interval)
190
+ @timer_id, @remocon_id, @time, @repeat_interval = timer_id, remocon_id, Time.at(time), repeat_interval;
145
191
  end
146
192
 
147
- def get_error(reply)
148
- cmd = reply[0]
149
- err_no = reply[2]
150
- return IRemoconError.new cmd, err_no
193
+ def to_s
194
+ "remocon_id : #{@remocon_id}, next : #{@time}, repeat : #{@repeat_interval}"
151
195
  end
196
+
197
+ alias_method :inspect, :to_s
152
198
  end
153
199
  end
154
200
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iremocon_control
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - YutaTanaka
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-05 00:00:00.000000000 Z
11
+ date: 2014-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -75,7 +75,7 @@ files:
75
75
  - lib/iremocon_control/version.rb
76
76
  - spec/iremocon_control_spec.rb
77
77
  - spec/spec_helper.rb
78
- homepage: ''
78
+ homepage: https://github.com/84q/iremocon_control
79
79
  licenses:
80
80
  - MIT
81
81
  metadata: {}
@@ -100,3 +100,4 @@ signing_key:
100
100
  specification_version: 4
101
101
  summary: send commands to iremocon
102
102
  test_files: []
103
+ has_rdoc: