hiveline 0.0.3 → 0.0.4
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/README.md +31 -0
- data/bin/hiveline +38 -2
- data/lib/hiveline.rb +16 -0
- data/lib/hiveline/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d4be34e7717f789bb3ca3d4a6dc1a95f07bc51c
|
4
|
+
data.tar.gz: 93a2b5ff4240bbf56d461a654752aabc4be36dec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1156d81bf7996c7a605c858ca7ee4965e506aa067dbcbaffe1227a664cbfd4d73e5894be5d78375735d4ff8b93f0397151367b68c3cde8b6ac2f34f01bbed799
|
7
|
+
data.tar.gz: a6f222d4d97ed8a5e3aa9278d4d23b0a3a4cfdef465047a58b88c354aa4ddb25e2e35bd0843ba02d3501bece4beba427c10726233e4d5c11dcba465513c46f4a
|
data/README.md
CHANGED
@@ -44,4 +44,35 @@ $ hiveline 19 # Set temperature to 19°C
|
|
44
44
|
|
45
45
|
Setting temperature to 19°C
|
46
46
|
Successfully updated temperature. Set to 19°C
|
47
|
+
```
|
48
|
+
|
49
|
+
Get temperature history
|
50
|
+
|
51
|
+
```bash
|
52
|
+
$ hiveline --history
|
53
|
+
|
54
|
+
Retrieving history
|
55
|
+
00 AM ================================== 19.9°C
|
56
|
+
01 AM ================================= 19.4°C
|
57
|
+
02 AM ================================= 19.0°C
|
58
|
+
03 AM ================================ 18.6°C
|
59
|
+
04 AM =============================== 18.3°C
|
60
|
+
05 AM =============================== 18.0°C
|
61
|
+
06 AM ============================== 17.8°C
|
62
|
+
07 AM ================================= 19.1°C
|
63
|
+
08 AM ================================= 19.0°C
|
64
|
+
09 AM ================================= 19.1°C
|
65
|
+
10 AM ================================== 19.8°C
|
66
|
+
11 AM ================================= 19.2°C
|
67
|
+
12 PM ================================ 18.7°C
|
68
|
+
13 PM ================================ 18.5°C
|
69
|
+
14 PM =============================== 18.2°C
|
70
|
+
15 PM ================================= 19.3°C
|
71
|
+
16 PM ================================== 19.9°C
|
72
|
+
17 PM ================================= 19.2°C
|
73
|
+
18 PM ================================= 19.4°C
|
74
|
+
19 PM ================================= 19.2°C
|
75
|
+
20 PM ================================== 20.1°C
|
76
|
+
21 PM ================================== 20.0°C
|
77
|
+
22 PM ================================== 19.9°C
|
47
78
|
```
|
data/bin/hiveline
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
2
|
|
3
|
+
require 'date'
|
3
4
|
require 'optparse'
|
4
5
|
require 'hiveline'
|
5
6
|
|
@@ -15,6 +16,10 @@ OptionParser.new do |opts|
|
|
15
16
|
opts.on("-p", "--password", "Login password") do |password|
|
16
17
|
options[:password] = password
|
17
18
|
end
|
19
|
+
|
20
|
+
opts.on("-h", "--history", "History") do
|
21
|
+
options[:history] = true
|
22
|
+
end
|
18
23
|
end.parse!
|
19
24
|
|
20
25
|
username = options[:username] || ENV["HIVE_USERNAME"]
|
@@ -65,9 +70,40 @@ def lookup_temperature(client)
|
|
65
70
|
end
|
66
71
|
end
|
67
72
|
|
73
|
+
def lookup_history(client)
|
74
|
+
print "Retrieving history\n"
|
75
|
+
history = client.get_history
|
76
|
+
unless history.nil?
|
77
|
+
history
|
78
|
+
else
|
79
|
+
unknown_error
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
68
83
|
if numeric?(command)
|
69
|
-
set_temperature
|
84
|
+
set_temperature client, command
|
85
|
+
exit
|
86
|
+
end
|
87
|
+
|
88
|
+
def pretty_print_temp(p, max)
|
89
|
+
max_width = 35
|
90
|
+
d = DateTime.parse(p["date"])
|
91
|
+
print d.strftime("%H %p ")
|
92
|
+
temp = p["temperature"]
|
93
|
+
bar_length = ((temp / max) * max_width).round
|
94
|
+
bar_length.times { print '=' }
|
95
|
+
(max_width - bar_length).times { print ' ' }
|
96
|
+
print " #{p["temperature"].round(1)}°C"
|
97
|
+
print "\n"
|
98
|
+
end
|
99
|
+
|
100
|
+
if options[:history]
|
101
|
+
history = lookup_history client
|
102
|
+
max = history["data"].map { |p| p["temperature"] }.max
|
103
|
+
history["data"]
|
104
|
+
.reject { |p| DateTime.parse(p["date"]).strftime("%M") != "00" }
|
105
|
+
.each { |p| pretty_print_temp p, max }
|
70
106
|
exit
|
71
107
|
end
|
72
108
|
|
73
|
-
lookup_temperature
|
109
|
+
lookup_temperature client
|
data/lib/hiveline.rb
CHANGED
@@ -53,6 +53,22 @@ module Hiveline
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
+
def get_history
|
57
|
+
history_url = "https://my.hivehome.com/history/today"
|
58
|
+
response = self.class.get(history_url, {
|
59
|
+
headers: {
|
60
|
+
"Cookie" => "hsid=#{self.session}",
|
61
|
+
"Content-Type" => "application/json"
|
62
|
+
},
|
63
|
+
follow_redirects: false
|
64
|
+
})
|
65
|
+
if response.code == 200
|
66
|
+
JSON.parse(response.body)
|
67
|
+
else
|
68
|
+
nil
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
56
72
|
private
|
57
73
|
|
58
74
|
def retrieve_session
|
data/lib/hiveline/version.rb
CHANGED