Class: Renstar::Thermostat
- Inherits:
-
Object
- Object
- Renstar::Thermostat
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
#settings
#control
#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_info ⇒ Object
Returns the value of attribute cached_info.
15
16
17
|
# File 'lib/renstar/thermostat.rb', line 15
def cached_info
@cached_info
end
|
#location ⇒ Object
Returns the value of attribute location.
15
16
17
|
# File 'lib/renstar/thermostat.rb', line 15
def location
@location
end
|
#usn ⇒ Object
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
42
43
|
# 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|
location = thermo[:params]['Location']
usn = thermo[:params]['USN']
Renstar::Thermostat.new(location, usn)
end
end
|
Instance Method Details
#auto(heattemp = nil, cooltemp = nil) ⇒ Object
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/renstar/thermostat.rb', line 83
def auto(heattemp = nil, cooltemp = nil)
update
heattemp ||= @cached_info.heattemp
cooltemp ||= @cached_info.cooltemp
response = control("mode": 3, "cooltemp": cooltemp, "heattemp": heattemp)
update
response
end
|
#away ⇒ Object
132
133
134
135
136
|
# File 'lib/renstar/thermostat.rb', line 132
def away
response = settings("away": 1)
update
response
end
|
#cool(cooltemp = nil) ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/renstar/thermostat.rb', line 69
def cool(cooltemp = nil)
update
if cooltemp
heattemp = cooltemp.to_i - 1
else
cooltemp = @cached_info.cooltemp
heattemp = @cached_info.heattemp
end
response = control("mode": 2, "cooltemp": cooltemp, "heattemp": heattemp)
update
response
end
|
#fan_off ⇒ Object
94
95
96
97
98
|
# File 'lib/renstar/thermostat.rb', line 94
def fan_off
response = control("fan": 0)
update
response
end
|
#fan_on ⇒ Object
100
101
102
103
104
|
# File 'lib/renstar/thermostat.rb', line 100
def fan_on
response = control("fan": 1)
update
response
end
|
#fan_toggle ⇒ Object
106
107
108
|
# File 'lib/renstar/thermostat.rb', line 106
def fan_toggle
@cached_info.fan == 1 ? fan_off : fan_on
end
|
#heat(heattemp = nil) ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/renstar/thermostat.rb', line 56
def heat(heattemp = nil)
update
if heattemp
cooltemp = heattemp.to_i + 1
else
cooltemp = @cached_info.cooltemp
heattemp = @cached_info.heattemp
end
response = control("mode": 1, "cooltemp": cooltemp, "heattemp": heattemp)
update
response
end
|
#home ⇒ Object
126
127
128
129
130
|
# File 'lib/renstar/thermostat.rb', line 126
def home
response = settings("away": 0)
update
response
end
|
#off ⇒ Object
50
51
52
53
54
|
# File 'lib/renstar/thermostat.rb', line 50
def off
response = control("mode": 0, "cooltemp": @cached_info.cooltemp, "heattemp": @cached_info.heattemp)
update
response
end
|
#schedule_off ⇒ Object
110
111
112
113
114
|
# File 'lib/renstar/thermostat.rb', line 110
def schedule_off
response = settings("schedule": 0)
update
response
end
|
#schedule_on ⇒ Object
116
117
118
119
120
|
# File 'lib/renstar/thermostat.rb', line 116
def schedule_on
response = settings("schedule": 1)
update
response
end
|
#schedule_toggle ⇒ Object
122
123
124
|
# File 'lib/renstar/thermostat.rb', line 122
def schedule_toggle
@cached_info.schedule == 1 ? schedule_off : schedule_on
end
|
#update ⇒ Object
45
46
47
48
|
# File 'lib/renstar/thermostat.rb', line 45
def update
@cache_timestamp = Time.now
@cached_info = info
end
|