hs1xx 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e0d7ee1d0db3aca6181b42b45c0921fa94684dfc
4
+ data.tar.gz: 70a82d875708d58a5b9a8f2b3ce38bfb0e802ec0
5
+ SHA512:
6
+ metadata.gz: 02c6c165c0e8b79c051cc0dd49fb7db4643a0570a3791f8e94b887851af356d2e19383066f4b524007e87236828c6f5019b23a682def94f9158d2cf4147429a5
7
+ data.tar.gz: 5d16d40b938f896d84e6c8bebaef237abf4689ac82e9c4e39d84eade218faa497904860f03f93d448158468ae4043053c01aff1083549252408c1e4782690c2f
@@ -0,0 +1 @@
1
+ require 'hs1xx/plug'
@@ -0,0 +1,62 @@
1
+ require 'socket'
2
+ require 'base64'
3
+ require 'json'
4
+
5
+ module HS1xx
6
+ class Plug
7
+
8
+ def initialize(ip_address)
9
+ @ip_address = ip_address
10
+ end
11
+
12
+ def on
13
+ send_to_plug(:system => {:set_relay_state => {:state => 1}})
14
+ end
15
+
16
+ def off
17
+ send_to_plug(:system => {:set_relay_state => {:state => 0}})
18
+ end
19
+
20
+ def on?
21
+ status = send_to_plug(:system => {:get_sysinfo => {}})
22
+ status['system']['get_sysinfo']['relay_state'] == 1
23
+ end
24
+
25
+ def off?
26
+ !on?
27
+ end
28
+
29
+ private
30
+
31
+ def send_to_plug(payload)
32
+ payload = payload.to_json
33
+ socket = TCPSocket.new(@ip_address, 9999)
34
+ socket.puts(encrypt(payload))
35
+ decrypt(socket.gets)
36
+ ensure
37
+ socket.close rescue nil
38
+ end
39
+
40
+ def encrypt(payload)
41
+ output = []
42
+ key = 0xAB
43
+ payload.bytes do |b|
44
+ output << (b ^ key)
45
+ key = (b ^ key)
46
+ end
47
+ a = [output.size, *output]
48
+ a.pack('NC*')
49
+ end
50
+
51
+ def decrypt(payload)
52
+ key = 0xAB
53
+ array = []
54
+ payload.bytes[4..-1].each do |b, i|
55
+ array << (b ^ key)
56
+ key = b
57
+ end
58
+ result = array.pack('C*')
59
+ JSON.parse(result)
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,3 @@
1
+ module HS1xx
2
+ VERSION = '1.0.0'
3
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hs1xx
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Adam Cooke
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-11-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Control TP-Link HS100/110 devices
28
+ email:
29
+ - me@adamcooke.io
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - lib/hs1xx.rb
35
+ - lib/hs1xx/plug.rb
36
+ - lib/hs1xx/version.rb
37
+ homepage: https://github.com/adamcooke/hs1xx
38
+ licenses:
39
+ - MIT
40
+ metadata: {}
41
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubyforge_project:
57
+ rubygems_version: 2.5.2
58
+ signing_key:
59
+ specification_version: 4
60
+ summary: This gem provides an easy to use wrapper for controlling TP-Link HS100/110
61
+ Wifi Sockets
62
+ test_files: []