hiveline 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -2
- data/bin/hiveline +32 -8
- data/lib/hiveline.rb +39 -22
- data/lib/hiveline/version.rb +1 -1
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c059e7ee5eddcd56423655cf5845b6bcc27c02a5
|
4
|
+
data.tar.gz: 325dbd20157ab085de429d24fe17ef49abca0db8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7feb248a4d80217044dc2aaa86ff6e2fa817807b71dae85a48549f6f736f7a75eabaa96f5019cab4c98fddb7417a907d42be4c1d13234f19ff99b78f5e7ee15
|
7
|
+
data.tar.gz: 58bca2c3519cf2ead934391615126d29320922110d2ba02d8120152d15d7d27ff8fb98b5818c82a14baeaff816cbd952444d7c90e17be35ff0835e8c910379db
|
data/README.md
CHANGED
@@ -28,8 +28,20 @@ $ hiveline -u <email> -p <password>
|
|
28
28
|
|
29
29
|
## Use
|
30
30
|
|
31
|
-
|
31
|
+
Get temperature
|
32
32
|
|
33
33
|
```bash
|
34
|
-
$ hiveline
|
34
|
+
$ hiveline
|
35
|
+
|
36
|
+
Inside Temperature: 19.9°C
|
37
|
+
Weather in London: Cloudy With Light Rain (2.8°C)
|
38
|
+
```
|
39
|
+
|
40
|
+
Set temperature
|
41
|
+
|
42
|
+
```bash
|
43
|
+
$ hiveline 19 # Set temperature to 19°C
|
44
|
+
|
45
|
+
Setting temperature to 19°C
|
46
|
+
Successfully updated temperature. Set to 19°C
|
35
47
|
```
|
data/bin/hiveline
CHANGED
@@ -31,19 +31,43 @@ if password.nil?
|
|
31
31
|
exit false
|
32
32
|
end
|
33
33
|
|
34
|
-
|
34
|
+
client = Hiveline::Client.new(username, password)
|
35
|
+
|
36
|
+
command = ARGV.last
|
37
|
+
|
38
|
+
def unknown_error
|
39
|
+
print "Something went wrong. Not sure what though because the API is not documented... maybe get up and go check your thermostat?\n"
|
40
|
+
end
|
35
41
|
|
36
42
|
def numeric?(number)
|
37
43
|
return true if number =~ /^\d+$/
|
38
44
|
true if Float(number) rescue false
|
39
45
|
end
|
40
46
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
47
|
+
def set_temperature(client, temp)
|
48
|
+
print "Setting temperature to #{temp}°C\n"
|
49
|
+
temperature = client.set_temperature(temp)
|
50
|
+
unless temperature.nil?
|
51
|
+
print "Successfully updated temperature. Set to #{temperature}°C\n"
|
52
|
+
else
|
53
|
+
unknown_error
|
54
|
+
end
|
46
55
|
end
|
47
56
|
|
48
|
-
|
49
|
-
|
57
|
+
def lookup_temperature(client)
|
58
|
+
print "Retrieving temperature information\n"
|
59
|
+
environment = client.get_temperature
|
60
|
+
unless environment.nil?
|
61
|
+
print "Inside Temperature: #{environment["inside"]}°C\n"
|
62
|
+
print "Weather in #{environment["city"]}: #{environment['weather'].split('_').map{|e| e.capitalize}.join(" ")} (#{environment["outside"]}°C)\n"
|
63
|
+
else
|
64
|
+
unknown_error
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
if numeric?(command)
|
69
|
+
set_temperature(client, command)
|
70
|
+
exit
|
71
|
+
end
|
72
|
+
|
73
|
+
lookup_temperature(client)
|
data/lib/hiveline.rb
CHANGED
@@ -1,54 +1,64 @@
|
|
1
|
+
require 'hiveline/version'
|
1
2
|
require 'httparty'
|
2
3
|
require 'json'
|
3
|
-
require 'hiveline/version'
|
4
4
|
|
5
5
|
module Hiveline
|
6
6
|
class Client
|
7
|
-
|
7
|
+
include HTTParty
|
8
|
+
attr_accessor :username, :password, :session
|
8
9
|
|
9
10
|
def initialize(username, password)
|
10
11
|
@username = username
|
11
12
|
@password = password
|
12
|
-
|
13
|
+
end
|
14
|
+
|
15
|
+
def session
|
16
|
+
@session ||= retrieve_session
|
13
17
|
end
|
14
18
|
|
15
19
|
def set_temperature(temp)
|
16
|
-
print "Setting temperature to #{temp}C...\n"
|
17
20
|
heating_url = "https://my.hivehome.com/heating/target"
|
18
|
-
|
21
|
+
id = self.session
|
22
|
+
response = self.class.put(heating_url, {
|
19
23
|
body: {
|
20
24
|
id:1,
|
21
25
|
target:temp
|
22
26
|
},
|
23
27
|
headers: {
|
24
|
-
"Cookie" => "hsid=#{
|
28
|
+
"Cookie" => "hsid=#{id}"
|
25
29
|
},
|
26
30
|
follow_redirects: false
|
27
31
|
})
|
28
32
|
|
29
33
|
if response.code == 200
|
30
|
-
|
31
|
-
print "Successfully updated temperature. Set to #{target}C\n"
|
34
|
+
JSON.parse(response.body)["target"]
|
32
35
|
else
|
33
|
-
|
36
|
+
nil
|
34
37
|
end
|
35
|
-
response
|
36
38
|
end
|
37
39
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
username: @username,
|
46
|
-
password: @password
|
47
|
-
},
|
40
|
+
def get_temperature
|
41
|
+
weather_url = "https://my.hivehome.com/weather"
|
42
|
+
response = self.class.get(weather_url, {
|
43
|
+
headers: {
|
44
|
+
"Cookie" => "hsid=#{self.session}",
|
45
|
+
"Content-Type" => "application/json"
|
46
|
+
},
|
48
47
|
follow_redirects: false
|
49
48
|
})
|
49
|
+
if response.code == 200
|
50
|
+
JSON.parse(response.body)
|
51
|
+
else
|
52
|
+
nil
|
53
|
+
end
|
50
54
|
end
|
51
55
|
|
56
|
+
private
|
57
|
+
|
58
|
+
def retrieve_session
|
59
|
+
extract_session_id login
|
60
|
+
end
|
61
|
+
|
52
62
|
def extract_session_id(response)
|
53
63
|
id_attribute_regex = /^hsid=/
|
54
64
|
set_cookie_header = response.headers["set-cookie"]
|
@@ -60,8 +70,15 @@ module Hiveline
|
|
60
70
|
.gsub(id_attribute_regex, "")
|
61
71
|
end
|
62
72
|
|
63
|
-
def
|
64
|
-
|
73
|
+
def login
|
74
|
+
login_url = "https://my.hivehome.com/login"
|
75
|
+
self.class.post(login_url, {
|
76
|
+
body: {
|
77
|
+
username: @username,
|
78
|
+
password: @password
|
79
|
+
},
|
80
|
+
follow_redirects: false
|
81
|
+
})
|
65
82
|
end
|
66
83
|
end
|
67
84
|
end
|
data/lib/hiveline/version.rb
CHANGED
metadata
CHANGED
@@ -1,55 +1,55 @@
|
|
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.3
|
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-01-
|
11
|
+
date: 2015-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 0.13.3
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 0.13.3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '1.7'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.7'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '10.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '10.0'
|
55
55
|
description: The Hive API was reversed engineered via the Hive thermostat website
|
@@ -80,17 +80,17 @@ require_paths:
|
|
80
80
|
- lib
|
81
81
|
required_ruby_version: !ruby/object:Gem::Requirement
|
82
82
|
requirements:
|
83
|
-
- -
|
83
|
+
- - '>='
|
84
84
|
- !ruby/object:Gem::Version
|
85
85
|
version: '0'
|
86
86
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
87
|
requirements:
|
88
|
-
- -
|
88
|
+
- - '>='
|
89
89
|
- !ruby/object:Gem::Version
|
90
90
|
version: '0'
|
91
91
|
requirements: []
|
92
92
|
rubyforge_project:
|
93
|
-
rubygems_version: 2.
|
93
|
+
rubygems_version: 2.4.3
|
94
94
|
signing_key:
|
95
95
|
specification_version: 4
|
96
96
|
summary: A small Ruby script to change your Hive thermostat temperature through your
|