senec 0.7.2 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/senec/request.rb +14 -6
- data/lib/senec/state.rb +5 -4
- data/lib/senec/value.rb +1 -1
- data/lib/senec/version.rb +1 -1
- data/lib/senec.rb +1 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1742fde56f587e423ac2c22d38d8cfee11fc324faa7b026af09c1419e2a93841
|
4
|
+
data.tar.gz: e5d4184d3d24741d76baedecf0a565fe7aad6685f6c3c2f8f745ce22a75a38b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3d1f2a65475ae606ab0c6f4f13eed3363d9cd2c8bd0e7f57cc4fe730492410295860800b1e1027e18bbd2ad5abc7b01012ec6c7fe7286c304b58e025a8cd110
|
7
|
+
data.tar.gz: 3dea00f3618c57301a9509cc5de3b0e14df42f9a4cefff6a82a047a73073602cbe9fc2ce2b5f0438c8f1539e1cb5784fe526198373990a8a2f271ef0e232acb9
|
data/lib/senec/request.rb
CHANGED
@@ -4,11 +4,14 @@ require 'senec/constants'
|
|
4
4
|
|
5
5
|
module Senec
|
6
6
|
class Request
|
7
|
-
def initialize(host:, state_names: nil)
|
7
|
+
def initialize(host:, schema: 'http', state_names: nil)
|
8
8
|
@host = host
|
9
|
+
@schema = schema
|
9
10
|
@state_names = state_names
|
10
11
|
end
|
11
12
|
|
13
|
+
attr_reader :host, :schema, :state_names
|
14
|
+
|
12
15
|
def house_power
|
13
16
|
get('ENERGY', 'GUI_HOUSE_POW')
|
14
17
|
end
|
@@ -54,9 +57,9 @@ module Senec
|
|
54
57
|
end
|
55
58
|
|
56
59
|
def current_state_name
|
57
|
-
throw RuntimeError, 'No state names provided!' unless
|
60
|
+
throw RuntimeError, 'No state names provided!' unless state_names
|
58
61
|
|
59
|
-
|
62
|
+
state_names[current_state]
|
60
63
|
end
|
61
64
|
|
62
65
|
def measure_time
|
@@ -72,9 +75,13 @@ module Senec
|
|
72
75
|
value.map do |v|
|
73
76
|
Senec::Value.new(v).decoded
|
74
77
|
end
|
75
|
-
|
78
|
+
elsif value
|
76
79
|
Senec::Value.new(value).decoded
|
80
|
+
else
|
81
|
+
raise Senec::Error, "Value missing for #{keys.join('.')}"
|
77
82
|
end
|
83
|
+
rescue DecodingError => e
|
84
|
+
raise Senec::Error, "Decoding failed for #{keys.join('.')}: #{e.message}"
|
78
85
|
end
|
79
86
|
|
80
87
|
def response
|
@@ -84,7 +91,8 @@ module Senec
|
|
84
91
|
body: JSON.generate(Senec::BASIC_REQUEST),
|
85
92
|
headers: {
|
86
93
|
'Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8'
|
87
|
-
}
|
94
|
+
},
|
95
|
+
verify: false
|
88
96
|
)
|
89
97
|
raise Senec::Error, res.message.to_s unless res.success?
|
90
98
|
|
@@ -93,7 +101,7 @@ module Senec
|
|
93
101
|
end
|
94
102
|
|
95
103
|
def url
|
96
|
-
"
|
104
|
+
"#{schema}://#{host}/lala.cgi"
|
97
105
|
end
|
98
106
|
end
|
99
107
|
end
|
data/lib/senec/state.rb
CHANGED
@@ -2,11 +2,12 @@ require 'httparty'
|
|
2
2
|
|
3
3
|
module Senec
|
4
4
|
class State
|
5
|
-
def initialize(host:)
|
5
|
+
def initialize(host:, schema: 'http')
|
6
6
|
@host = host
|
7
|
+
@schema = schema
|
7
8
|
end
|
8
9
|
|
9
|
-
attr_reader :host
|
10
|
+
attr_reader :host, :schema
|
10
11
|
|
11
12
|
# Extract state names from JavaScript file, which is formatted like this:
|
12
13
|
#
|
@@ -31,7 +32,7 @@ module Senec
|
|
31
32
|
|
32
33
|
def response
|
33
34
|
@response ||= begin
|
34
|
-
res = HTTParty.get url
|
35
|
+
res = HTTParty.get url, verify: false
|
35
36
|
raise Senec::Error, res.message unless res.success?
|
36
37
|
|
37
38
|
res.body
|
@@ -40,7 +41,7 @@ module Senec
|
|
40
41
|
|
41
42
|
# Use the JavaScript file with German names from the SENEC web interface
|
42
43
|
def url
|
43
|
-
"
|
44
|
+
"#{schema}://#{host}/js/DE-de.js"
|
44
45
|
end
|
45
46
|
end
|
46
47
|
end
|
data/lib/senec/value.rb
CHANGED
data/lib/senec/version.rb
CHANGED
data/lib/senec.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: senec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Georg Ledermann
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -73,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '0'
|
75
75
|
requirements: []
|
76
|
-
rubygems_version: 3.4.
|
76
|
+
rubygems_version: 3.4.18
|
77
77
|
signing_key:
|
78
78
|
specification_version: 4
|
79
79
|
summary: Unofficial Ruby Client for SENEC Home
|