my_tado 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/main.yml +16 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/.rubocop.yml +35 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +64 -0
- data/LICENSE.txt +21 -0
- data/README.md +89 -0
- data/Rakefile +12 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/my_tado/client.rb +51 -0
- data/lib/my_tado/credential_getter.rb +58 -0
- data/lib/my_tado/oauth_client.rb +63 -0
- data/lib/my_tado/request/abstract_request.rb +42 -0
- data/lib/my_tado/request/home.rb +12 -0
- data/lib/my_tado/request/me.rb +16 -0
- data/lib/my_tado/request/presence.rb +12 -0
- data/lib/my_tado/request/weather.rb +12 -0
- data/lib/my_tado/request/zone_state.rb +12 -0
- data/lib/my_tado/request/zones.rb +12 -0
- data/lib/my_tado/response/abstract_response.rb +50 -0
- data/lib/my_tado/version.rb +5 -0
- data/lib/my_tado.rb +23 -0
- data/lib/secrets.example.yml +5 -0
- data/my_tado.gemspec +35 -0
- metadata +88 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 015430353e51fc1f2a947573f6f59536a1a221ca027d2c6c48b9b5e578a860bf
|
4
|
+
data.tar.gz: 580a0498666d8efdf55aa1d262cc85c8611bdf091fcd6c7934a99736da62e9ac
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9641dec73aaf5244769a4760dabb6edb536fc8fc6b8ba0d64773af9b5775b0d8416147967401c9614d56e5df64023aabc0fb1e3a305c7d7846ef7a26a88cb87e
|
7
|
+
data.tar.gz: 9db05b3bb6bdde2faec471378c9a19d5257745b58c8bbf5bcd32cc9b2ccc7d5e46a88b1c66fc85bbfdd5cc263879336559b4e84217046bd53f46b94dc114bbfa
|
@@ -0,0 +1,16 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on: [push,pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
steps:
|
9
|
+
- uses: actions/checkout@v2
|
10
|
+
- name: Set up Ruby
|
11
|
+
uses: ruby/setup-ruby@v1
|
12
|
+
with:
|
13
|
+
ruby-version: 3.0.1
|
14
|
+
bundler-cache: true
|
15
|
+
- name: Run the default task
|
16
|
+
run: bundle exec rake
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
AllCops:
|
2
|
+
NewCops: enable
|
3
|
+
TargetRubyVersion: 3.0
|
4
|
+
|
5
|
+
Layout/EndOfLine:
|
6
|
+
Enabled: False
|
7
|
+
|
8
|
+
Layout/FirstHashElementIndentation:
|
9
|
+
EnforcedStyle: consistent
|
10
|
+
|
11
|
+
Layout/LineLength:
|
12
|
+
Max: 120
|
13
|
+
|
14
|
+
Lint/ScriptPermission:
|
15
|
+
Enabled: false
|
16
|
+
|
17
|
+
Metrics/BlockLength:
|
18
|
+
Exclude:
|
19
|
+
- "spec/**/*"
|
20
|
+
|
21
|
+
Style/BlockDelimiters:
|
22
|
+
IgnoredMethods: ["subject"]
|
23
|
+
|
24
|
+
Style/StringLiterals:
|
25
|
+
Enabled: false
|
26
|
+
|
27
|
+
Style/StringLiteralsInInterpolation:
|
28
|
+
Enabled: true
|
29
|
+
EnforcedStyle: double_quotes
|
30
|
+
|
31
|
+
Style/TrailingCommaInArguments:
|
32
|
+
EnforcedStyleForMultiline: consistent_comma
|
33
|
+
|
34
|
+
Style/TrailingCommaInHashLiteral:
|
35
|
+
EnforcedStyleForMultiline: comma
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
my_tado (0.1.0)
|
5
|
+
httparty (~> 0.17.3)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
ast (2.4.2)
|
11
|
+
diff-lcs (1.4.4)
|
12
|
+
httparty (0.17.3)
|
13
|
+
mime-types (~> 3.0)
|
14
|
+
multi_xml (>= 0.5.2)
|
15
|
+
mime-types (3.4.1)
|
16
|
+
mime-types-data (~> 3.2015)
|
17
|
+
mime-types-data (3.2021.1115)
|
18
|
+
multi_xml (0.6.0)
|
19
|
+
parallel (1.21.0)
|
20
|
+
parser (3.0.2.0)
|
21
|
+
ast (~> 2.4.1)
|
22
|
+
rainbow (3.0.0)
|
23
|
+
rake (13.0.6)
|
24
|
+
regexp_parser (2.1.1)
|
25
|
+
rexml (3.2.5)
|
26
|
+
rspec (3.10.0)
|
27
|
+
rspec-core (~> 3.10.0)
|
28
|
+
rspec-expectations (~> 3.10.0)
|
29
|
+
rspec-mocks (~> 3.10.0)
|
30
|
+
rspec-core (3.10.1)
|
31
|
+
rspec-support (~> 3.10.0)
|
32
|
+
rspec-expectations (3.10.1)
|
33
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
34
|
+
rspec-support (~> 3.10.0)
|
35
|
+
rspec-mocks (3.10.2)
|
36
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
37
|
+
rspec-support (~> 3.10.0)
|
38
|
+
rspec-support (3.10.3)
|
39
|
+
rubocop (1.23.0)
|
40
|
+
parallel (~> 1.10)
|
41
|
+
parser (>= 3.0.0.0)
|
42
|
+
rainbow (>= 2.2.2, < 4.0)
|
43
|
+
regexp_parser (>= 1.8, < 3.0)
|
44
|
+
rexml
|
45
|
+
rubocop-ast (>= 1.12.0, < 2.0)
|
46
|
+
ruby-progressbar (~> 1.7)
|
47
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
48
|
+
rubocop-ast (1.13.0)
|
49
|
+
parser (>= 3.0.1.1)
|
50
|
+
ruby-progressbar (1.11.0)
|
51
|
+
unicode-display_width (2.1.0)
|
52
|
+
|
53
|
+
PLATFORMS
|
54
|
+
x64-mingw32
|
55
|
+
x86_64-linux
|
56
|
+
|
57
|
+
DEPENDENCIES
|
58
|
+
my_tado!
|
59
|
+
rake (>= 12.3.3)
|
60
|
+
rspec (~> 3.0)
|
61
|
+
rubocop (~> 1.17)
|
62
|
+
|
63
|
+
BUNDLED WITH
|
64
|
+
2.2.21
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 reedstonefood
|
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,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
|
+
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/
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "my_tado"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'httparty'
|
4
|
+
|
5
|
+
module MyTado
|
6
|
+
# The main object from where everything else happens
|
7
|
+
class Client
|
8
|
+
IMPLEMENTED_ENDPOINTS = %i[me home presence weather zones zone_state].freeze
|
9
|
+
|
10
|
+
def initialize(credentials_source)
|
11
|
+
@credentials_source = credentials_source
|
12
|
+
end
|
13
|
+
|
14
|
+
def credentials
|
15
|
+
@credentials ||= CredentialGetter.new(@credentials_source)
|
16
|
+
end
|
17
|
+
|
18
|
+
def access_token
|
19
|
+
oauth_client.access_token
|
20
|
+
end
|
21
|
+
|
22
|
+
def home_id
|
23
|
+
@home_id ||= credentials.home_id || me["homeId"]
|
24
|
+
end
|
25
|
+
|
26
|
+
IMPLEMENTED_ENDPOINTS.each do |endpoint|
|
27
|
+
define_method endpoint.to_s do |options = {}|
|
28
|
+
klass = Object.const_get("MyTado::Request::#{camelize(endpoint)}")
|
29
|
+
options.merge!(home_id: home_id) if klass.requires_home_id_param?
|
30
|
+
request = klass.new(access_token, options)
|
31
|
+
Response::AbstractResponse.new(request.call)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def oauth_client
|
38
|
+
return @oauth_client if defined?(@oauth_client)
|
39
|
+
|
40
|
+
@oauth_client = OAuthClient.new(
|
41
|
+
client_secret: credentials.client_secret,
|
42
|
+
username: credentials.username,
|
43
|
+
password: credentials.password,
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
def camelize(string)
|
48
|
+
string.to_s.split('_').collect(&:capitalize).join
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MyTado
|
4
|
+
# Gets credentials from a source, either YAML or a string
|
5
|
+
class CredentialGetter
|
6
|
+
class InvalidSourceError < StandardError; end
|
7
|
+
class HomeIDNotAnIntegerError < StandardError; end
|
8
|
+
DEFAULT_CLIENT_SECRET = 'wZaRN7rpjn3FoNyF5IFuxg9uMzYJcvOoQ8QWiIqS3hfk6gLhVlG57j5YNoZL2Rtc'
|
9
|
+
require 'yaml'
|
10
|
+
attr_reader :data
|
11
|
+
|
12
|
+
def initialize(data_source)
|
13
|
+
case data_source.class.to_s
|
14
|
+
when "Hash"
|
15
|
+
load_hash(data_source)
|
16
|
+
when "String"
|
17
|
+
load_file(data_source)
|
18
|
+
else
|
19
|
+
raise InvalidSourceError
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def client_secret
|
24
|
+
data["client_secret"] || DEFAULT_CLIENT_SECRET
|
25
|
+
end
|
26
|
+
|
27
|
+
def home_id
|
28
|
+
data["home_id"]
|
29
|
+
end
|
30
|
+
|
31
|
+
def password
|
32
|
+
data["password"]
|
33
|
+
end
|
34
|
+
|
35
|
+
def refresh_token
|
36
|
+
data["refresh_token"]
|
37
|
+
end
|
38
|
+
|
39
|
+
def username
|
40
|
+
data["username"]
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def load_file(source_file)
|
46
|
+
@data = YAML.load_file(source_file)
|
47
|
+
end
|
48
|
+
|
49
|
+
def load_hash(hash)
|
50
|
+
@data = hash.transform_keys(&:to_s)
|
51
|
+
begin
|
52
|
+
@data["home_id"] = Integer(@data["home_id"]) if @data["home_id"]
|
53
|
+
rescue ArgumentError
|
54
|
+
raise HomeIDNotAnIntegerError
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'httparty'
|
4
|
+
|
5
|
+
module MyTado
|
6
|
+
# Gets the authorization credentials we need to interact with the main API
|
7
|
+
class OAuthClient
|
8
|
+
class NoCredentialsError < StandardError; end
|
9
|
+
include HTTParty
|
10
|
+
base_uri "https://auth.tado.com/oauth"
|
11
|
+
|
12
|
+
def initialize(client_secret:, username:, password:)
|
13
|
+
@default_options = { client_id: "tado-web-app", scope: "home.user", client_secret: client_secret }
|
14
|
+
@refresh_token = nil
|
15
|
+
@username = username
|
16
|
+
@password = password
|
17
|
+
end
|
18
|
+
|
19
|
+
# Doesn't cache it or do anything clever yet
|
20
|
+
def access_token(preferred_method: "refresh")
|
21
|
+
if preferred_method == "refresh" && @refresh_token
|
22
|
+
using_refresh_token["access_token"]
|
23
|
+
elsif @username && @password
|
24
|
+
using_username_and_password["access_token"]
|
25
|
+
else
|
26
|
+
raise NoCredentialsError
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def using_refresh_token
|
31
|
+
response = self.class.post(
|
32
|
+
"/token",
|
33
|
+
options({
|
34
|
+
grant_type: "refresh_token",
|
35
|
+
refresh_token: @refresh_token,
|
36
|
+
}),
|
37
|
+
)
|
38
|
+
|
39
|
+
@refresh_token = response["refresh_token"]
|
40
|
+
response
|
41
|
+
end
|
42
|
+
|
43
|
+
def using_username_and_password
|
44
|
+
response = self.class.post(
|
45
|
+
"/token",
|
46
|
+
options({
|
47
|
+
grant_type: "password",
|
48
|
+
username: @username,
|
49
|
+
password: @password,
|
50
|
+
}),
|
51
|
+
)
|
52
|
+
|
53
|
+
@refresh_token = response["refresh_token"]
|
54
|
+
response
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def options(extra_options)
|
60
|
+
{ body: @default_options.merge(extra_options) }
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'httparty'
|
4
|
+
|
5
|
+
module MyTado
|
6
|
+
module Request
|
7
|
+
# Sends requests to tado's main API
|
8
|
+
class AbstractRequest
|
9
|
+
include HTTParty
|
10
|
+
base_uri "https://my.tado.com/api"
|
11
|
+
attr_reader :options
|
12
|
+
|
13
|
+
def self.requires_home_id_param?
|
14
|
+
true
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(access_token, options)
|
18
|
+
@access_token = access_token
|
19
|
+
@options = options
|
20
|
+
end
|
21
|
+
|
22
|
+
def call
|
23
|
+
self.class.public_send(method, endpoint, {
|
24
|
+
headers: { "Authorization" => "Bearer #{@access_token}" },
|
25
|
+
body: body,
|
26
|
+
},)
|
27
|
+
end
|
28
|
+
|
29
|
+
def method
|
30
|
+
:get
|
31
|
+
end
|
32
|
+
|
33
|
+
def klass_name
|
34
|
+
self.class.to_s.gsub(/(.)([A-Z])/, '\1_\2').downcase
|
35
|
+
end
|
36
|
+
|
37
|
+
def body
|
38
|
+
nil
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'forwardable'
|
4
|
+
|
5
|
+
module MyTado
|
6
|
+
module Response
|
7
|
+
# Make response a bit easier to deal with in Ruby
|
8
|
+
class AbstractResponse
|
9
|
+
attr_reader :raw_response
|
10
|
+
|
11
|
+
extend Forwardable
|
12
|
+
|
13
|
+
def_delegators :@parsed_response, :[]
|
14
|
+
|
15
|
+
def initialize(raw_response)
|
16
|
+
@raw_response = raw_response
|
17
|
+
parse
|
18
|
+
end
|
19
|
+
|
20
|
+
def ok?
|
21
|
+
raw_response.ok?
|
22
|
+
end
|
23
|
+
|
24
|
+
def parse
|
25
|
+
@parsed_response = recursive_parse(raw_response)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
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
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Try to identify dates, which Tado's API always sends in a consistent format
|
43
|
+
def iso8601_string?(value)
|
44
|
+
value.is_a?(String) &&
|
45
|
+
value.length == 24 &&
|
46
|
+
/[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}/.match(value)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/my_tado.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "my_tado/client"
|
4
|
+
require_relative "my_tado/credential_getter"
|
5
|
+
require_relative "my_tado/oauth_client"
|
6
|
+
require_relative "my_tado/version"
|
7
|
+
require_relative "my_tado/request/abstract_request"
|
8
|
+
require_relative "my_tado/request/me"
|
9
|
+
require_relative "my_tado/request/home"
|
10
|
+
require_relative "my_tado/request/presence"
|
11
|
+
require_relative "my_tado/request/weather"
|
12
|
+
require_relative "my_tado/request/zones"
|
13
|
+
require_relative "my_tado/request/zone_state"
|
14
|
+
require_relative "my_tado/response/abstract_response"
|
15
|
+
|
16
|
+
# Caling `new` creates a Client
|
17
|
+
module MyTado
|
18
|
+
class Error < StandardError; end
|
19
|
+
|
20
|
+
def self.new(...)
|
21
|
+
Client.new(...)
|
22
|
+
end
|
23
|
+
end
|
data/my_tado.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/my_tado/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "my_tado"
|
7
|
+
spec.version = MyTado::VERSION
|
8
|
+
spec.authors = ["reedstonefood"]
|
9
|
+
spec.email = ["reedstonefood@users.noreply.github.com"]
|
10
|
+
|
11
|
+
spec.summary = "Interact with Tado's v2 API"
|
12
|
+
spec.description = "Tado sell smart home heating devices. See www.tado.com"
|
13
|
+
spec.homepage = "https://github.com/reedstonefood/my_tado"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 3.0.0"
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = "https://github.com/reedstonefood/my_tado"
|
19
|
+
spec.metadata["changelog_uri"] = "https://github.com/reedstonefood/my_tado/CHANGELOG.md"
|
20
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
25
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
26
|
+
end
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
spec.add_dependency "httparty", "~> 0.17.3"
|
32
|
+
|
33
|
+
# For more information and examples about making a new gem, checkout our
|
34
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: my_tado
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- reedstonefood
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-07-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.17.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.17.3
|
27
|
+
description: Tado sell smart home heating devices. See www.tado.com
|
28
|
+
email:
|
29
|
+
- reedstonefood@users.noreply.github.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".github/workflows/main.yml"
|
35
|
+
- ".gitignore"
|
36
|
+
- ".rspec"
|
37
|
+
- ".rubocop.yml"
|
38
|
+
- CHANGELOG.md
|
39
|
+
- Gemfile
|
40
|
+
- Gemfile.lock
|
41
|
+
- LICENSE.txt
|
42
|
+
- README.md
|
43
|
+
- Rakefile
|
44
|
+
- bin/console
|
45
|
+
- bin/setup
|
46
|
+
- lib/my_tado.rb
|
47
|
+
- lib/my_tado/client.rb
|
48
|
+
- lib/my_tado/credential_getter.rb
|
49
|
+
- lib/my_tado/oauth_client.rb
|
50
|
+
- lib/my_tado/request/abstract_request.rb
|
51
|
+
- lib/my_tado/request/home.rb
|
52
|
+
- lib/my_tado/request/me.rb
|
53
|
+
- lib/my_tado/request/presence.rb
|
54
|
+
- lib/my_tado/request/weather.rb
|
55
|
+
- lib/my_tado/request/zone_state.rb
|
56
|
+
- lib/my_tado/request/zones.rb
|
57
|
+
- lib/my_tado/response/abstract_response.rb
|
58
|
+
- lib/my_tado/version.rb
|
59
|
+
- lib/secrets.example.yml
|
60
|
+
- my_tado.gemspec
|
61
|
+
homepage: https://github.com/reedstonefood/my_tado
|
62
|
+
licenses:
|
63
|
+
- MIT
|
64
|
+
metadata:
|
65
|
+
homepage_uri: https://github.com/reedstonefood/my_tado
|
66
|
+
source_code_uri: https://github.com/reedstonefood/my_tado
|
67
|
+
changelog_uri: https://github.com/reedstonefood/my_tado/CHANGELOG.md
|
68
|
+
rubygems_mfa_required: 'true'
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 3.0.0
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubygems_version: 3.2.15
|
85
|
+
signing_key:
|
86
|
+
specification_version: 4
|
87
|
+
summary: Interact with Tado's v2 API
|
88
|
+
test_files: []
|