atrea_control 1.0.0 → 1.1.0

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: 88aee51ff62bb07d3020bb0a65f13361ae6c36055072da6dc09d80bf4c0b2aff
4
- data.tar.gz: fd32eb80961e9355fc9bb9f9af1a9ed4b49072272b7e5142dbd5f1b17c2d4844
3
+ metadata.gz: 857675ccedb6095d28dced21a663615a053d1d12704da407ea0e6c029bd657eb
4
+ data.tar.gz: e2ed731b15bd2d742e230da0ae1b0b276f3b3d8a47dacac9f920424891507ed8
5
5
  SHA512:
6
- metadata.gz: 03aeeac63edae08f4e6ed4f7a4316846015540d3c4d5439bbb914270c66e1bf897cc399f53eb2d7f2f884c6c176198b28ce4331b37572b0abeb895fa54de5c51
7
- data.tar.gz: b9d55180b76bb447b6030f5b56cb1a617a07363ed9d239dea90264cacd450a18a7382ead94cb43de2c87fa447b02be2a0bceae3960354130ab6287a978142ec6
6
+ metadata.gz: 98f9cbff3552cfc90bf823048d5724b56b0f40877a096bab44181c4890c310bda7c6bb2238376529c730070746455f36a5efe10fd0bf6d75ac62108c280052b9
7
+ data.tar.gz: 7b5737cdd13aae0767a6ed41329ddbb886c6002e2d2bb65b248a35306a582859056d32afd7253fab54ae026a22f487ce700ce095ceb4e0dcaf416d459961759b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,7 @@
1
1
  ## [Unreleased]
2
+ ## [1.1.0] - 2021-10-22
3
+ ### Added
4
+ - to_json
2
5
 
3
6
  ## [1.0.0] - 2021-09-13
4
-
5
7
  - Initial release
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- atrea_control (1.0.0)
4
+ atrea_control (1.1.0)
5
5
  selenium-webdriver (~> 3.142)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -58,7 +58,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
58
58
 
59
59
  ## Contributing
60
60
 
61
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/atrea_control. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/luk4s/atrea_control/blob/master/CODE_OF_CONDUCT.md).
61
+ Bug reports and pull requests are welcome on GitHub at https://github.com/luk4s/atrea_control. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/luk4s/atrea_control/blob/master/CODE_OF_CONDUCT.md).
62
62
 
63
63
  ## Code of Conduct
64
64
 
@@ -8,8 +8,6 @@ module AtreaControl
8
8
  class Duplex
9
9
  CONTROL_URI = "https://control.atrea.eu/"
10
10
 
11
- attr_reader :driver
12
-
13
11
  # @param [String] login
14
12
  # @param [String] password
15
13
  # @param [Hash] sensors_map which box is related to sensor ID
@@ -21,10 +19,14 @@ module AtreaControl
21
19
  @login = login
22
20
  @password = password
23
21
  @sensors = sensors_map
22
+ end
23
+
24
+ def driver
25
+ return @driver if defined?(@driver)
24
26
 
25
27
  options = Selenium::WebDriver::Firefox::Options.new
26
28
  options.headless! unless ENV["NO_HEADLESS"]
27
- @driver = Selenium::WebDriver.for :firefox, options: options
29
+ @driver ||= Selenium::WebDriver.for :firefox, options: options
28
30
  end
29
31
 
30
32
  def logged?
@@ -95,15 +97,30 @@ module AtreaControl
95
97
  element.find_element(css: "div:first-child").text
96
98
  end
97
99
 
98
- def inspect
99
- "<AtreaControl name: '#{name}' outdoor_temperature: #{outdoor_temperature}°C current_power: #{current_power}% current_mode: '#{current_mode}>'"
100
- end
101
-
100
+ # quit selenium browser
102
101
  def close
103
102
  @logged = false
104
103
  driver.quit
105
104
  end
106
105
 
106
+ def as_json(_options = nil)
107
+ {
108
+ logged: logged?,
109
+ current_mode: current_mode,
110
+ current_power: current_power,
111
+ outdoor_temperature: outdoor_temperature,
112
+ }
113
+ end
114
+
115
+ def to_json(*args)
116
+ as_json.to_json(*args)
117
+ end
118
+
119
+ def inspect
120
+ "<AtreaControl name: '#{name}' outdoor_temperature: #{outdoor_temperature}°C current_power: #{current_power}% current_mode: '#{current_mode}'>"
121
+ end
122
+
123
+
107
124
  private
108
125
 
109
126
  def logger
@@ -115,10 +132,10 @@ module AtreaControl
115
132
  end
116
133
 
117
134
  def finish_login
118
- 8.times do |i|
135
+ 13.times do |i|
119
136
  return true if open_dashboard
120
137
  rescue Selenium::WebDriver::Error::NoSuchElementError => _e
121
- t = 5 * (1 + i)
138
+ t = [5 * (1 + i), 25].min
122
139
  logger.debug "waiting #{t}s for login..."
123
140
  sleep t
124
141
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AtreaControl
4
- VERSION = "1.0.0"
4
+ VERSION = "1.1.0"
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.0.0
4
+ version: 1.1.0
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-09-16 00:00:00.000000000 Z
11
+ date: 2021-10-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: selenium-webdriver