class Tado::Zone

Class wrapping interaction with the Tado Zone

Attributes

dazzle[R]

Dazze mode

@return [nil] not supported @return [Boolean] is dazzle mode enabled

devices[R]

Devices associated with this zone

@return [Array<Device>] list of devices

id[R]

Zone identifier

@return [Integer] identifier

name[R]

Name of zone

@return [String] name

open_window[R]

Open window detection

@return [nil] not supported @return [Boolean] is window detection enabled

open_window_timeout[R]

Open window timeout

@return [nil] not supported @return [Integer] is window detection enabled

type[R]

Type of zone (heating, airconditioning)

@return [:HEATING] heating zone @return [Symbol]

Public Class Methods

from_json(json, home:) click to toggle source

Create a zone instance associated to the home from the JSON returned by the Tado API

@param json [Object] json returned by the Tado API @param home [Home ] home to which this zone belongs

# File lib/tado/zone.rb, line 11
def self.from_json(json, home:)
    self.new(json.dig('id'),
             data: self.parse_from_json(json),
             home: home)
end
new(id, data:, home:) click to toggle source

Create a zone instance associated to the home

@param id [String] home identifier @param home [Home ] home to which this zone belongs @param data [Hash{Symbol => Object}] initialising data

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

    data&.each {|k, v| instance_variable_set("@#{k}", v) }
end

Private Class Methods

parse_from_json(json) click to toggle source
# File lib/tado/zone.rb, line 110
def self.parse_from_json(json)
    supported_enabled = ->(d) {
        d.dig('supported') ? d.dig('enabled') : nil }
    {
        :name        => json.dig('name'),
        :type        => json.dig('type'),
        :created     => Time.parse(json.dig('dateCreated')),
        :devices     => json.dig('devices').map {|data|
                           Device.from_json(data, zone: self) },
        :dazzle      => supported_enabled.(json.dig('dazzleMode')),
        :open_window => supported_enabled.(json.dig('openWindowDetection')),
        :open_window_timeout => json.dig('openWindowDetection', 'timeoutInSeconds'),
    }
end

Public Instance Methods

getHistory(date = Date.today) click to toggle source

Retrieve history (temperature, humidity, …) for this zone

@param date [String] date in yyyy-mm-dd format @return [Hash{Symbol => Object}] history of the given day. For example:

{ :wheather => {
    :condition => [ [ timeFrom..timeTo, state, temperature ]... ],
    :sunny     => [ [ timeFrom..timeTo, is_sunny ]... ],
    :slots     => { 'hh:mm' => [ state, temperature ] } },
  :settings => [ [ timeFrom..timeTo, type, powered, temperature ]... ],
  :measure  => {
    :temperature      => [ [ time, temperature ]... ],
    :humidity         => [ [ time, humidity ]... ],
    :device_connected => [ [ timeFrom..timeTo, is_connected ]... ] },
  :stripes => [ [ timeFrom..timeTo, mode, type, is_powerd, temperature ]... ]
}
# File lib/tado/zone.rb, line 94
def getHistory(date = Date.today)
    History.get(date, zone: self)
end
v2_get(resource, **opts) click to toggle source

Retrieve a resource as a JSON

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

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