dirigera 0.1.0 → 0.1.1
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 +4 -4
- data/LICENSE +21 -0
- data/README.md +48 -0
- data/dirigera.gemspec +16 -0
- data/lib/dirigera/blinds.rb +30 -0
- data/lib/dirigera/client.rb +61 -0
- data/lib/dirigera/device.rb +51 -0
- data/lib/dirigera/light.rb +5 -0
- data/lib/dirigera/on_off_behaviour.rb +23 -0
- data/lib/dirigera/outlet.rb +5 -0
- data/lib/dirigera/version.rb +3 -0
- metadata +11 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 000c4ff5d39d54cdf523b1cb3d2177972061cac28144f791dd8053ddd1d28a5a
|
4
|
+
data.tar.gz: 0accf6d71a935486564c2bacb040625eedf6d81b1ae21b3fe5219d485c64f787
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 266253f0d4a5ca2f5c8f9637c34e75648450359474bc04d4e7b87a453cca13dbf6ed4df9aa8d0d72fb2af88c52d3b83150e3b15065de246093126ab5f3eab358
|
7
|
+
data.tar.gz: 914529e979786f6eeae4091046d880e0e41f53f67a058e6a4d501eda0e70464553f7f37caeb297c01db6c8003960c904d8765b29fcd18949612d016cccb0a191
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2024 phillipp
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# Dirigera Hub API client
|
2
|
+
|
3
|
+
This gem implements an API client for the IKEA Dirigera hub.
|
4
|
+
|
5
|
+
Add it to your Gemfile or install it with gem install
|
6
|
+
|
7
|
+
# Quick start
|
8
|
+
|
9
|
+
Install it via rubygems:
|
10
|
+
|
11
|
+
```
|
12
|
+
gem install example
|
13
|
+
```
|
14
|
+
|
15
|
+
First, you need to get a token. Run the setup.rb from this repository to get it.
|
16
|
+
|
17
|
+
Then you can use the client:
|
18
|
+
|
19
|
+
```
|
20
|
+
require "dirigera"
|
21
|
+
|
22
|
+
client = Dirigera::Client.new(
|
23
|
+
'192.168.x.x',
|
24
|
+
'YOURTOKEN'
|
25
|
+
)
|
26
|
+
|
27
|
+
light = client.lights.last
|
28
|
+
|
29
|
+
light.name = 'Any light'
|
30
|
+
|
31
|
+
light.on
|
32
|
+
sleep 10
|
33
|
+
light.off
|
34
|
+
|
35
|
+
blinds = client.blinds.last
|
36
|
+
|
37
|
+
blinds.up
|
38
|
+
sleep 60
|
39
|
+
blinds.down
|
40
|
+
```
|
41
|
+
|
42
|
+
# TODO
|
43
|
+
|
44
|
+
- Yeah, I know, there is no specs...
|
45
|
+
- Scenes
|
46
|
+
- Link devices
|
47
|
+
- Set power loss behaviour
|
48
|
+
- Implement websocket to receive events
|
data/dirigera.gemspec
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require_relative 'lib/dirigera/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = 'dirigera'
|
5
|
+
s.version = Dirigera::VERSION
|
6
|
+
s.licenses = ['MIT']
|
7
|
+
s.required_ruby_version = '>= 2.7.0'
|
8
|
+
s.summary = "API client for the IKEA Dirigera hub using a local connection"
|
9
|
+
s.authors = ["Phillipp Röll"]
|
10
|
+
s.email = 'phillipp.roell@trafficplex.de'
|
11
|
+
s.files = %w[dirigera.gemspec README.md LICENSE] + `git ls-files | grep -E '^lib'`.split("\n")
|
12
|
+
s.homepage = 'https://rubygems.org/gems/dirigera'
|
13
|
+
s.metadata = { "source_code_uri" => "https://github.com/phillipp/dirigera" }
|
14
|
+
|
15
|
+
s.add_dependency 'httparty'
|
16
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class Dirigera::Blinds < Dirigera::Device
|
2
|
+
def up
|
3
|
+
self.target_level = 0
|
4
|
+
end
|
5
|
+
|
6
|
+
def down
|
7
|
+
self.target_level = 100
|
8
|
+
end
|
9
|
+
|
10
|
+
def state
|
11
|
+
@data['attributes']['blindsState']
|
12
|
+
end
|
13
|
+
|
14
|
+
def current_level
|
15
|
+
@data['attributes']['blindsCurrentLevel']
|
16
|
+
end
|
17
|
+
|
18
|
+
def target_level
|
19
|
+
@data['attributes']['blindsTargetLevel']
|
20
|
+
end
|
21
|
+
|
22
|
+
def target_level=(level)
|
23
|
+
raise ArgumentError, 'level must be between 0 and 100' unless (0..100).include?(level)
|
24
|
+
|
25
|
+
response = @client.patch("/devices/#{id}", [{ attributes: { blindsTargetLevel: level } }])
|
26
|
+
raise 'Failed to update target level' unless response.code == 202
|
27
|
+
|
28
|
+
@data['attributes']['blindsTargetLevel'] = level
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
3
|
+
class Dirigera::Client
|
4
|
+
def initialize(ip, bearer_token)
|
5
|
+
@ip = ip
|
6
|
+
@bearer_token = bearer_token
|
7
|
+
end
|
8
|
+
|
9
|
+
def blinds
|
10
|
+
devices.select { |data| data['type'] == 'blinds' }.map { |data| make_device(data) }
|
11
|
+
end
|
12
|
+
|
13
|
+
def outlets
|
14
|
+
devices.select { |data| data['type'] == 'outlet' }.map { |data| make_device(data) }
|
15
|
+
end
|
16
|
+
|
17
|
+
def lights
|
18
|
+
devices.select { |data| data['type'] == 'light' }.map { |data| make_device(data) }
|
19
|
+
end
|
20
|
+
|
21
|
+
def devices
|
22
|
+
get("/devices")
|
23
|
+
end
|
24
|
+
|
25
|
+
def get(path, params = {})
|
26
|
+
HTTParty.get(
|
27
|
+
"#{base_url}#{path}",
|
28
|
+
query: params,
|
29
|
+
headers: headers,
|
30
|
+
verify: false
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
def patch(path, data)
|
35
|
+
HTTParty.patch(
|
36
|
+
"#{base_url}#{path}",
|
37
|
+
body: data.to_json,
|
38
|
+
headers: headers,
|
39
|
+
verify: false
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def make_device(data)
|
46
|
+
Object.const_get("Dirigera::#{data['deviceType'].capitalize}").new(data, self)
|
47
|
+
rescue NameError
|
48
|
+
Dirigera::Device.new(data, self)
|
49
|
+
end
|
50
|
+
|
51
|
+
def headers
|
52
|
+
{
|
53
|
+
'Authorization': "Bearer #{@bearer_token}",
|
54
|
+
"Content-Type": 'application/json'
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
def base_url
|
59
|
+
"https://#{@ip}:8443/v1"
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
class Dirigera::Device
|
2
|
+
def initialize(data, client)
|
3
|
+
@data = data
|
4
|
+
@client = client
|
5
|
+
end
|
6
|
+
|
7
|
+
attr_reader :client
|
8
|
+
|
9
|
+
def id
|
10
|
+
@data['id']
|
11
|
+
end
|
12
|
+
|
13
|
+
def type
|
14
|
+
@data['type']
|
15
|
+
end
|
16
|
+
|
17
|
+
def name
|
18
|
+
@data['attributes']['customName']
|
19
|
+
end
|
20
|
+
|
21
|
+
def created_at
|
22
|
+
Time.parse(@data['createdAt'])
|
23
|
+
end
|
24
|
+
|
25
|
+
def last_seen_at
|
26
|
+
Time.parse(@data['lastSeen'])
|
27
|
+
end
|
28
|
+
|
29
|
+
def battery_level
|
30
|
+
@data['attributes']['batteryPercentage']
|
31
|
+
end
|
32
|
+
|
33
|
+
def reachable?
|
34
|
+
@data['isReachable']
|
35
|
+
end
|
36
|
+
|
37
|
+
def room
|
38
|
+
@data['room']
|
39
|
+
end
|
40
|
+
|
41
|
+
def name=(new_name)
|
42
|
+
response = @client.patch("/devices/#{id}", [{ attributes: { customName: new_name } }])
|
43
|
+
raise "Failed to update name" unless response.code == 202
|
44
|
+
|
45
|
+
@data['attributes']['customName'] = new_name
|
46
|
+
end
|
47
|
+
|
48
|
+
def reload
|
49
|
+
@data = @client.get("/devices/#{id}")
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Dirigera::OnOffBehaviour
|
2
|
+
def on?
|
3
|
+
@data['attributes']['isOn']
|
4
|
+
end
|
5
|
+
|
6
|
+
def off?
|
7
|
+
!on?
|
8
|
+
end
|
9
|
+
|
10
|
+
def on
|
11
|
+
response = @client.patch("/devices/#{id}", [{ attributes: { isOn: true } }])
|
12
|
+
raise "Failed to update attribute isOn" unless response.code == 202
|
13
|
+
|
14
|
+
@data['attributes']['isOn'] = true
|
15
|
+
end
|
16
|
+
|
17
|
+
def off
|
18
|
+
response = @client.patch("/devices/#{id}", [{ attributes: { isOn: false } }])
|
19
|
+
raise "Failed to update attribute isOn" unless response.code == 202
|
20
|
+
|
21
|
+
@data['attributes']['isOn'] = false
|
22
|
+
end
|
23
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dirigera
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Phillipp Röll
|
@@ -30,7 +30,17 @@ executables: []
|
|
30
30
|
extensions: []
|
31
31
|
extra_rdoc_files: []
|
32
32
|
files:
|
33
|
+
- LICENSE
|
34
|
+
- README.md
|
35
|
+
- dirigera.gemspec
|
33
36
|
- lib/dirigera.rb
|
37
|
+
- lib/dirigera/blinds.rb
|
38
|
+
- lib/dirigera/client.rb
|
39
|
+
- lib/dirigera/device.rb
|
40
|
+
- lib/dirigera/light.rb
|
41
|
+
- lib/dirigera/on_off_behaviour.rb
|
42
|
+
- lib/dirigera/outlet.rb
|
43
|
+
- lib/dirigera/version.rb
|
34
44
|
homepage: https://rubygems.org/gems/dirigera
|
35
45
|
licenses:
|
36
46
|
- MIT
|