Skip to content

Commit

Permalink
raise exception if session expired
Browse files Browse the repository at this point in the history
  • Loading branch information
luk4s committed Jan 23, 2025
1 parent 9841516 commit 560548b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 35 deletions.
46 changes: 12 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# atrea_control
Ventilation systems by https://www.atrea.eu are build with web UI portal - but this portal did not provide any API interface...

This gem provide simple DSL by parsing content of https://control.atrea.eu with selenium webdriver.
This gem provide way how to connect to portal and obtain data from unit as API.

## Highlights

Expand All @@ -19,16 +19,24 @@ This gem provide simple DSL by parsing content of https://control.atrea.eu with
Add this line to your application's Gemfile:

```ruby
gem 'atrea_control'
gem "atrea_control"
```

And then execute:
```bash
bundle install
```

$ bundle install
Or
```bash
bundle add atrea_control
```

Or install it yourself as:

$ gem install atrea_control
```bash
gem install atrea_control
```

## Usage

Expand Down Expand Up @@ -56,36 +64,6 @@ control.power # => 88.0

__Please check [lib/atrea_control/duplex/user_ctrl.rb](./lib/atrea_control/duplex/user_ctrl.rb) for more details !__

## Development / TODO
Login is currently done by selenium - fill login form.
I found that Atrea submit form to BE, generate some "empty" HTML and JS which onLoad start doing request to queue for "login".

Re-login user, add login procedure into queue:
```bash
curl -X POST -d "comm=config%2Flogin.cgi" "https://control.atrea.eu/apps/rd5Control/handle.php?action=unitLogin&user=XXXX&unit=NNNNNNN&table=userUnits&idPwd=YYYYYYY&NFP"
```
Response is time in seconds when login will ready:
```xml
<root><sended time="264"/></root>
```
Based it su shown countdown ...


Request for current queue status
```bash
curl 'https://control.atrea.eu/apps/rd5Control/handle.php?Sync=1&action=unitQuery&query=loged&user=XXXX&unit=NNNNNNN'
```
if queue is processed:
```xml
<root><login uconn="16395889" sid="010101" ver="3001009"/></root>
```
else
```xml
<root><login uconn="16390480" sid="0"/></root>
```

Goal is to obtain "SID".

After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
Expand Down
7 changes: 6 additions & 1 deletion lib/atrea_control.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@

module AtreaControl
class Error < StandardError; end
class Expired < Error; end

class SessionExpired < Error
def message
"Session expired. Please perform login again."
end
end

autoload :Duplex, "atrea_control/duplex"
autoload :Logger, "atrea_control/logger"
Expand Down
2 changes: 2 additions & 0 deletions lib/atrea_control/duplex/unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ def values
parsed.each do |name, value|
instance_variable_set :"@#{name}", value
end
raise AtreaControl::SessionExpired unless valid?

as_json
end

Expand Down
5 changes: 5 additions & 0 deletions spec/atrea_control/duplex/unit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

before do
allow(unit).to receive(:request).and_return(request)
allow(unit).to receive(:valid?).and_return(true)
end

describe "#name" do
Expand Down Expand Up @@ -102,6 +103,10 @@
describe "#valid?" do
subject(:valid?) { unit.valid? }

before do
allow(unit).to receive(:valid?).and_call_original
end

context "when timestamp is nil" do
before { allow(unit).to receive(:timestamp).and_return nil }

Expand Down

0 comments on commit 560548b

Please sign in to comment.