-
Notifications
You must be signed in to change notification settings - Fork 0
/
nibe_uplink_helper.rb
62 lines (56 loc) · 1.59 KB
/
nibe_uplink_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# frozen_string_literal: true
# A module with helper methods for Nibe Uplink
module NibeUplinkHelper
def self.list_systems(systems)
puts "ID:\tName:"
systems['numItems'].times do |i|
puts "#{systems['objects'][i]['systemId']}\t(#{systems['objects'][i]['name']})"
end
end
def self.extract_set_parameters(array)
parameters = {}
temp_array = array.select { |str| str.include? '=' }
array.reject! { |str| str.include? '=' }
temp_array.each do |str|
a = str.split('=')
parameters[a[0].to_sym] = a[1]
end
parameters
end
def self.get_parameter_values(hash_array, values)
result = {}
if values.size > 1
hash_array.each do |hash|
r = {}
values.each { |value| r[value.to_sym] = hash[value] if hash[value] }
result[hash['parameterId']] = r
end
else
hash_array.each { |hash| result[hash['parameterId']] = hash[values[0]] }
end
result
end
def self.split_parameter_array(parameters)
pages = (parameters.size - 1) / 15 + 1
request_parameters = []
pages.times do |i|
remainder = parameters.size - (i * 15)
request_parameters[i] = parameters.slice(i * 15, remainder < 15 ? remainder : 15)
end
request_parameters
end
def self.get_status_items(json)
hash = JSON.parse(json)
result = {
'Ventilation' => 'OFF',
'Heating Medium Pump' => 'OFF',
'Holiday' => 'OFF',
'Hot Water' => 'OFF',
'Compressor' => 'OFF',
'Addition' => 'OFF',
'Heating' => 'OFF'
}
hash.each { |h| result[h['title']] = 'ON' }
result.to_json
end
end