class Tado::Home

Class wrapping interaction with the Tado Home

Attributes

address[R]

Home address

@return [Hash{Symbol => String,Array<String>}] home address

* :address [Array<String>]      address
* :zipcode [String]             zip code
* :city    [String]             city
* :state   [String]             state
* :country [String]             country (iso3)
away_radius[R]

Distance to consider user away from home

@return [Float] distance in meters

contact[R]

Home contact

@return [Hash{Symbol => String}] contact information

* :name    [String]             contact name
* :email   [String]             email address
* :phone   [String]             phone number
created[R]

Creation time

@return [Time] timestamp

geoloc[R]

Geolocalisation (GPS coordinate)

@return [Array<Numeric>] latitude/longitude

id[R]

Home identifier

@return [Integer] identifier

name[R]

Name of home

@return [String] name

tz[R]

Timezone

@return [TZInfo::Timezone] timezone

Public Class Methods

new(id, tado:) click to toggle source

Create a new Home associated to the Tado account

@param id [Integer] @param tado [Tado]

# File lib/tado/home.rb, line 14
def initialize(id, tado:)
    @tado = tado
    @id   = id

    refresh!
end

Public Instance Methods

getWeather() click to toggle source

Retrieve weather information associated with this home

@return [Hash<Symbol,Object>] weather information

* :solar_intensity  [Float]
* :temperature      [Float]
* :state            [Symbol]
* :timestamp        [Time]
# File lib/tado/home.rb, line 29
def getWeather
    w  = v2_get('weather')
    
    ts = [ 'solarIntensity', 'outsideTemperature', 'weatherState' ]
             .map {|k| w.dig(k, 'timestamp') }.uniq
    raise ParsingError if ts.size != 1

    {   :solar_intensity => w.dig('solarIntensity',     'percentage'),
        :temperature     => w.dig('outsideTemperature', 'celsius'),
        :state           => w.dig('weatherState',       'value').to_sym,
        :timestamp       => Time.parse(ts.first)
    }
end
getZones() click to toggle source

Retrieve zones associated with this home

@return [Array<Zone>] list of zones

# File lib/tado/home.rb, line 47
def getZones
    v2_get('zones').map{|data|
        Zone.from_json(data, home: self)
    }
end
refresh!() click to toggle source

Force a refresh of home attributs

@return [self]

# File lib/tado/home.rb, line 113
def refresh!
    data = @tado.v2_get("homes/#{@id}")
    @tz          = TZInfo::Timezone.get(data.dig('dateTimeZone'))
    @created     = Time.parse(data.dig('dateCreated'))
    @name        = data.dig('name')
    @geoloc      = [ data.dig('geolocation', 'latitude'),
                     data.dig('geolocation', 'longitude') ]
    @away_radius = data.dig('awayRadiusInMeters')
    @address     = {
        :address => [ data.dig('address', 'addressLine1'),
                      data.dig('address', 'addressLine2') ].compact,
        :zipcode => data.dig('address', 'zipCode'),
        :city    => data.dig('address', 'city'),
        :state   => data.dig('address', 'state'),
        :country => data.dig('address', 'country')
    }.compact
    @contact     = data.dig('contactDetails').transform_keys(&:to_sym)
    self
end
v2_get(resource, **opts) click to toggle source

Retrieve a resource as a JSON

@param [String] resource relative to the home @return a JSON structure

# File lib/tado/home.rb, line 138
def v2_get(resource, **opts)
    @tado.v2_get("homes/#{@id}/#{resource}", **opts)
end