tado 0.1.0
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 +7 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +29 -0
- data/lib/tado/version.rb +3 -0
- data/lib/tado.rb +101 -0
- data/tado.gemspec +21 -0
- metadata +65 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3b70b1e11a4dc7994b001628a6e54dd9947cee12
|
4
|
+
data.tar.gz: e4aa98d0c3b6263db65e0216fec38a58eb9cbc92
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 50cf2b316f4463db1ed6613a49594935a3150b33e070e0956a5aab4a4d3df460500333a3ec2f09dff481bc4894b63632ec857251bd5b2363ee3109baa397308f
|
7
|
+
data.tar.gz: 1d396fed67eecbb83370da75d6972c5ebe8999b2112faa8d4b1da618737621dc10d9eff62291addc8aedd24fd5303ec1a0c0176effcbc798580a0c2d7655fb5f
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Jamie Schembri
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Tado
|
2
|
+
|
3
|
+
Really simple gem for interacting with Tado's V2 API. The API is still officially closed, so I followed [this excellent blog post](http://blog.scphillips.com/posts/2017/01/the-tado-api-v2/) by [Stephen C Phillips](https://github.com/scp93ch).
|
4
|
+
|
5
|
+
Note that the auth response is cached to `~/.tado_auth`.
|
6
|
+
|
7
|
+
## Basic usage
|
8
|
+
|
9
|
+
Set up a new Tado object:
|
10
|
+
|
11
|
+
```
|
12
|
+
tado = Tado.new(username: ..., password: ...)
|
13
|
+
```
|
14
|
+
|
15
|
+
Get some info about you and your home with `tado.me`. You might want to grab your home ID. You'll find it in `tado.me.homes`.
|
16
|
+
|
17
|
+
Now set your home_id. You can also pass `home_id` to the initializer.
|
18
|
+
|
19
|
+
```
|
20
|
+
tado.home_id = ...
|
21
|
+
```
|
22
|
+
|
23
|
+
Now you can get some info about your home using the other methods.
|
24
|
+
|
25
|
+
|
26
|
+
## License
|
27
|
+
|
28
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
29
|
+
|
data/lib/tado/version.rb
ADDED
data/lib/tado.rb
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
class Tado
|
5
|
+
BASE_URI = 'https://my.tado.com/'.freeze
|
6
|
+
AUTH_URI = "#{BASE_URI}oauth/token".freeze
|
7
|
+
API_BASE_URI = "#{BASE_URI}api/v2/".freeze
|
8
|
+
|
9
|
+
AUTH_FILEPATH = "#{Dir.home}/.tado_auth".freeze
|
10
|
+
AUTH_CLIENT_ID = 'tado-webapp'.freeze
|
11
|
+
AUTH_GRANT_TYPE = 'password'.freeze
|
12
|
+
AUTH_SCOPE = 'home.user'.freeze
|
13
|
+
|
14
|
+
attr_writer :home_id
|
15
|
+
|
16
|
+
def initialize(username:, password:, home_id: nil)
|
17
|
+
@username = username
|
18
|
+
@password = password
|
19
|
+
@home_id = home_id
|
20
|
+
end
|
21
|
+
|
22
|
+
def me
|
23
|
+
get('me')
|
24
|
+
end
|
25
|
+
|
26
|
+
def home(home_id = @home_id)
|
27
|
+
get ['homes', home_id].join('/')
|
28
|
+
end
|
29
|
+
|
30
|
+
def weather(home_id = @home_id)
|
31
|
+
get ['homes', home_id, 'weather'].join('/')
|
32
|
+
end
|
33
|
+
|
34
|
+
def zones(home_id = @home_id)
|
35
|
+
get ['homes', home_id, 'zones'].join('/')
|
36
|
+
end
|
37
|
+
|
38
|
+
def zone_state(home_id = @home_id, zone = 1)
|
39
|
+
get ['homes', home_id, 'zones', zone, 'state'].join('/')
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def get(path)
|
45
|
+
uri = URI("#{API_BASE_URI}#{path}")
|
46
|
+
|
47
|
+
request = Net::HTTP::Get.new(uri)
|
48
|
+
request['Authorization'] = "Bearer #{auth_token}"
|
49
|
+
|
50
|
+
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
|
51
|
+
http.request(request)
|
52
|
+
end
|
53
|
+
|
54
|
+
JSON.parse(response.body)
|
55
|
+
end
|
56
|
+
|
57
|
+
def auth_token
|
58
|
+
return auth['access_token'] unless auth_expired?
|
59
|
+
|
60
|
+
authorize
|
61
|
+
end
|
62
|
+
|
63
|
+
def authorize
|
64
|
+
response = Net::HTTP.post_form(URI(AUTH_URI),
|
65
|
+
client_id: AUTH_CLIENT_ID,
|
66
|
+
grant_type: AUTH_GRANT_TYPE,
|
67
|
+
scope: AUTH_SCOPE,
|
68
|
+
username: @username,
|
69
|
+
password: @password)
|
70
|
+
|
71
|
+
@auth = JSON.parse(response.body)
|
72
|
+
@auth_expiry = nil
|
73
|
+
|
74
|
+
write_auth
|
75
|
+
|
76
|
+
@auth['access_token']
|
77
|
+
end
|
78
|
+
|
79
|
+
def auth_expired?
|
80
|
+
return true unless auth_exists?
|
81
|
+
return true if Time.now >= auth_expires_at
|
82
|
+
|
83
|
+
false
|
84
|
+
end
|
85
|
+
|
86
|
+
def auth_expires_at
|
87
|
+
@auth_expiry ||= (File.mtime(AUTH_FILEPATH) + auth['expires_in'].to_i)
|
88
|
+
end
|
89
|
+
|
90
|
+
def auth
|
91
|
+
@auth ||= JSON.parse(File.read(AUTH_FILEPATH))
|
92
|
+
end
|
93
|
+
|
94
|
+
def auth_exists?
|
95
|
+
File.exist?(AUTH_FILEPATH)
|
96
|
+
end
|
97
|
+
|
98
|
+
def write_auth
|
99
|
+
File.open(AUTH_FILEPATH, 'w') { |file| file.write(JSON.dump(@auth)) }
|
100
|
+
end
|
101
|
+
end
|
data/tado.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'tado/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'tado'
|
8
|
+
spec.version = Tado::VERSION
|
9
|
+
spec.authors = ['Jamie Schembri']
|
10
|
+
spec.email = ['jamie@schembri.me']
|
11
|
+
|
12
|
+
spec.summary = "Quick 'n dirty API client for Tado's V2 API"
|
13
|
+
spec.homepage = 'https://github.com/shkm/tado'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
|
20
|
+
spec.add_development_dependency 'bundler', '~> 1.13'
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tado
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jamie Schembri
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-02-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
27
|
+
description:
|
28
|
+
email:
|
29
|
+
- jamie@schembri.me
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".gitignore"
|
35
|
+
- Gemfile
|
36
|
+
- LICENSE.txt
|
37
|
+
- README.md
|
38
|
+
- lib/tado.rb
|
39
|
+
- lib/tado/version.rb
|
40
|
+
- tado.gemspec
|
41
|
+
homepage: https://github.com/shkm/tado
|
42
|
+
licenses:
|
43
|
+
- MIT
|
44
|
+
metadata: {}
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
requirements: []
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 2.5.1
|
62
|
+
signing_key:
|
63
|
+
specification_version: 4
|
64
|
+
summary: Quick 'n dirty API client for Tado's V2 API
|
65
|
+
test_files: []
|