my_tado 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -2
- data/Gemfile.lock +2 -2
- data/README.md +95 -89
- data/lib/my_tado/client.rb +1 -1
- data/lib/my_tado/request/day_report.rb +16 -0
- data/lib/my_tado/response/abstract_response.rb +33 -13
- data/lib/my_tado/version.rb +5 -5
- data/lib/my_tado.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f975cc9f1cace37124934514f0f40d6c3e2bcf775c6fca9a31581dfb06bfc7b
|
4
|
+
data.tar.gz: 1cb76dadc5a24ce68e0f849aca4a0a1f2dd7bfac6197c86a54f9b913c2b330a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be1ca88c32e3b4bdacae421c8263fc6874670851dbb44211692f672d6b3f9f2ba8aef0925f01ed4fb36fa4c7845a48e936405994574c3f88046803bedd2d820a
|
7
|
+
data.tar.gz: d854ba9699a3b2255a08ee9c245f27cd25e867cf8f30ea36c5eab443edea61c79a4b4e393dec7f6252293cabe1a72bd666f1b23f3b97d74a555b9145afa01943
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
my_tado (0.
|
4
|
+
my_tado (0.2.0)
|
5
5
|
httparty (~> 0.17.3)
|
6
6
|
|
7
7
|
GEM
|
@@ -14,7 +14,7 @@ GEM
|
|
14
14
|
multi_xml (>= 0.5.2)
|
15
15
|
mime-types (3.4.1)
|
16
16
|
mime-types-data (~> 3.2015)
|
17
|
-
mime-types-data (3.
|
17
|
+
mime-types-data (3.2022.0105)
|
18
18
|
multi_xml (0.6.0)
|
19
19
|
parallel (1.21.0)
|
20
20
|
parser (3.0.2.0)
|
data/README.md
CHANGED
@@ -1,89 +1,95 @@
|
|
1
|
-
# MyTado
|
2
|
-
|
3
|
-
A Ruby wrapper for interacting with Tado's v2 API.
|
4
|
-
|
5
|
-
The API is officially undocumented so there are no guarantees that this will work for you!
|
6
|
-
|
7
|
-
## Installation
|
8
|
-
|
9
|
-
`gem install my_tado`
|
10
|
-
|
11
|
-
## Usage
|
12
|
-
|
13
|
-
To connect to Tado's API, you need to have a username, password, and (optionally) client_secret.
|
14
|
-
|
15
|
-
At time of writing, the client_secret that is widely used is `wZaRN7rpjn3FoNyF5IFuxg9uMzYJcvOoQ8QWiIqS3hfk6gLhVlG57j5YNoZL2Rtc`, so if you do not provide a client_secret of your own, MyTado will use that one. See https://shkspr.mobi/blog/2019/02/tado-api-guide-updated-for-2019/ for more information on this.
|
16
|
-
|
17
|
-
Once you have all three, you can put them into MyTado either as a hash (using strings or symbols as keys), or a YML file (for example, see [secrets.example.yml](https://github.com/reedstonefood/my_tado/blob/master/lib/secrets.example.yml)), like so:
|
18
|
-
|
19
|
-
```ruby
|
20
|
-
# Using a hash
|
21
|
-
credentials = { username: "foo@example.com", password: "terrible_password" }
|
22
|
-
tado = MyTado.new(credentials)
|
23
|
-
|
24
|
-
# Or, using a YML file
|
25
|
-
tado = MyTado.new("secrets.yml")
|
26
|
-
```
|
27
|
-
|
28
|
-
Once initialized you can call other endpoints like so:
|
29
|
-
|
30
|
-
```ruby
|
31
|
-
tado.home # no extra parameters needed
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
- `
|
42
|
-
- `
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
##
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
1
|
+
# MyTado
|
2
|
+
|
3
|
+
A Ruby wrapper for interacting with Tado's v2 API.
|
4
|
+
|
5
|
+
The API is officially undocumented so there are no guarantees that this will work for you!
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
`gem install my_tado`
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
To connect to Tado's API, you need to have a username, password, and (optionally) client_secret.
|
14
|
+
|
15
|
+
At time of writing, the client_secret that is widely used is `wZaRN7rpjn3FoNyF5IFuxg9uMzYJcvOoQ8QWiIqS3hfk6gLhVlG57j5YNoZL2Rtc`, so if you do not provide a client_secret of your own, MyTado will use that one. See https://shkspr.mobi/blog/2019/02/tado-api-guide-updated-for-2019/ for more information on this.
|
16
|
+
|
17
|
+
Once you have all three, you can put them into MyTado either as a hash (using strings or symbols as keys), or a YML file (for example, see [secrets.example.yml](https://github.com/reedstonefood/my_tado/blob/master/lib/secrets.example.yml)), like so:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
# Using a hash
|
21
|
+
credentials = { username: "foo@example.com", password: "terrible_password" }
|
22
|
+
tado = MyTado.new(credentials)
|
23
|
+
|
24
|
+
# Or, using a YML file
|
25
|
+
tado = MyTado.new("secrets.yml")
|
26
|
+
```
|
27
|
+
|
28
|
+
Once initialized you can call other endpoints like so:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
tado.home # no extra parameters needed
|
32
|
+
|
33
|
+
tado.zone_state(zone_id: 0) # an example where a parameter is needed
|
34
|
+
|
35
|
+
# treat the output as an Array/Hash
|
36
|
+
tado.zones.map { |zone| zone["name"] } # gives the names of all zones
|
37
|
+
```
|
38
|
+
|
39
|
+
## Endpoints
|
40
|
+
|
41
|
+
- `day_report` - detailed data from a zone for a specific day
|
42
|
+
- `me` - your account information - name, email etc.
|
43
|
+
- `home` - information about your home, address, contact details
|
44
|
+
- `presence` - returns whether tado thinks your presence is HOME or AWAY
|
45
|
+
- `weather` - the external weather for your home
|
46
|
+
- `zones` - a lot of information about your installation
|
47
|
+
- `zone_state` (requires `zone_id`) - information about your hot water or heating
|
48
|
+
|
49
|
+
## Responses
|
50
|
+
|
51
|
+
The response object that MyTado returns from the endpoints has the following methods:
|
52
|
+
|
53
|
+
- `raw_response` if you want the HTTParty response class
|
54
|
+
- `["thing"]` for looking at the response
|
55
|
+
- `ok?` - a convenience method for `raw_response.ok?` which lets you know if the response was an HTTP 200 or not.
|
56
|
+
|
57
|
+
Differences between `raw_response["thing"]` and `["thing"]` are:
|
58
|
+
- `["thing"]` will have automatically converted dates into Ruby Date objects to make it easier to use.
|
59
|
+
- You can call regular Array/Hash methods on ["thing"] directly, eg `tado.zones.count`. Easy!
|
60
|
+
|
61
|
+
## Example usage
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
credentials = { username: "foo@example.com", password: "terrible_password" }
|
65
|
+
tado = MyTado.new(credentials)
|
66
|
+
|
67
|
+
# Get the state of every zone
|
68
|
+
zones_state = tado.zones.map { |zone| tado.zone_state(zone["id"]) }
|
69
|
+
|
70
|
+
# Get the temperature in every zone, in celsius
|
71
|
+
acutal_temperatures = zone_states.map do |zone_state|
|
72
|
+
zone_state.dig('sensorDataPoints', 'insideTemperature', 'celsius')
|
73
|
+
end
|
74
|
+
```
|
75
|
+
|
76
|
+
## Running tests
|
77
|
+
|
78
|
+
~~There is no known test environment, so if you want to run tests you have to use your own Tado username and password. Don't worry, the tests only read data, they do not make any changes to your tado setup.~~
|
79
|
+
|
80
|
+
~~Put your username & password into spec/spec_helper, in the `test_username` and `test_password` methods. Then run `rspec spec`.~~
|
81
|
+
None of the tests that have been written test the actual API, they only test internal aspects of the client.
|
82
|
+
|
83
|
+
## Future development
|
84
|
+
|
85
|
+
This gem does what I want to do for my own purposes. I may add to it in the future, or I may not.
|
86
|
+
|
87
|
+
If you want to expand the functionality, feel free to fork it or raise a PR.
|
88
|
+
|
89
|
+
## License
|
90
|
+
|
91
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
92
|
+
|
93
|
+
## Helpful resources
|
94
|
+
|
95
|
+
https://shkspr.mobi/blog/2019/02/tado-api-guide-updated-for-2019/
|
data/lib/my_tado/client.rb
CHANGED
@@ -5,7 +5,7 @@ require 'httparty'
|
|
5
5
|
module MyTado
|
6
6
|
# The main object from where everything else happens
|
7
7
|
class Client
|
8
|
-
IMPLEMENTED_ENDPOINTS = %i[me home presence weather zones zone_state].freeze
|
8
|
+
IMPLEMENTED_ENDPOINTS = %i[me day_report home presence weather zones zone_state].freeze
|
9
9
|
|
10
10
|
def initialize(credentials_source)
|
11
11
|
@credentials_source = credentials_source
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MyTado
|
4
|
+
module Request
|
5
|
+
# Calls the /dayReport endpoint
|
6
|
+
class DayReport < AbstractRequest
|
7
|
+
def endpoint
|
8
|
+
"/v2/homes/#{options[:home_id]}/zones/#{options[:zone_id]}/dayReport?date=#{formatted_date}"
|
9
|
+
end
|
10
|
+
|
11
|
+
def formatted_date
|
12
|
+
Date.parse(options[:date]).strftime('%Y-%m-%d')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -4,14 +4,11 @@ require 'forwardable'
|
|
4
4
|
|
5
5
|
module MyTado
|
6
6
|
module Response
|
7
|
-
# Make response a bit easier to deal with in Ruby
|
7
|
+
# Make response a bit easier to deal with in Ruby, largely by
|
8
|
+
# converting datetimes to Ruby DateTime objects
|
8
9
|
class AbstractResponse
|
9
10
|
attr_reader :raw_response
|
10
11
|
|
11
|
-
extend Forwardable
|
12
|
-
|
13
|
-
def_delegators :@parsed_response, :[]
|
14
|
-
|
15
12
|
def initialize(raw_response)
|
16
13
|
@raw_response = raw_response
|
17
14
|
parse
|
@@ -22,23 +19,46 @@ module MyTado
|
|
22
19
|
end
|
23
20
|
|
24
21
|
def parse
|
25
|
-
@parsed_response = recursive_parse(raw_response)
|
22
|
+
@parsed_response = recursive_parse(raw_response.parsed_response)
|
23
|
+
end
|
24
|
+
|
25
|
+
def method_missing(method_name, *args, &block)
|
26
|
+
if @parsed_response.respond_to?(method_name)
|
27
|
+
@parsed_response.public_send(method_name, *args, &block)
|
28
|
+
else
|
29
|
+
super
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def respond_to_missing?(method_name, *_args)
|
34
|
+
@parsed_response.respond_to?(method_name)
|
26
35
|
end
|
27
36
|
|
28
37
|
private
|
29
38
|
|
30
39
|
def recursive_parse(original)
|
31
|
-
original
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
40
|
+
case original
|
41
|
+
when Hash
|
42
|
+
original.transform_values do |value|
|
43
|
+
clever_parse(value)
|
44
|
+
end
|
45
|
+
when Array
|
46
|
+
original.map do |value|
|
47
|
+
clever_parse(value)
|
38
48
|
end
|
39
49
|
end
|
40
50
|
end
|
41
51
|
|
52
|
+
def clever_parse(value)
|
53
|
+
if value.is_a?(Hash) || value.is_a?(Array)
|
54
|
+
recursive_parse(value)
|
55
|
+
elsif iso8601_string?(value)
|
56
|
+
DateTime.parse(value)
|
57
|
+
else
|
58
|
+
value
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
42
62
|
# Try to identify dates, which Tado's API always sends in a consistent format
|
43
63
|
def iso8601_string?(value)
|
44
64
|
value.is_a?(String) &&
|
data/lib/my_tado/version.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module MyTado
|
4
|
-
VERSION = "0.
|
5
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MyTado
|
4
|
+
VERSION = "0.2.0"
|
5
|
+
end
|
data/lib/my_tado.rb
CHANGED
@@ -5,6 +5,7 @@ require_relative "my_tado/credential_getter"
|
|
5
5
|
require_relative "my_tado/oauth_client"
|
6
6
|
require_relative "my_tado/version"
|
7
7
|
require_relative "my_tado/request/abstract_request"
|
8
|
+
require_relative "my_tado/request/day_report"
|
8
9
|
require_relative "my_tado/request/me"
|
9
10
|
require_relative "my_tado/request/home"
|
10
11
|
require_relative "my_tado/request/presence"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: my_tado
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- reedstonefood
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-07-
|
11
|
+
date: 2022-07-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -48,6 +48,7 @@ files:
|
|
48
48
|
- lib/my_tado/credential_getter.rb
|
49
49
|
- lib/my_tado/oauth_client.rb
|
50
50
|
- lib/my_tado/request/abstract_request.rb
|
51
|
+
- lib/my_tado/request/day_report.rb
|
51
52
|
- lib/my_tado/request/home.rb
|
52
53
|
- lib/my_tado/request/me.rb
|
53
54
|
- lib/my_tado/request/presence.rb
|