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

API_SITE

Site used for API requests

AUTH_SITE

Site used sefor authentication

CLIENT_ID

Client ID used the the Tado web application

CLIENT_SECRET

Client secret used by the Tado web application

VERSION

Version of Tado ruby implementation

Attributes

email[R]

Email of Tado owner

@return [String]

name[R]

Name of Tado owner

@return [String]

username[R]

Username of Tado owner

@return [String]

Public Class Methods

new(username, password, client_id: CLIENT_ID, client_secret: CLIENT_SECRET) click to toggle source

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

getHistory(date = Date.today, home:, zone:) click to toggle source

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
getHomes() click to toggle source

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
refresh!() click to toggle source

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
v2_get(resource, **opts) click to toggle source

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