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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eabf3cf6c200b6e167e68ba309a8a0365f1ad3c388bc6e6797460606ba81d13e
4
- data.tar.gz: e7d1742ca594b43bb8a1636e3faea98784a468efc1a4fc86b96052a9b613f26b
3
+ metadata.gz: 1742fde56f587e423ac2c22d38d8cfee11fc324faa7b026af09c1419e2a93841
4
+ data.tar.gz: e5d4184d3d24741d76baedecf0a565fe7aad6685f6c3c2f8f745ce22a75a38b2
5
5
  SHA512:
6
- metadata.gz: 9a7ac30d46616071e3d0a6d57151ff21f3c2a219e347aceda27423f82fefa9c5b7dddbcdcbeff840573f4b35c82fff575e2d3bbbc3caa526822b147a82b705b5
7
- data.tar.gz: 511506136b9baf3839e92aa9ca66fb7a9354e7a924c6290e0a24ba9ce47d2d64d1f501bcc8caba0f58def09d620b57f9021781ce06f3bff5d76094a17cdeb150
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 @state_names
60
+ throw RuntimeError, 'No state names provided!' unless state_names
58
61
 
59
- @state_names[current_state]
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
- else
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
- "http://#{@host}/lala.cgi"
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
- "http://#{host}/js/DE-de.js"
44
+ "#{schema}://#{host}/js/DE-de.js"
44
45
  end
45
46
  end
46
47
  end
data/lib/senec/value.rb CHANGED
@@ -18,7 +18,7 @@ module Senec
18
18
  value
19
19
  # TODO: There are some more prefixes to handle
20
20
  else
21
- raise ArgumentError, "#{@data} has unknown prefix!"
21
+ raise Senec::DecodingError, "Unknown value '#{@data}'"
22
22
  end
23
23
  end
24
24
 
data/lib/senec/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Senec
2
- VERSION = '0.7.2'.freeze
2
+ VERSION = '0.8.0'.freeze
3
3
  end
data/lib/senec.rb CHANGED
@@ -4,4 +4,5 @@ require 'senec/request'
4
4
 
5
5
  module Senec
6
6
  class Error < StandardError; end
7
+ class DecodingError < StandardError; end
7
8
  end
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.7.2
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-04-23 00:00:00.000000000 Z
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.12
76
+ rubygems_version: 3.4.18
77
77
  signing_key:
78
78
  specification_version: 4
79
79
  summary: Unofficial Ruby Client for SENEC Home