Class: Tado
- Inherits:
-
Object
- Object
- Tado
- Defined in:
- lib/tado.rb,
lib/tado/home.rb,
lib/tado/zone.rb,
lib/tado/device.rb,
lib/tado/errors.rb,
lib/tado/history.rb,
lib/tado/version.rb
Overview
Access to the Tado API
Unoffical API documentation is provided by:
Web app client id/secret are retrieved from:
Example:
require 'tado'
$t = Tado.new('login', 'password')
puts $t.getHomes.first.getZones.first.getHistory.inspect
Defined Under Namespace
Modules: History Classes: Device, Error, Home, ParsingError, Zone
Constant Summary collapse
- CLIENT_ID =
Client ID used the the Tado web application
'tado-web-app'- CLIENT_SECRET =
Client secret used by the Tado web application
'wZaRN7rpjn3FoNyF5IFuxg9uMzYJcvOo' \ 'Q8QWiIqS3hfk6gLhVlG57j5YNoZL2Rtc'
- AUTH_SITE =
Site used sefor authentication
'https://auth.tado.com'.freeze
- API_SITE =
Site used for API requests
'https://my.tado.com'.freeze
- VERSION =
Version of Tado ruby implementation
'0.1.0'
Instance Attribute Summary collapse
-
#email ⇒ String
readonly
Email of Tado owner.
-
#name ⇒ String
readonly
Name of Tado owner.
-
#username ⇒ String
readonly
Username of Tado owner.
Instance Method Summary collapse
-
#getHistory(date = Date.today, home:, zone:) ⇒ Hash{Symbol => Object}
Shortcut to get zone history from home/zone identifiers.
-
#getHomes ⇒ Array<Home>
Retrieve list of homes associated with the tado account.
-
#initialize(username, password, client_id: CLIENT_ID, client_secret: CLIENT_SECRET) ⇒ Tado
constructor
Create a new instance of Tado.
-
#refresh! ⇒ self
Force a refresh of tado attributs.
-
#v2_get(resource, **opts) ⇒ Object
Retrieve a resource as a JSON.
Constructor Details
#initialize(username, password, client_id: CLIENT_ID, client_secret: CLIENT_SECRET) ⇒ Tado
Create a new instance of Tado
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/tado.rb', line 62 def initialize(username, password, client_id: CLIENT_ID, client_secret: CLIENT_SECRET) tclient = OAuth2::Client.new(client_id, client_secret, site: AUTH_SITE) @token = tclient.password.get_token(username, password) @client = Faraday.new(url: API_SITE) do |f| f.request :oauth2_refresh, @token f.request :url_encoded f.adapter :net_http end refresh! end |
Instance Attribute Details
#email ⇒ String (readonly)
Email of Tado owner
47 48 49 |
# File 'lib/tado.rb', line 47 def email @email end |
#name ⇒ String (readonly)
Name of Tado owner
41 42 43 |
# File 'lib/tado.rb', line 41 def name @name end |
#username ⇒ String (readonly)
Username of Tado owner
53 54 55 |
# File 'lib/tado.rb', line 53 def username @username end |
Instance Method Details
#getHistory(date = Date.today, home:, zone:) ⇒ Hash{Symbol => Object}
Shortcut to get zone history from home/zone identifiers.
92 93 94 |
# File 'lib/tado.rb', line 92 def getHistory(date = Date.today, home:, zone:) History.get(date, home: home, zone: zone, tado: self) end |
#getHomes ⇒ Array<Home>
Retrieve list of homes associated with the tado account
80 81 82 83 84 |
# File 'lib/tado.rb', line 80 def getHomes v2_get('me').dig('homes').map {|h| Home.new( h.dig('id'), tado: self ) } end |
#refresh! ⇒ self
Force a refresh of tado attributs
99 100 101 102 103 104 105 |
# File 'lib/tado.rb', line 99 def refresh! data = v2_get('me') @name = data.dig('name') @email = data.dig('email') @username = data.dig('username') self end |
#v2_get(resource, **opts) ⇒ Object
Retrieve a resource as a JSON
112 113 114 |
# File 'lib/tado.rb', line 112 def v2_get(resource, **opts) JSON.parse(@client.get("/api/v2/#{resource}", **opts).body) end |