Class: Renstar::Thermostat

Inherits:
Object
  • Object
show all
Extended by:
Discovery
Includes:
APIClient
Defined in:
lib/renstar/thermostat.rb

Overview

Thermostat object Contains convenience methods along the lines of what is provided in the mobile app, website, or control panel, e.g. Heat, Cool, Auto, Fan, Schedule Home/Away, and Off

Constant Summary collapse

USN_REGEX =
/^(\w+):(\w+)+:((?:[0-9a-fA-F]{2}:?)+):name:(.*):type:(.*)/

Constants included from Discovery

Discovery::SERVICE

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from APIClient

#get, key_to_description, #post, value_to_formatted

Methods included from APIClient::Settings

#settings

Methods included from APIClient::Control

#control

Methods included from APIClient::Query

#alerts, #info, #runtimes, #sensors

Constructor Details

#initialize(location, usn = nil) ⇒ Thermostat

Returns a new instance of Thermostat.



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/renstar/thermostat.rb', line 20

def initialize(location, usn = nil)
  if location && usn
    @location = location
    @usn = usn
  else
    @location = "http://#{location}/"
    @usn = ''
  end

  @cache_timestamp = Time.now
  @cached_info = info
end

Instance Attribute Details

#cached_infoObject (readonly)

Returns the value of attribute cached_info.



15
16
17
# File 'lib/renstar/thermostat.rb', line 15

def cached_info
  @cached_info
end

#locationObject (readonly)

Returns the value of attribute location.



15
16
17
# File 'lib/renstar/thermostat.rb', line 15

def location
  @location
end

#usnObject (readonly)

Returns the value of attribute usn.



15
16
17
# File 'lib/renstar/thermostat.rb', line 15

def usn
  @usn
end

Class Method Details

.search(timeout = 3) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/renstar/thermostat.rb', line 33

def self.search(timeout = 3)
  all_thermos = ips.each do |ip|
    all_thermos << ssdp_search(ip, timeout)
  end

  all_thermos.flatten.map do |thermo|
    Renstar::Thermostat.new(thermo[:params]['Location'], thermo[:params]['USN'])
  end
end

Instance Method Details

#auto(heattemp = nil, cooltemp = nil) ⇒ Object



68
69
70
71
72
73
74
75
76
77
# File 'lib/renstar/thermostat.rb', line 68

def auto(heattemp = nil, cooltemp = nil)
  # we want to make sure we have the latest values
  # so we'll update then set the defaults
  update
  heattemp ||= @cached_info.heattemp
  cooltemp ||= @cached_info.cooltemp
  response = control("mode": 3, "cooltemp": cooltemp, "heattemp": heattemp)
  update
  response
end

#awayObject



117
118
119
120
121
# File 'lib/renstar/thermostat.rb', line 117

def away
  response = settings("away": 1)
  update
  response
end

#cool(cooltemp = nil) ⇒ Object



61
62
63
64
65
66
# File 'lib/renstar/thermostat.rb', line 61

def cool(cooltemp = nil)
  cooltemp, heattemp = set_temps(cooltemp, 2)
  response = control("mode": 2, "cooltemp": cooltemp, "heattemp": heattemp)
  update
  response
end

#fan_offObject



79
80
81
82
83
# File 'lib/renstar/thermostat.rb', line 79

def fan_off
  response = control("fan": 0)
  update
  response
end

#fan_onObject



85
86
87
88
89
# File 'lib/renstar/thermostat.rb', line 85

def fan_on
  response = control("fan": 1)
  update
  response
end

#fan_toggleObject



91
92
93
# File 'lib/renstar/thermostat.rb', line 91

def fan_toggle
  @cached_info.fan == 1 ? fan_off : fan_on
end

#heat(heattemp = nil) ⇒ Object



54
55
56
57
58
59
# File 'lib/renstar/thermostat.rb', line 54

def heat(heattemp = nil)
  cooltemp, heattemp = set_temps(heattemp, 1)
  response = control("mode": 1, "cooltemp": cooltemp, "heattemp": heattemp)
  update
  response
end

#homeObject



111
112
113
114
115
# File 'lib/renstar/thermostat.rb', line 111

def home
  response = settings("away": 0)
  update
  response
end

#offObject



48
49
50
51
52
# File 'lib/renstar/thermostat.rb', line 48

def off
  response = control("mode": 0, "cooltemp": @cached_info.cooltemp, "heattemp": @cached_info.heattemp)
  update
  response
end

#schedule_offObject



95
96
97
98
99
# File 'lib/renstar/thermostat.rb', line 95

def schedule_off
  response = settings("schedule": 0)
  update
  response
end

#schedule_onObject



101
102
103
104
105
# File 'lib/renstar/thermostat.rb', line 101

def schedule_on
  response = settings("schedule": 1)
  update
  response
end

#schedule_toggleObject



107
108
109
# File 'lib/renstar/thermostat.rb', line 107

def schedule_toggle
  @cached_info.schedule == 1 ? schedule_off : schedule_on
end

#updateObject



43
44
45
46
# File 'lib/renstar/thermostat.rb', line 43

def update
  @cache_timestamp = Time.now
  @cached_info = info
end