inels 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/inels.rb +3 -0
- data/lib/inels/client.rb +33 -0
- data/lib/inels/controller.rb +64 -0
- data/lib/inels/multi_client.rb +19 -0
- data/lib/inels/templates/schedule.erb +107 -0
- metadata +62 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4e4a9be095323243c6ffbf08d2c305dd34da30eb
|
4
|
+
data.tar.gz: 78a7a88c2cc7779cd5c1a2201be40d46195a74b6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5529712db8a6ac06592e4d824e8eb4b78729e181ad7e4720a71f813d6407dff2a001d080dc55d1ef35559848bd9349bdd13303e9e76a6d0cbf55cbaab6831648
|
7
|
+
data.tar.gz: 0affe0c0ab3462747332b09b22cabf130b94790b8873fdbb146e10f794e50e7b3edfb13c63b8434aaae79ef0ce874dbcace2403c45637efa54962aa540c80127
|
data/lib/inels.rb
ADDED
data/lib/inels/client.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Inels
|
5
|
+
class Client
|
6
|
+
def initialize ip
|
7
|
+
@ip = ip
|
8
|
+
end
|
9
|
+
|
10
|
+
attr_reader :ip
|
11
|
+
|
12
|
+
def api_get path
|
13
|
+
response = RestClient.get "http://#{@ip}/api/#{path}"
|
14
|
+
JSON.parse(response.body)
|
15
|
+
end
|
16
|
+
|
17
|
+
def api_post path, payload
|
18
|
+
response = RestClient.post "http://#{@ip}/api/#{path}", payload, {content_type: :json, accept: :json}
|
19
|
+
response.body
|
20
|
+
end
|
21
|
+
|
22
|
+
def api_delete path
|
23
|
+
response = RestClient.delete "http://#{@ip}/api/#{path}"
|
24
|
+
response.body
|
25
|
+
end
|
26
|
+
|
27
|
+
def api_put path, payload
|
28
|
+
response = RestClient.put "http://#{@ip}/api/#{path}", payload, {content_type: :json, accept: :json}
|
29
|
+
response.body
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require_relative 'multi_client'
|
3
|
+
|
4
|
+
module Inels
|
5
|
+
class Controller
|
6
|
+
def initialize ips
|
7
|
+
@multi_client = MultiClient.new(ips)
|
8
|
+
@schedule = ERB.new(File.read(File.join(File.dirname(__FILE__), 'templates/schedule.erb')))
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_reader :multi_client
|
12
|
+
attr_reader :schedule
|
13
|
+
|
14
|
+
def list_devices
|
15
|
+
room_states = multi_client.clients.map do |client|
|
16
|
+
rooms = client.api_get('rooms')
|
17
|
+
rooms.keys.map do |room_id|
|
18
|
+
room = client.api_get("rooms/#{room_id}")
|
19
|
+
devices = room['devices'].keys.map do |device_id|
|
20
|
+
device = client.api_get("devices/#{device_id}")
|
21
|
+
case device['device info']['product type']
|
22
|
+
when 'HeatCoolArea'
|
23
|
+
device['room_name'] = room['room info']['label']
|
24
|
+
device['ip'] = client.ip
|
25
|
+
{
|
26
|
+
id: device['id'],
|
27
|
+
name: device['device info']['label'],
|
28
|
+
product_type: device['device info']['product type'],
|
29
|
+
room_name: room['room info']['label'],
|
30
|
+
ip: client.ip
|
31
|
+
}
|
32
|
+
else
|
33
|
+
nil
|
34
|
+
end
|
35
|
+
end.compact
|
36
|
+
end
|
37
|
+
end.flatten
|
38
|
+
end
|
39
|
+
|
40
|
+
def get_device id, client: nil, verbose: false
|
41
|
+
client ||= multi_client.client_for_id('devices', id)
|
42
|
+
device_state = client.api_get("devices/#{id}/state")
|
43
|
+
if verbose
|
44
|
+
device = client.api_get("devices/#{id}")
|
45
|
+
|
46
|
+
device_state['valves'] = device['heating devices'].map do |valve|
|
47
|
+
client.api_get("devices/#{valve['id']}/state")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
device_state
|
51
|
+
end
|
52
|
+
|
53
|
+
def set_temperature id, temperature, client: nil
|
54
|
+
client ||= multi_client.client_for_id('devices', id)
|
55
|
+
schedule_id = client.api_get("devices/#{id}")['schedule']
|
56
|
+
client.api_post('temperature/schedules', schedule.result(binding))
|
57
|
+
end
|
58
|
+
|
59
|
+
def set_power id, power, client: nil
|
60
|
+
client ||= multi_client.client_for_id('devices', id)
|
61
|
+
client.api_put("devices/#{id}", {power: power}.to_json)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative 'client'
|
2
|
+
|
3
|
+
module Inels
|
4
|
+
class MultiClient
|
5
|
+
def initialize ips
|
6
|
+
@clients = ips.map{ |ip| Client.new(ip)}
|
7
|
+
end
|
8
|
+
|
9
|
+
attr_reader :clients
|
10
|
+
|
11
|
+
def client_for_id path, id
|
12
|
+
clients.each do |client|
|
13
|
+
hash = client.api_get(path)
|
14
|
+
return client if hash.keys.include?(id)
|
15
|
+
end
|
16
|
+
raise RestClient::NotFound
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
{
|
2
|
+
"id": "<%= schedule_id %>",
|
3
|
+
"hysteresis": 0.1,
|
4
|
+
"label": "<%= schedule_id %>",
|
5
|
+
"modes": {
|
6
|
+
"1": {
|
7
|
+
"min": <%= temperature %>,
|
8
|
+
"max": 35
|
9
|
+
},
|
10
|
+
"2": {
|
11
|
+
"min": 20,
|
12
|
+
"max": 35
|
13
|
+
},
|
14
|
+
"3": {
|
15
|
+
"min": 20,
|
16
|
+
"max": 35
|
17
|
+
},
|
18
|
+
"4": {
|
19
|
+
"min": 28,
|
20
|
+
"max": 35
|
21
|
+
}
|
22
|
+
},
|
23
|
+
"schedule": {
|
24
|
+
"monday": [
|
25
|
+
{
|
26
|
+
"duration": 480,
|
27
|
+
"mode": 2
|
28
|
+
},
|
29
|
+
{
|
30
|
+
"duration": 720,
|
31
|
+
"mode": 1
|
32
|
+
},
|
33
|
+
{
|
34
|
+
"duration": 240,
|
35
|
+
"mode": 2
|
36
|
+
}
|
37
|
+
],
|
38
|
+
"tuesday": [
|
39
|
+
{
|
40
|
+
"duration": 480,
|
41
|
+
"mode": 2
|
42
|
+
},
|
43
|
+
{
|
44
|
+
"duration": 720,
|
45
|
+
"mode": 1
|
46
|
+
},
|
47
|
+
{
|
48
|
+
"duration": 240,
|
49
|
+
"mode": 2
|
50
|
+
}
|
51
|
+
],
|
52
|
+
"wednesday": [
|
53
|
+
{
|
54
|
+
"duration": 480,
|
55
|
+
"mode": 2
|
56
|
+
},
|
57
|
+
{
|
58
|
+
"duration": 720,
|
59
|
+
"mode": 1
|
60
|
+
},
|
61
|
+
{
|
62
|
+
"duration": 240,
|
63
|
+
"mode": 2
|
64
|
+
}
|
65
|
+
],
|
66
|
+
"thursday": [
|
67
|
+
{
|
68
|
+
"duration": 480,
|
69
|
+
"mode": 2
|
70
|
+
},
|
71
|
+
{
|
72
|
+
"duration": 720,
|
73
|
+
"mode": 1
|
74
|
+
},
|
75
|
+
{
|
76
|
+
"duration": 240,
|
77
|
+
"mode": 2
|
78
|
+
}
|
79
|
+
],
|
80
|
+
"friday": [
|
81
|
+
{
|
82
|
+
"duration": 480,
|
83
|
+
"mode": 2
|
84
|
+
},
|
85
|
+
{
|
86
|
+
"duration": 720,
|
87
|
+
"mode": 1
|
88
|
+
},
|
89
|
+
{
|
90
|
+
"duration": 240,
|
91
|
+
"mode": 2
|
92
|
+
}
|
93
|
+
],
|
94
|
+
"saturday": [
|
95
|
+
{
|
96
|
+
"duration": 1440,
|
97
|
+
"mode": 2
|
98
|
+
}
|
99
|
+
],
|
100
|
+
"sunday": [
|
101
|
+
{
|
102
|
+
"duration": 1440,
|
103
|
+
"mode": 2
|
104
|
+
}
|
105
|
+
]
|
106
|
+
}
|
107
|
+
}
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: inels
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Zsolt Prontvai
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-12-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Client library for the Inels eLAN-RF-003 home automation system
|
28
|
+
email:
|
29
|
+
- prozsolt@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- lib/inels.rb
|
35
|
+
- lib/inels/client.rb
|
36
|
+
- lib/inels/controller.rb
|
37
|
+
- lib/inels/multi_client.rb
|
38
|
+
- lib/inels/templates/schedule.erb
|
39
|
+
homepage: https://github.com/ProZsolt/inels
|
40
|
+
licenses: []
|
41
|
+
metadata: {}
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
requirements: []
|
57
|
+
rubyforge_project:
|
58
|
+
rubygems_version: 2.6.11
|
59
|
+
signing_key:
|
60
|
+
specification_version: 4
|
61
|
+
summary: Inels client library
|
62
|
+
test_files: []
|