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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 23a1848523acc948dd653d39fa3b9cec937bdba9d2a0ad6970308bac4af64d8d
4
- data.tar.gz: dd4d4a0fda92aeabfdc7adfb5f751f1b957438b168e5c96efaf4950d69e1bb3d
3
+ metadata.gz: 6bed1e62fae7e4947c064c2157b91f7a243ae7bc3ead0d98401206c9a5542170
4
+ data.tar.gz: 8635ee04999de8cc49825bcd44ae59c63cde489954649b8a99bb4a3c3fa8b8c6
5
5
  SHA512:
6
- metadata.gz: e2259524ac344b200b19d4824178dfe18b5b7d92c8fbead1b3a4c40f3c073a3078b529f73bf035c4e1505f9827c9323f2f5c8e98f8076270783ed701d1ce6058
7
- data.tar.gz: 24ae9be641e069804c884abd18594ee8a2c355370033c06c36091dff990c0846325cc9878c1e08550658e88fabebe42e98ce60b0edf82cc57f71006b0b5d1753
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 a plug with a command
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
- raise 'Error occured during disconnect' unless closed?
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.alpha1
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-08 00:00:00.000000000 Z
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