redlink 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.DS_Store +0 -0
- data/.gitignore +17 -0
- data/.travis.yml +4 -0
- data/Changelog.markdown +0 -0
- data/Gemfile +17 -0
- data/LICENSE +22 -0
- data/Rakefile +14 -0
- data/Readme.markdown +1 -0
- data/bin/redlink +7 -0
- data/lib/.DS_Store +0 -0
- data/lib/redlink/.DS_Store +0 -0
- data/lib/redlink/cli.rb +50 -0
- data/lib/redlink/configuration.rb +89 -0
- data/lib/redlink/endpoint.rb +78 -0
- data/lib/redlink/location.rb +38 -0
- data/lib/redlink/redthing.rb +9 -0
- data/lib/redlink/thermostat.rb +23 -0
- data/lib/redlink/ui.rb +75 -0
- data/lib/redlink/version.rb +3 -0
- data/lib/redlink/weather.rb +24 -0
- data/lib/redlink.rb +12 -0
- data/redlink.gemspec +25 -0
- data/test/support/vcr.rb +4 -0
- data/test/test_helper.rb +15 -0
- data/wsdl/MobileV2.xml +3524 -0
- metadata +123 -0
data/.DS_Store
ADDED
Binary file
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Changelog.markdown
ADDED
File without changes
|
data/Gemfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Gem dependencies
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
# Development dependencies
|
7
|
+
gem 'rake'
|
8
|
+
gem 'yard'
|
9
|
+
|
10
|
+
# Testing dependencies
|
11
|
+
group :test do
|
12
|
+
gem 'minitest'
|
13
|
+
gem 'minitest-wscolor'
|
14
|
+
gem 'fakeweb'
|
15
|
+
gem 'vcr'
|
16
|
+
gem 'mocha', require: false
|
17
|
+
end
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Sam Soffes
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rake/testtask'
|
3
|
+
|
4
|
+
Rake::TestTask.new(:test) do |t|
|
5
|
+
t.libs << 'test'
|
6
|
+
t.pattern = 'test/**/*_test.rb'
|
7
|
+
end
|
8
|
+
|
9
|
+
desc "Open an irb session preloaded with this library"
|
10
|
+
task :console do
|
11
|
+
sh "irb -rubygems -I lib -r redlink.rb"
|
12
|
+
end
|
13
|
+
|
14
|
+
task default: :test
|
data/Readme.markdown
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Redlink
|
data/bin/redlink
ADDED
data/lib/.DS_Store
ADDED
Binary file
|
Binary file
|
data/lib/redlink/cli.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'redlink'
|
3
|
+
require 'redlink/endpoint'
|
4
|
+
|
5
|
+
module Redlink
|
6
|
+
class Cli < Thor
|
7
|
+
desc 'init TOKEN', 'Stores the app token for your Redlink application'
|
8
|
+
def init(token)
|
9
|
+
Redlink::Configuration.app_token = token
|
10
|
+
end
|
11
|
+
|
12
|
+
desc 'login USERNAME PASSWORD', 'sign in'
|
13
|
+
def login(username, password)
|
14
|
+
Redlink::Endpoint.login(username, password)
|
15
|
+
end
|
16
|
+
|
17
|
+
desc 'logout', 'srsly'
|
18
|
+
def logout
|
19
|
+
Redlink::Endpoint.logout
|
20
|
+
end
|
21
|
+
|
22
|
+
desc 'locations', 'places'
|
23
|
+
def locations
|
24
|
+
Redlink::Location.all.each do |location|
|
25
|
+
s = [location]
|
26
|
+
if location.current_weather
|
27
|
+
s << location.current_weather
|
28
|
+
end
|
29
|
+
|
30
|
+
puts s.join(' - ')
|
31
|
+
|
32
|
+
location.thermostats.each do |thermostat|
|
33
|
+
puts "\t#{thermostat}"
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
desc 'operations', 'wfasd'
|
40
|
+
def operations
|
41
|
+
p Redlink::Endpoint.endpoint_client.operations
|
42
|
+
end
|
43
|
+
|
44
|
+
desc 'session_id SESSION_ID', 'blah'
|
45
|
+
def session_id(session_id)
|
46
|
+
Redlink::Configuration.session_id = session_id
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module Redlink
|
4
|
+
class Configuration
|
5
|
+
CONFIG_FILE = '~/.redlink'
|
6
|
+
|
7
|
+
def self.app_token
|
8
|
+
config_file['app_token']
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.app_token=(val)
|
12
|
+
self.config_file['app_token'] = val
|
13
|
+
save
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.session_id
|
17
|
+
config_file['session_id']
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.session_id=(val)
|
21
|
+
config_file['session_id'] = val
|
22
|
+
if val
|
23
|
+
config_file['session_id_expires'] = Time.now + 3600 # one hour from now
|
24
|
+
else
|
25
|
+
config_file['session_id_expires'] = nil
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.session_expired?
|
30
|
+
!config_file['session_id_expires'] && config_file['session_id_expires'] < Time.now
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.user
|
34
|
+
config_file['user']
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.user=(val)
|
38
|
+
config_file['user'] = val
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.username
|
42
|
+
config_file['username']
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.username=(val)
|
46
|
+
config_file['username'] = val
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.password
|
50
|
+
config_file['password']
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.password=(val)
|
54
|
+
config_file['password'] = val
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.save
|
58
|
+
File.open(File.expand_path(CONFIG_FILE), 'w+') do |f|
|
59
|
+
f.write YAML.dump(@config_file)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.clear!
|
64
|
+
[:session_id, :user, :username, :password].each do |k|
|
65
|
+
self.send("#{k}=", nil)
|
66
|
+
end
|
67
|
+
self.save
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def self.config_file
|
73
|
+
return @config_file if @config_file
|
74
|
+
|
75
|
+
@config_file = {}
|
76
|
+
if File.exists?(path = File.expand_path(CONFIG_FILE))
|
77
|
+
begin
|
78
|
+
@config_file = YAML.load(File.read(path)) || {}
|
79
|
+
rescue TypeError => ex
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
@config_file
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'savon'
|
2
|
+
|
3
|
+
module Redlink
|
4
|
+
class Endpoint
|
5
|
+
|
6
|
+
def self.endpoint_client
|
7
|
+
@endpoint_client ||= Savon.client do
|
8
|
+
wsdl File.expand_path("../../../wsdl/MobileV2.xml", __FILE__)
|
9
|
+
log_level :warn
|
10
|
+
log false
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.login(username = Configuration.username, password = Configuration.password)
|
15
|
+
raise "A username and password is required" unless username && password
|
16
|
+
|
17
|
+
params = {
|
18
|
+
username: username,
|
19
|
+
password: password,
|
20
|
+
applicationID: Redlink::Configuration.app_token,
|
21
|
+
applicationVersion: 2,
|
22
|
+
uiLanguage: 'Default'
|
23
|
+
}
|
24
|
+
|
25
|
+
body = endpoint_client.call(:authenticate_user_login, message: params).body
|
26
|
+
p body[:authenticate_user_login_response]
|
27
|
+
if body[:authenticate_user_login_response][:authenticate_user_login_result][:result] == 'Success'
|
28
|
+
user = body[:authenticate_user_login_response][:authenticate_user_login_result][:user_info]
|
29
|
+
session_id = body[:authenticate_user_login_response][:authenticate_user_login_result][:session_id]
|
30
|
+
|
31
|
+
Configuration.username = username
|
32
|
+
Configuration.password = password
|
33
|
+
Configuration.session_id = session_id
|
34
|
+
Configuration.user = user
|
35
|
+
Configuration.save
|
36
|
+
|
37
|
+
return true
|
38
|
+
else
|
39
|
+
return false
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.logout
|
44
|
+
return unless Configuration.session_id
|
45
|
+
body = endpoint_client.call(:log_off, message: {sessionID: Configuration.session_id}).body
|
46
|
+
|
47
|
+
if body[:log_off_response][:log_off_result][:result] == 'Success'
|
48
|
+
Configuration.clear!
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.locations
|
53
|
+
verify_token
|
54
|
+
|
55
|
+
body = endpoint_client.call(:get_locations, message: {sessionID: Configuration.session_id}).body
|
56
|
+
[body[:get_locations_response][:get_locations_result][:locations]].flatten.map do |loc|
|
57
|
+
loc[:location_info]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.get_volatile_thermostat_data(thermostat_id)
|
62
|
+
verify_token
|
63
|
+
|
64
|
+
body = endpoint_client.call(:get_volatile_thermostat_data, message: {sessionID: Configuration.session_id, thermostatID: thermostat_id}).body
|
65
|
+
|
66
|
+
body[:get_volatile_thermostat_data_response][:get_volatile_thermostat_data_result][:ui]
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def self.verify_token
|
72
|
+
if Configuration.session_expired?
|
73
|
+
login
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Redlink
|
2
|
+
class Location < Redthing
|
3
|
+
attr_accessor :location_id, :name, :type, :country, :zip_code, :current_weather, :thermostats, :time_zone
|
4
|
+
|
5
|
+
def thermostats=(val)
|
6
|
+
@thermostats = val[:thermostat_info].map do |therm|
|
7
|
+
Thermostat.new(therm)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def thermostats
|
12
|
+
@thermostats
|
13
|
+
end
|
14
|
+
|
15
|
+
def current_weather=(val)
|
16
|
+
@current_weather = Weather.new(val)
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_s
|
20
|
+
name
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.all
|
24
|
+
@all ||= Endpoint.locations.map do |loc|
|
25
|
+
Location.new(loc)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.first
|
30
|
+
all[0]
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.last
|
34
|
+
all[all.length - 1]
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Redlink
|
2
|
+
class Thermostat < Redthing
|
3
|
+
attr_accessor :thermostat_id, :mac_id, :domain_id, :instance, :device_name,
|
4
|
+
:user_defined_device_name, :upgrading, :thermostats_alerts, :ui, :fan,
|
5
|
+
:humidification, :can_control_schedule, :will_support_schedule
|
6
|
+
|
7
|
+
def ui=(val)
|
8
|
+
@ui = Ui.new(val)
|
9
|
+
end
|
10
|
+
|
11
|
+
def name
|
12
|
+
user_defined_device_name || device_name
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_s
|
16
|
+
"#{name} - #{ui}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def refresh
|
20
|
+
@ui = Ui.new Endpoint.get_volatile_thermostat_data(self.thermostat_id)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/redlink/ui.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# Encoding: utf-8
|
2
|
+
|
3
|
+
module Redlink
|
4
|
+
class Ui < Redthing
|
5
|
+
attr_accessor :created, :thermostat_locked, :outdoor_temp, :disp_temperature, :heat_setpoint,
|
6
|
+
:cool_setpoint, :displayed_units, :status_heat, :status_cool, :hold_until_capable,
|
7
|
+
:schedule_capable, :vacation_hold, :dual_setpoint_status, :heat_next_period, :cool_next_period,
|
8
|
+
:heat_lower_setpt_limit, :heat_upper_setpt_limit, :cool_lower_setpt_limit, :cool_upper_setpt_limit,
|
9
|
+
:sched_heat_sp, :sched_cool_sp, :system_switch_position, :can_set_switch_auto, :can_set_switch_cool,
|
10
|
+
:can_set_switch_off, :can_set_switch_heat, :can_set_switch_emergency_heat,
|
11
|
+
:can_set_switch_southern_away, :deadband, :outdoor_humidity, :indoor_humidity, :commercial
|
12
|
+
|
13
|
+
|
14
|
+
def outdoor_temp=(val)
|
15
|
+
@outdoor_temp = val.to_f
|
16
|
+
end
|
17
|
+
|
18
|
+
def heat_setpoint=(val)
|
19
|
+
@heat_setpoint = val.to_f
|
20
|
+
end
|
21
|
+
|
22
|
+
def cool_setpoint=(val)
|
23
|
+
@cool_setpoint = val.to_f
|
24
|
+
end
|
25
|
+
|
26
|
+
def sched_heat_sp=(val)
|
27
|
+
@sched_heat_sp = val.to_f
|
28
|
+
end
|
29
|
+
|
30
|
+
def sched_cool_sp=(val)
|
31
|
+
@sched_cool_sp = val.to_f
|
32
|
+
end
|
33
|
+
|
34
|
+
def outdoor_temp=(val)
|
35
|
+
@outdoor_temp = val.to_f
|
36
|
+
end
|
37
|
+
|
38
|
+
def disp_temperature=(val)
|
39
|
+
@disp_temperature = val.to_f
|
40
|
+
end
|
41
|
+
|
42
|
+
def heating?
|
43
|
+
status_heat.to_i == 1
|
44
|
+
end
|
45
|
+
|
46
|
+
def cooling?
|
47
|
+
status_cool.to_i == 1
|
48
|
+
end
|
49
|
+
|
50
|
+
def overridden?
|
51
|
+
heat_setpoint != sched_heat_sp && cool_setpoint != sched_cool_sp
|
52
|
+
end
|
53
|
+
|
54
|
+
def status
|
55
|
+
if heating?
|
56
|
+
if overridden?
|
57
|
+
return '(heating via override)'
|
58
|
+
else
|
59
|
+
return '(heating)'
|
60
|
+
end
|
61
|
+
elsif cooling?
|
62
|
+
if overridden?
|
63
|
+
return '(cooling via override)'
|
64
|
+
else
|
65
|
+
return '(cooling)'
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def to_s
|
71
|
+
"#{disp_temperature.to_i}° / #{heat_setpoint}° #{status}"
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# Encoding: utf-8
|
2
|
+
|
3
|
+
module Redlink
|
4
|
+
class Weather < Redthing
|
5
|
+
attr_accessor :is_defined, :is_valid, :condition, :temperature, :temp_unit, :humidity, :phrase_key
|
6
|
+
|
7
|
+
def to_s
|
8
|
+
if is_defined && is_valid
|
9
|
+
"#{temperature.to_i}° #{condition}"
|
10
|
+
else
|
11
|
+
""
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def temperature=(val)
|
16
|
+
@temperature = val.to_f
|
17
|
+
end
|
18
|
+
|
19
|
+
def humidity=(val)
|
20
|
+
@humidity = val.to_f
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
data/lib/redlink.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'redlink/version'
|
2
|
+
require 'redlink/configuration'
|
3
|
+
require 'redlink/redthing'
|
4
|
+
require 'redlink/location'
|
5
|
+
require 'redlink/thermostat'
|
6
|
+
require 'redlink/ui'
|
7
|
+
require 'redlink/weather'
|
8
|
+
require 'redlink/endpoint'
|
9
|
+
|
10
|
+
module Redlink
|
11
|
+
|
12
|
+
end
|
data/redlink.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'redlink/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = 'redlink'
|
8
|
+
gem.version = Redlink::VERSION
|
9
|
+
gem.authors = ['Aaron Gotwalt']
|
10
|
+
gem.email = ['gotwalt@gmail.com']
|
11
|
+
gem.description = 'Control Redlink home thermostats'
|
12
|
+
gem.summary = gem.description
|
13
|
+
gem.homepage = 'https://github.com/gotwalt/redlink'
|
14
|
+
gem.license = 'MIT'
|
15
|
+
|
16
|
+
gem.files = `git ls-files`.split($/)
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
|
+
gem.require_paths = ['lib']
|
20
|
+
|
21
|
+
gem.required_ruby_version = '>= 1.9.2'
|
22
|
+
gem.add_dependency 'savon', '~> 2.0.2'
|
23
|
+
gem.add_dependency 'nokogiri'
|
24
|
+
gem.add_dependency 'thor'
|
25
|
+
end
|
data/test/support/vcr.rb
ADDED
data/test/test_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
Bundler.require :test
|
4
|
+
require 'minitest/autorun'
|
5
|
+
require 'mocha/setup'
|
6
|
+
require 'redlink'
|
7
|
+
|
8
|
+
# Support files
|
9
|
+
Dir["#{File.expand_path(File.dirname(__FILE__))}/support/*.rb"].each do |file|
|
10
|
+
require file
|
11
|
+
end
|
12
|
+
|
13
|
+
class RedlinkTest < MiniTest::Unit::TestCase
|
14
|
+
|
15
|
+
end
|