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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c059e7ee5eddcd56423655cf5845b6bcc27c02a5
4
- data.tar.gz: 325dbd20157ab085de429d24fe17ef49abca0db8
3
+ metadata.gz: 7d4be34e7717f789bb3ca3d4a6dc1a95f07bc51c
4
+ data.tar.gz: 93a2b5ff4240bbf56d461a654752aabc4be36dec
5
5
  SHA512:
6
- metadata.gz: a7feb248a4d80217044dc2aaa86ff6e2fa817807b71dae85a48549f6f736f7a75eabaa96f5019cab4c98fddb7417a907d42be4c1d13234f19ff99b78f5e7ee15
7
- data.tar.gz: 58bca2c3519cf2ead934391615126d29320922110d2ba02d8120152d15d7d27ff8fb98b5818c82a14baeaff816cbd952444d7c90e17be35ff0835e8c910379db
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
  ```
@@ -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(client, command)
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(client)
109
+ lookup_temperature client
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Hiveline
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hiveline
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Blanchard