atrea_control 1.2.0 → 1.2.1

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: ff5e62d3cbb95e39a1b342fa6662636255b8d78b6d76ab54f1e4c3cc12841afc
4
- data.tar.gz: b1aa30c99ff332e261cb3c9e9752bba0eedd16e730bec244c67e91b51b2ab661
3
+ metadata.gz: 3801a6bbd9c137e26eecbf9adcb43d8d1ba7fd7dbcc19be4a95ff1ae5a189a47
4
+ data.tar.gz: efd8adb1f53738b28aac974260c0fca23d46ab3329ec745d2fce6d5bb73c43cf
5
5
  SHA512:
6
- metadata.gz: 881da41972aea45c4e3ea36b2a14ec44d87c9a8d42e6249048780bcfb9066c8c42b35d27770be7f23663a13cc3f0b663b621030adb58f52714851d7d3a833354
7
- data.tar.gz: ee2aaa4913ab06f77ff3fab98661b53085519dffdb1b49786d39e32db80d365618d274e3aef17d12e6041bba9d8d7f030afe5616e5c106c16ccd84062bb88b83
6
+ metadata.gz: a22728dedc9c10022d86dc433d81cacd91193a1851f4302d066763fa8f600c9a632dc02d235f97560d7300f72618ce25c57f83e4581085d049d41c36f7e0b340
7
+ data.tar.gz: e4348ee806d25350c3b2d1f861cec60f8b77504005aabd57115a82966ebb084735f7a8d04a4f79538dbbaa9dff777a34429551d90f302ebdf20dfddc632a09a2
data/.rubocop_todo.yml CHANGED
@@ -1,11 +1,28 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config --auto-gen-only-exclude`
3
- # on 2021-10-26 20:31:23 UTC using RuboCop version 1.22.2.
3
+ # on 2021-10-30 20:32:55 UTC using RuboCop version 1.22.2.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
+ # Offense count: 2
10
+ # Cop supports --auto-correct.
11
+ # Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator.
12
+ # SupportedStylesForExponentOperator: space, no_space
13
+ Layout/SpaceAroundOperators:
14
+ Exclude:
15
+ - '_x.rb'
16
+
17
+ # Offense count: 2
18
+ # Cop supports --auto-correct.
19
+ # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces.
20
+ # SupportedStyles: space, no_space, compact
21
+ # SupportedStylesForEmptyBraces: space, no_space
22
+ Layout/SpaceInsideHashLiteralBraces:
23
+ Exclude:
24
+ - '_x.rb'
25
+
9
26
  # Offense count: 2
10
27
  # Configuration parameters: CountComments, Max, CountAsOne, ExcludedMethods, IgnoredMethods.
11
28
  # IgnoredMethods: refine
@@ -20,13 +37,13 @@ Metrics/ClassLength:
20
37
  Exclude:
21
38
  - 'lib/atrea_control/duplex.rb'
22
39
 
23
- # Offense count: 5
40
+ # Offense count: 4
24
41
  # Configuration parameters: .
25
42
  # SupportedStyles: have_received, receive
26
43
  RSpec/MessageSpies:
27
44
  EnforcedStyle: receive
28
45
 
29
- # Offense count: 2
46
+ # Offense count: 1
30
47
  # Configuration parameters: Max.
31
48
  RSpec/MultipleExpectations:
32
49
  Exclude:
@@ -37,7 +54,7 @@ RSpec/StubbedMock:
37
54
  Exclude:
38
55
  - 'spec/atrea_control/duplex_spec.rb'
39
56
 
40
- # Offense count: 5
57
+ # Offense count: 6
41
58
  RSpec/SubjectStub:
42
59
  Exclude:
43
60
  - 'spec/atrea_control/duplex_spec.rb'
@@ -50,14 +67,23 @@ Style/Documentation:
50
67
  - 'test/**/*'
51
68
  - 'lib/atrea_control.rb'
52
69
 
53
- # Offense count: 1
70
+ # Offense count: 2
54
71
  # Cop supports --auto-correct.
55
72
  # Configuration parameters: EnforcedStyle.
56
73
  # SupportedStyles: always, always_true, never
57
74
  Style/FrozenStringLiteralComment:
58
75
  Exclude:
76
+ - '_x.rb'
59
77
  - 'spec/atrea_control/duplex_spec.rb'
60
78
 
79
+ # Offense count: 2
80
+ # Cop supports --auto-correct.
81
+ # Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
82
+ # SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
83
+ Style/HashSyntax:
84
+ Exclude:
85
+ - '_x.rb'
86
+
61
87
  # Offense count: 1
62
88
  # Cop supports --auto-correct.
63
89
  # Configuration parameters: EnforcedStyle.
data/CHANGELOG.md CHANGED
@@ -1,4 +1,9 @@
1
1
  ## [Unreleased]
2
+ ## [1.2.1] - 2021-10-30
3
+ ### Changed
4
+ - login procedure
5
+ - ensure logged user by window.user object
6
+
2
7
  ## [1.2.0] - 2021-10-26
3
8
  ### Changed
4
9
  - use internal unit.php for read values
data/Gemfile CHANGED
@@ -5,6 +5,7 @@ source "https://rubygems.org"
5
5
  # Specify your gem's dependencies in atrea_control.gemspec
6
6
  gemspec
7
7
 
8
+ gem "pry"
8
9
  gem "rake", "~> 13.0"
9
10
  gem "rspec", "~> 3.10"
10
11
  gem "rubocop", "~> 1.7", require: false
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- atrea_control (1.2.0)
4
+ atrea_control (1.2.1)
5
5
  nokogiri (~> 1.12)
6
6
  rest-client (~> 2.1)
7
7
  selenium-webdriver (~> 3.142)
@@ -13,6 +13,7 @@ GEM
13
13
  public_suffix (>= 2.0.2, < 5.0)
14
14
  ast (2.4.2)
15
15
  childprocess (3.0.0)
16
+ coderay (1.1.3)
16
17
  crack (0.4.5)
17
18
  rexml
18
19
  diff-lcs (1.4.4)
@@ -23,17 +24,19 @@ GEM
23
24
  http-accept (1.7.0)
24
25
  http-cookie (1.0.4)
25
26
  domain_name (~> 0.5)
27
+ method_source (1.0.0)
26
28
  mime-types (3.3.1)
27
29
  mime-types-data (~> 3.2015)
28
30
  mime-types-data (3.2021.0901)
29
31
  netrc (0.11.0)
30
32
  nokogiri (1.12.5-x86_64-darwin)
31
33
  racc (~> 1.4)
32
- nokogiri (1.12.5-x86_64-linux)
33
- racc (~> 1.4)
34
34
  parallel (1.21.0)
35
35
  parser (3.0.2.0)
36
36
  ast (~> 2.4.1)
37
+ pry (0.14.1)
38
+ coderay (~> 1.1)
39
+ method_source (~> 1.0)
37
40
  public_suffix (4.0.6)
38
41
  racc (1.6.0)
39
42
  rainbow (3.0.0)
@@ -97,6 +100,7 @@ PLATFORMS
97
100
 
98
101
  DEPENDENCIES
99
102
  atrea_control!
103
+ pry
100
104
  rake (~> 13.0)
101
105
  rspec (~> 3.10)
102
106
  rubocop (~> 1.7)
@@ -21,7 +21,6 @@ module AtreaControl
21
21
  # @option sensors_map [String] :current_power
22
22
  # @option sensors_map [String] :current_mode
23
23
  def initialize(login:, password:, sensors_map: Config.default_sensors_map)
24
- @logged = false
25
24
  @login = login
26
25
  @password = password
27
26
  @sensors = sensors_map
@@ -37,12 +36,26 @@ module AtreaControl
37
36
  end
38
37
 
39
38
  def logged?
40
- @logged
39
+ user&.[] "loged"
40
+ end
41
+
42
+ def login_in_progress?
43
+ @login_in_progress
41
44
  end
42
45
 
43
46
  # Login into control
44
47
  def login
48
+ @login_in_progress = true
49
+ logger.debug "start new login"
45
50
  driver.get CONTROL_URI
51
+ submit_login_form if user.nil? || !logged?
52
+ finish_login
53
+ @login_in_progress = false
54
+ inspect
55
+ end
56
+
57
+ # Submit given credentials and proceed login
58
+ def submit_login_form
46
59
  form = driver.find_element(id: "loginFrm")
47
60
  username = form.find_element(name: "username")
48
61
  username.send_keys @login
@@ -51,7 +64,6 @@ module AtreaControl
51
64
 
52
65
  submit = form.find_element(css: "input[type=submit]")
53
66
  submit.click
54
- finish_login && inspect
55
67
  end
56
68
 
57
69
  # Retrieve dashboard URI from object tag and open it again
@@ -59,7 +71,6 @@ module AtreaControl
59
71
  uri = driver.find_element(tag_name: "object").attribute "data"
60
72
  driver.get uri
61
73
  logger.debug "#{name} login success"
62
- @logged = true
63
74
  end
64
75
 
65
76
  # @return [String]
@@ -80,9 +91,10 @@ module AtreaControl
80
91
  @unit_id ||= driver.execute_script("return window._unit")
81
92
  end
82
93
 
83
- # @return [String]
84
- def user_auth
85
- @user_auth ||= driver.execute_script("return window.user")&.[] "auth"
94
+ # Window.user object from atrea
95
+ # @return [Hash, nil]
96
+ def user
97
+ driver.execute_script("return window.user")
86
98
  end
87
99
 
88
100
  # @return [String]
@@ -95,7 +107,6 @@ module AtreaControl
95
107
 
96
108
  # quit selenium browser
97
109
  def close
98
- @logged = false
99
110
  @user_auth = nil
100
111
  driver.quit
101
112
  remove_instance_variable :@driver
@@ -124,12 +135,14 @@ module AtreaControl
124
135
  end
125
136
 
126
137
  def call_unit!
127
- return false unless user_auth
138
+ return false if @login_in_progress
128
139
 
140
+ logger.debug "call_unit!"
129
141
  parse_response(response_comm_unit)
130
142
  @valid_for = Time.now
131
143
  as_json
132
144
  rescue RestClient::Forbidden
145
+ logger.debug "session expired..."
133
146
  close if @logged
134
147
  login && call_unit!
135
148
  end
@@ -183,7 +196,7 @@ module AtreaControl
183
196
  params = {
184
197
  _user: user_id,
185
198
  _unit: unit_id,
186
- auth: user_auth,
199
+ auth: user&.[]("auth"),
187
200
  _t: "config/xml.xml",
188
201
  }
189
202
  autologin_token = CGI.escape([@login, @password].join("\b"))
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AtreaControl
4
- VERSION = "1.2.0"
4
+ VERSION = "1.2.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: atrea_control
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lukáš Pokorný
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-10-27 00:00:00.000000000 Z
11
+ date: 2021-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri