hiveline 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/bin/hiveline +19 -8
- data/lib/hiveline.rb +45 -34
- data/lib/hiveline/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3d9806ec2d28bb69b9618c42c926cbf7d8eb78a
|
4
|
+
data.tar.gz: 9180f209cfbffd935973a68300855ce7c9e717e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c0561b0b060cbab1811037cd96da4802218eeb81df2771ceeb674bb6d723ce4e2c13160b7be92fd64a9a0f87c399337e47ee183482f0acf8e12c0f979df1b46
|
7
|
+
data.tar.gz: 85d58deca29ef22806e3d52292a600d0dc4305c024d934a4f0d2eea1064cde44d74458d96fd369893471363e63d540b2a078a7e8f5006de7d0eb6a496d7f5ea9
|
data/README.md
CHANGED
data/bin/hiveline
CHANGED
@@ -51,9 +51,9 @@ end
|
|
51
51
|
|
52
52
|
def set_temperature(client, temp)
|
53
53
|
print "Setting temperature to #{temp}°C\n"
|
54
|
-
|
55
|
-
|
56
|
-
print "Successfully updated temperature. Set to #{
|
54
|
+
response_success = client.set_temperature(temp)
|
55
|
+
if response_success
|
56
|
+
print "Successfully updated temperature. Set to #{temp}°C\n"
|
57
57
|
else
|
58
58
|
unknown_error
|
59
59
|
end
|
@@ -62,11 +62,11 @@ end
|
|
62
62
|
def lookup_temperature(client)
|
63
63
|
print "Retrieving temperature information\n"
|
64
64
|
environment = client.get_temperature
|
65
|
+
inside = environment["inside"]
|
66
|
+
outside = environment["outside"]
|
65
67
|
unless environment.nil?
|
66
|
-
print "Inside Temperature: #{
|
67
|
-
|
68
|
-
print "Weather in #{environment["city"]}: #{environment['weather'].split('_').map{|e| e.capitalize}.join(" ")} (#{environment["outside"]}°C)\n"
|
69
|
-
end
|
68
|
+
print "Inside Temperature: #{inside["now"]}°C (#{inside["averages"]["today"]}°C todays average)\n"
|
69
|
+
print "Outide Temperature: #{outside["now"]}°C (#{outside["weather"]["description"]})\n"
|
70
70
|
else
|
71
71
|
unknown_error
|
72
72
|
end
|
@@ -92,6 +92,10 @@ def pretty_print_temp(p, max)
|
|
92
92
|
d = DateTime.parse(p["date"])
|
93
93
|
print d.strftime("%H %p ")
|
94
94
|
temp = p["temperature"]
|
95
|
+
if temp.instance_of? String
|
96
|
+
print "\n"
|
97
|
+
return
|
98
|
+
end
|
95
99
|
bar_length = ((temp / max) * max_width).round
|
96
100
|
bar_length.times { print '=' }
|
97
101
|
(max_width - bar_length).times { print ' ' }
|
@@ -101,7 +105,14 @@ end
|
|
101
105
|
|
102
106
|
if options[:history]
|
103
107
|
history = lookup_history client
|
104
|
-
max = history["data"].map
|
108
|
+
max = history["data"].map do |p|
|
109
|
+
temp = p["temperature"]
|
110
|
+
if temp.instance_of? String
|
111
|
+
0
|
112
|
+
else
|
113
|
+
temp
|
114
|
+
end
|
115
|
+
end.max
|
105
116
|
history["data"]
|
106
117
|
.reject { |p| DateTime.parse(p["date"]).strftime("%M") != "00" }
|
107
118
|
.each { |p| pretty_print_temp p, max }
|
data/lib/hiveline.rb
CHANGED
@@ -5,43 +5,45 @@ require 'json'
|
|
5
5
|
module Hiveline
|
6
6
|
class Client
|
7
7
|
include HTTParty
|
8
|
-
attr_accessor :username, :password, :
|
8
|
+
attr_accessor :username, :password, :session_cache
|
9
9
|
|
10
10
|
def initialize(username, password)
|
11
11
|
@username = username
|
12
12
|
@password = password
|
13
13
|
end
|
14
14
|
|
15
|
+
def api_session
|
16
|
+
session[:ApiSession]
|
17
|
+
end
|
18
|
+
|
19
|
+
def hub_ids
|
20
|
+
session[:hubIds]
|
21
|
+
end
|
22
|
+
|
15
23
|
def session
|
16
|
-
@
|
24
|
+
@session_cache ||= get_session
|
17
25
|
end
|
18
26
|
|
19
27
|
def set_temperature(temp)
|
20
|
-
heating_url = "https://
|
21
|
-
id = self.session
|
28
|
+
heating_url = "https://api.hivehome.com/v5/users/#{self.username}/widgets/climate/targetTemperature"
|
22
29
|
response = self.class.put(heating_url, {
|
23
30
|
body: {
|
24
|
-
|
25
|
-
|
31
|
+
temperature: temp,
|
32
|
+
temperatureUnit: "C"
|
26
33
|
},
|
27
34
|
headers: {
|
28
|
-
"Cookie" => "
|
35
|
+
"Cookie" => "ApiSession=#{self.api_session}",
|
29
36
|
},
|
30
37
|
follow_redirects: false
|
31
38
|
})
|
32
|
-
|
33
|
-
if response.code == 200
|
34
|
-
JSON.parse(response.body)["target"]
|
35
|
-
else
|
36
|
-
nil
|
37
|
-
end
|
39
|
+
response.code == 204
|
38
40
|
end
|
39
41
|
|
40
42
|
def get_temperature
|
41
|
-
weather_url = "https://
|
43
|
+
weather_url = "https://api.hivehome.com/v5/users/#{self.username}/widgets/temperature"
|
42
44
|
response = self.class.get(weather_url, {
|
43
45
|
headers: {
|
44
|
-
"Cookie" => "
|
46
|
+
"Cookie" => "ApiSession=#{self.api_session}",
|
45
47
|
"Content-Type" => "application/json"
|
46
48
|
},
|
47
49
|
follow_redirects: false
|
@@ -54,10 +56,14 @@ module Hiveline
|
|
54
56
|
end
|
55
57
|
|
56
58
|
def get_history
|
57
|
-
|
59
|
+
# Just get the first device, ignore others
|
60
|
+
hub_id = hub_ids[0]
|
61
|
+
thermostat = get_thermostat hub_id
|
62
|
+
thermostat_id = thermostat["id"]
|
63
|
+
history_url = "https://api.hivehome.com/v5/users/#{self.username}/widgets/temperature/#{thermostat_id}/history?period=today"
|
58
64
|
response = self.class.get(history_url, {
|
59
65
|
headers: {
|
60
|
-
"Cookie" => "
|
66
|
+
"Cookie" => "ApiSession=#{self.api_session}",
|
61
67
|
"Content-Type" => "application/json"
|
62
68
|
},
|
63
69
|
follow_redirects: false
|
@@ -69,32 +75,37 @@ module Hiveline
|
|
69
75
|
end
|
70
76
|
end
|
71
77
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
78
|
+
def get_devices(hub_id)
|
79
|
+
devices_url = "https://api.hivehome.com/v5/users/#{self.username}/hubs/#{hub_id}/devices"
|
80
|
+
response = self.class.get(devices_url, {
|
81
|
+
headers: {
|
82
|
+
"Cookie" => "ApiSession=#{self.api_session}"
|
83
|
+
},
|
84
|
+
follow_redirects: false
|
85
|
+
})
|
86
|
+
if response.code == 200
|
87
|
+
JSON.parse(response.body)
|
88
|
+
else
|
89
|
+
nil
|
90
|
+
end
|
76
91
|
end
|
77
|
-
|
78
|
-
def
|
79
|
-
|
80
|
-
set_cookie_header = response.headers["set-cookie"]
|
81
|
-
set_cookie_header
|
82
|
-
.split(";")
|
83
|
-
.each(&:strip!)
|
84
|
-
.grep(id_attribute_regex)
|
85
|
-
.first
|
86
|
-
.gsub(id_attribute_regex, "")
|
92
|
+
|
93
|
+
def get_thermostat(hub_id)
|
94
|
+
get_devices(hub_id).select { |device| device["type"] == "HAHVACThermostat" }.pop
|
87
95
|
end
|
88
96
|
|
89
|
-
|
90
|
-
|
91
|
-
|
97
|
+
private
|
98
|
+
|
99
|
+
def get_session
|
100
|
+
login_url = "https://api.hivehome.com/v5/login"
|
101
|
+
response = self.class.post(login_url, {
|
92
102
|
body: {
|
93
103
|
username: @username,
|
94
104
|
password: @password
|
95
105
|
},
|
96
106
|
follow_redirects: false
|
97
107
|
})
|
108
|
+
JSON.parse(response.body, symbolize_names: true)
|
98
109
|
end
|
99
110
|
end
|
100
111
|
end
|
data/lib/hiveline/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hiveline
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Blanchard
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|