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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 015430353e51fc1f2a947573f6f59536a1a221ca027d2c6c48b9b5e578a860bf
4
- data.tar.gz: 580a0498666d8efdf55aa1d262cc85c8611bdf091fcd6c7934a99736da62e9ac
3
+ metadata.gz: 6f975cc9f1cace37124934514f0f40d6c3e2bcf775c6fca9a31581dfb06bfc7b
4
+ data.tar.gz: 1cb76dadc5a24ce68e0f849aca4a0a1f2dd7bfac6197c86a54f9b913c2b330a8
5
5
  SHA512:
6
- metadata.gz: 9641dec73aaf5244769a4760dabb6edb536fc8fc6b8ba0d64773af9b5775b0d8416147967401c9614d56e5df64023aabc0fb1e3a305c7d7846ef7a26a88cb87e
7
- data.tar.gz: 9db05b3bb6bdde2faec471378c9a19d5257745b58c8bbf5bcd32cc9b2ccc7d5e46a88b1c66fc85bbfdd5cc263879336559b4e84217046bd53f46b94dc114bbfa
6
+ metadata.gz: be1ca88c32e3b4bdacae421c8263fc6874670851dbb44211692f672d6b3f9f2ba8aef0925f01ed4fb36fa4c7845a48e936405994574c3f88046803bedd2d820a
7
+ data.tar.gz: d854ba9699a3b2255a08ee9c245f27cd25e867cf8f30ea36c5eab443edea61c79a4b4e393dec7f6252293cabe1a72bd666f1b23f3b97d74a555b9145afa01943
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
- ## [Releases]
2
-
1
+ ## [Releases]
2
+
3
+ - 0.2 - 30th Jul 2022
4
+ - Added dayReport endpoint - detailed data from a zone for a specific day
5
+ - Fixed the code that automatically converts date to DateTime objects
3
6
  - 0.1 - 25th Jul 2022 - Initial release
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- my_tado (0.1.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.2021.1115)
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
- tado.zone_state({zone_id: 0}) # an example where a parameter is needed
33
- ```
34
-
35
- ## Endpoints
36
-
37
- - `me` - your account information - name, email etc.
38
- - `home` - information about your home, address, contact details
39
- - `presence` - returns whether tado thinks your presence is HOME or AWAY
40
- - `weather` - the external weather for your home
41
- - `zones` - a lot of information about your installation
42
- - `zone_state` (requires `zone_id`) - information about your hot water or heating
43
-
44
- ## Responses
45
-
46
- The response object that MyTado returns from the endpoints has the following methods:
47
-
48
- - `raw_response` if you want the HTTParty response class
49
- - `["thing"]` for looking at the response
50
- - `ok?` - a convenience method for `raw_response.ok?` which lets you know if the response was an HTTP 200 or not.
51
-
52
- Differences between `raw_response["thing"]` and `["thing"]` are:
53
- - ~~`["thing"]` will have automatically converted dates into Ruby Date objects to make it easier to use.~~ doesn't work yet
54
-
55
- ## Example usage
56
-
57
- ```ruby
58
- credentials = { username: "foo@example.com", password: "terrible_password" }
59
- tado = MyTado.new(credentials)
60
-
61
- # Get the state of every zone
62
- zones_state = tado.zones.map { |zone| tado.zone_state(zone["id"]) }
63
-
64
- # Get the temperature in every zone, in celsius
65
- acutal_temperatures = zone_states.map do |zone_state|
66
- zone_state.dig('sensorDataPoints', 'insideTemperature', 'celsius')
67
- end
68
- ```
69
-
70
- ## Running tests
71
-
72
- ~~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.~~
73
-
74
- ~~Put your username & password into spec/spec_helper, in the `test_username` and `test_password` methods. Then run `rspec spec`.~~
75
- None of the tests that have been written test the actual API, they only test internal aspects of the client.
76
-
77
- ## Future development
78
-
79
- This gem does what I want to do for my own purposes. I may add to it in the future, or I may not.
80
-
81
- If you want to expand the functionality, feel free to fork it or raise a PR.
82
-
83
- ## License
84
-
85
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
86
-
87
- ## Helpful resources
88
-
89
- https://shkspr.mobi/blog/2019/02/tado-api-guide-updated-for-2019/
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/
@@ -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.transform_values do |value|
32
- if value.is_a?(Hash)
33
- recursive_parse(value)
34
- elsif iso8601_string?(value)
35
- Date.parse(value)
36
- else
37
- value
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) &&
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
-
3
- module MyTado
4
- VERSION = "0.1.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.1.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-25 00:00:00.000000000 Z
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