class Tado
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
Constants
Attributes
Email of Tado
owner
@return [String]
Name of Tado
owner
@return [String]
Username of Tado
owner
@return [String]
Public Class Methods
Create a new instance of Tado
@param [String] username account username @param [String] password account password @param [String] client_id client id used for oauth2 @param [String] client_secret client secret used for oauth2
# 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
Public Instance Methods
Shortcut to get zone history from home/zone identifiers. @see Zone#getHistory
@param home [Integer] home identifier @param zone [Integer] zone identifier @return [Hash{Symbol => Object}] history of the given day.
# File lib/tado.rb, line 92 def getHistory(date = Date.today, home:, zone:) History.get(date, home: home, zone: zone, tado: self) end
Retrieve list of homes associated with the tado account
@return [Array<Home>] list of homes
# File lib/tado.rb, line 80 def getHomes v2_get('me').dig('homes').map {|h| Home.new( h.dig('id'), tado: self ) } end
Force a refresh of tado attributs
@return [self]
# 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
Retrieve a resource as a JSON
@param [String] resource relative to the v2 API @return a JSON structure
# File lib/tado.rb, line 112 def v2_get(resource, **opts) JSON.parse(@client.get("/api/v2/#{resource}", **opts).body) end