Class: Tado

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(username, password, client_id: CLIENT_ID, client_secret: CLIENT_SECRET) ⇒ Tado

Create a new instance of Tado

Parameters:

  • account username

  • account password

  • (defaults to: CLIENT_ID)

    client id used for oauth2

  • (defaults to: CLIENT_SECRET)

    client secret used for oauth2



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

#emailString (readonly)

Email of Tado owner

Returns:



47
48
49
# File 'lib/tado.rb', line 47

def email
  @email
end

#nameString (readonly)

Name of Tado owner

Returns:



41
42
43
# File 'lib/tado.rb', line 41

def name
  @name
end

#usernameString (readonly)

Username of Tado owner

Returns:



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.

Parameters:

  • home identifier

  • zone identifier

Returns:

  • history of the given day.

See Also:



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

#getHomesArray<Home>

Retrieve list of homes associated with the tado account

Returns:

  • list of homes



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

Returns:



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

Parameters:

  • relative to the v2 API

Returns:

  • a JSON structure



112
113
114
# File 'lib/tado.rb', line 112

def v2_get(resource, **opts)
    JSON.parse(@client.get("/api/v2/#{resource}", **opts).body)
end