kasa 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/kasa/devices.rb +10 -7
- data/lib/kasa/factory.rb +4 -2
- data/lib/kasa/protocol.rb +10 -2
- data/lib/kasa/version.rb +1 -1
- 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: 25195b0def3dbeb1694fbc6ffead20ad21aa32e4d95721f5fdc698549474c96b
|
4
|
+
data.tar.gz: 326a7ccf19efefb2f1edf6dbe25ea644e5062bb600d18424020b90386900444e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a44f2a6b231f50f3ca98ea0d484528cf445ba6d608b0f5211e72ab414e7ed9c9ae421834a4256fd290bbf4572dd52f9c39dbdf5f996126468d1c888614f08bf
|
7
|
+
data.tar.gz: a1c2a2911abb04bfc4f6aa961e5e5d714c5b9963ea258c7d79ff18229e2705b46cfbf706dd11c14947aa4bb00f7d02eebd255b949c9fe492d097f7551b963767
|
data/lib/kasa/devices.rb
CHANGED
@@ -6,12 +6,15 @@ class Kasa
|
|
6
6
|
ON = 1
|
7
7
|
OFF = 0
|
8
8
|
|
9
|
-
attr_reader :ip
|
9
|
+
attr_reader :ip, :alias, :model, :dev_name, :mac
|
10
10
|
|
11
11
|
# initialize
|
12
|
-
def initialize(ip)
|
12
|
+
def initialize(ip, args)
|
13
13
|
@ip = ip
|
14
|
-
@
|
14
|
+
@alias = args['alias']
|
15
|
+
@model = args['model']
|
16
|
+
@dev_name = args['dev_name']
|
17
|
+
@mac = args['mac']
|
15
18
|
end
|
16
19
|
|
17
20
|
# Get system information
|
@@ -70,8 +73,8 @@ class Kasa
|
|
70
73
|
def brightness=(level)
|
71
74
|
Kasa::Protocol.get(
|
72
75
|
@ip,
|
73
|
-
location: '/smartlife.iot.dimmer/set_brightness
|
74
|
-
value: level
|
76
|
+
location: '/smartlife.iot.dimmer/set_brightness',
|
77
|
+
value: { brightness: level }
|
75
78
|
)
|
76
79
|
end
|
77
80
|
end
|
@@ -80,9 +83,9 @@ class Kasa
|
|
80
83
|
class SmartStrip < NonDimmable
|
81
84
|
attr_accessor :children
|
82
85
|
|
83
|
-
def initialize(ip)
|
86
|
+
def initialize(ip, args)
|
84
87
|
super
|
85
|
-
@children =
|
88
|
+
@children = args['children'].map { |c| c['id'] }
|
86
89
|
end
|
87
90
|
|
88
91
|
# Turn on light
|
data/lib/kasa/factory.rb
CHANGED
@@ -11,6 +11,7 @@ class Kasa
|
|
11
11
|
NonDimmable => [
|
12
12
|
'HS200(US)',
|
13
13
|
'HS105(US)',
|
14
|
+
'HS103(US)',
|
14
15
|
'HS210(US)'
|
15
16
|
],
|
16
17
|
SmartStrip => [
|
@@ -24,13 +25,14 @@ class Kasa
|
|
24
25
|
class Factory
|
25
26
|
# Factory
|
26
27
|
def self.new(ip)
|
27
|
-
|
28
|
+
sysinfo = Kasa::Protocol.get(ip, location: '/system/get_sysinfo')
|
29
|
+
model = sysinfo['model']
|
28
30
|
begin
|
29
31
|
object = DEVICE_TYPES.detect { |_k, v| v.include? model }.first.allocate
|
30
32
|
rescue StandardError => _e
|
31
33
|
raise "#{model} not supported"
|
32
34
|
end
|
33
|
-
object.send :initialize, ip
|
35
|
+
object.send :initialize, ip, sysinfo
|
34
36
|
object
|
35
37
|
end
|
36
38
|
end
|
data/lib/kasa/protocol.rb
CHANGED
@@ -19,13 +19,21 @@ class Kasa
|
|
19
19
|
transport(ip, encode(request.to_json))
|
20
20
|
end
|
21
21
|
|
22
|
-
|
22
|
+
response = JSON.parse decode(encoded_response)
|
23
|
+
response = strip_location(location, response)
|
24
|
+
validate response
|
25
|
+
|
26
|
+
response
|
27
|
+
end
|
28
|
+
|
29
|
+
# examine error code
|
30
|
+
def self.validate(response)
|
31
|
+
raise response.to_json if response.is_a?(Hash) && response['err_code']&.negative?
|
23
32
|
end
|
24
33
|
|
25
34
|
# strip away the request location from the response
|
26
35
|
def self.strip_location(location, response)
|
27
36
|
location = location.split('/').reject(&:empty?)
|
28
|
-
response = JSON.parse response
|
29
37
|
location.each do |j|
|
30
38
|
response = (response[j] or response)
|
31
39
|
end
|
data/lib/kasa/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kasa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christopher Jenkins
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-02-
|
11
|
+
date: 2022-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|