tp_link_smartplug 0.1.0.alpha1 → 0.1.0.alpha2
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 +4 -4
- data/lib/tp_link_smartplug/device.rb +10 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6bed1e62fae7e4947c064c2157b91f7a243ae7bc3ead0d98401206c9a5542170
|
4
|
+
data.tar.gz: 8635ee04999de8cc49825bcd44ae59c63cde489954649b8a99bb4a3c3fa8b8c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54396217a8ae3f902f7f950659729d4af468ef2c4176254cfbe3dfe95fd19ff8e40d452b2f6d58e54a3afb57c07096768b8b0d85c93eb1b7efeabacbb664da7f
|
7
|
+
data.tar.gz: ea6c85622bbeedd77d260e259820183bfa95efe5179e745adb8462336120ad3caa239651a5a0442450537151123f6aa80da195f751153af22d7aa799f941f7f1
|
@@ -21,6 +21,7 @@ module TpLinkSmartplug
|
|
21
21
|
attr_accessor :address
|
22
22
|
attr_accessor :port
|
23
23
|
attr_accessor :timeout
|
24
|
+
attr_accessor :poll_auto_close
|
24
25
|
attr_accessor :debug
|
25
26
|
|
26
27
|
def initialize(address:, port: 9999)
|
@@ -30,6 +31,7 @@ module TpLinkSmartplug
|
|
30
31
|
@debug = false
|
31
32
|
@sockaddr = Addrinfo.getaddrinfo(address.to_s, port, Socket::PF_INET, :STREAM, 6).first.to_sockaddr
|
32
33
|
@socket = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM)
|
34
|
+
@poll_auto_close = true
|
33
35
|
end
|
34
36
|
|
35
37
|
# Open connection to plug
|
@@ -68,21 +70,21 @@ module TpLinkSmartplug
|
|
68
70
|
@socket.close unless @socket.closed?
|
69
71
|
end
|
70
72
|
|
71
|
-
# Return connection state
|
73
|
+
# Return connection state open
|
72
74
|
#
|
73
75
|
# @return [True, False]
|
74
76
|
def open?
|
75
77
|
!@socket.closed?
|
76
78
|
end
|
77
79
|
|
78
|
-
# Return connection state
|
80
|
+
# Return connection state closed
|
79
81
|
#
|
80
82
|
# @return [True, False]
|
81
83
|
def closed?
|
82
84
|
@socket.closed?
|
83
85
|
end
|
84
86
|
|
85
|
-
# Polls
|
87
|
+
# Polls plug with a command
|
86
88
|
#
|
87
89
|
# @param command [String] the command to send to the plug
|
88
90
|
# @return [Hash] the output from the plug command
|
@@ -102,11 +104,13 @@ module TpLinkSmartplug
|
|
102
104
|
rescue IO::WaitReadable
|
103
105
|
IO.select([@socket])
|
104
106
|
retry
|
105
|
-
ensure
|
106
|
-
disconnect unless closed?
|
107
107
|
end
|
108
108
|
|
109
|
-
|
109
|
+
if @poll_auto_close && !closed?
|
110
|
+
disconnect
|
111
|
+
raise 'Error occured during disconnect' unless closed?
|
112
|
+
end
|
113
|
+
|
110
114
|
raise 'No data received' if data.nil? || data.empty?
|
111
115
|
|
112
116
|
debug_message("Received Raw: #{data}") if debug
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tp_link_smartplug
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0.
|
4
|
+
version: 0.1.0.alpha2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Hughes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-06-
|
11
|
+
date: 2019-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Control and retrieve data from a TP-Link HS100/110 (Metered) Smartplug
|
14
14
|
email: bmhughes@bmhughes.co.uk
|