ruby_myq 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3e25cbc16593c4ee50cf10fac89b571b6c79cbd441d17498f19848821bd88549
4
+ data.tar.gz: 2f2d1f28ed2d5cff5aef474d8596731c5d829b4de942013cfa6f4a57eecd7209
5
+ SHA512:
6
+ metadata.gz: ae89e6cb88e2b754b752c92782bc061031090e90124ef14c5d7052befd5ba1e6bcf513d94a9a21166f449c368670e44bbade7d5a64f5b36ab0caae772504fde5
7
+ data.tar.gz: b752f51c0564e8f77f38b5d8e1fcbfcadf9a28a1643f1b0e256bfea78d9d33fc4f95c621886c8983ac9bbdf3af2c06c8fac7a1891e85073c19877044c9c4e39a
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+
19
+ sandbox.rb
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in ruby_myq.gemspec
6
+ gemspec
7
+
8
+ gem 'irb', require: false
9
+ gem 'rubocop', require: false
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 David Pfeffer
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.
@@ -0,0 +1,48 @@
1
+ # RubyMyq
2
+
3
+ Ruby gem to control a Chaimberlain ruby MyQ system.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'ruby_myq'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install ruby_myq-X.X.X.gem (Note: X.X.X should be changed to the current version number)
18
+
19
+ ## Usage
20
+
21
+ To create the gem:
22
+
23
+ $ gem build /path/to/ruby_myq/ruby_myq.gemspec
24
+
25
+ To instantiate the system:
26
+
27
+ $ require 'ruby_myq'
28
+ $ system = RubyMyq::System.new('your_username','your_password')
29
+
30
+ To see your device list in all it's ruby glory:
31
+
32
+ $ system.gateways
33
+ $ system.garage_doors
34
+ $ system.garage_doors.count
35
+
36
+ Have fun with:
37
+
38
+ $ system.garage_doors[0].open
39
+ $ system.garage_doors[0].close
40
+ $ system.garage_doors[0].status
41
+
42
+ ## Contributing
43
+
44
+ 1. Fork it
45
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
46
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
47
+ 4. Push to the branch (`git push origin my-new-feature`)
48
+ 5. Create new Pull Request
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
@@ -0,0 +1,65 @@
1
+ FORMAT: 1A
2
+ HOST: http://myqexternal.myqdevice.com
3
+
4
+ # Chamberlain Liftmaster MyQ API
5
+ This is unofficial (and partial) documentation of the Chamberlain/Liftmaster MyQ API used by the iOS and Android apps. It features functionality to monitor and control the garage door system remotely. A ruby gem implementation of this API is available at http://github.com/pfeffed/liftmaster_myq.
6
+
7
+ ## Constant Values
8
+ This API has some static values:
9
+
10
+ Application Id = "Vj8pQggXLhLy0WHahglCD4N1nAkkXQtGYpq2HrHD7H1nvmbT55KqtN6RSF4ILB%2fi"
11
+
12
+ Culture = 'en' (Note: other regions may be supported as well)
13
+
14
+ ## Login [/Membership/ValidateUserWithCulture?appId={appId}&securityToken=null&username={username}&password={password}&culture={culture}]
15
+ ### Send login request [GET]
16
+ You should only need to store the securityToken in the response for subsequent requests. Also, I have noticed that sometimes the call to login returns a token that does not work. From time to time, I have found that retrying the login call once or twice gets one that works.
17
+ + Parameters
18
+ + appId (required, string) ... This appears to be a constant string value associated with the mobile app.
19
+ + username (required, string) ... The account's email address in url encoded format (i.e. someone@test.com -> someone%40test.com).
20
+ + password (required, string) ... The account password in url encoded format.
21
+ + culture (required, string) ... This appears to be the country code. I have only tried it with 'en'.
22
+
23
+ + Response 200 (application/json)
24
+
25
+ {"UserId":987654,"SecurityToken":"YOUR_TOKEN_HERE","ReturnCode":"0","ErrorMessage":"","ExecutionTimes":"15.6;46.8;78;62.4","BrandId":2,"BrandName":"Chamberlain"}
26
+
27
+ ## System Detail [/api/UserDeviceDetails?appId={appId}&securityToken={securityToken}]
28
+ ### Get devices and information about the MyQ system [GET]
29
+ The security token is the one received from the login request. If the system comes back without any MyQ units, it may be a sign your login token needs to be refreshed.
30
+ + Parameters
31
+ + appId (required, string) ... This appears to be a static string associated with the mobile app.
32
+ + securityToken (required, string) ... This appears to be a static string associated with the mobile app.
33
+
34
+ + Response 200 (application/json)
35
+
36
+ {"Devices":[{"MyQDeviceId":987654321098,"MyQDeviceTypeId":1,"MyQDeviceTypeName":"Gateway","DeviceId":"876543","DeviceName":"GW000000XXXX","TypeId":49,"TypeName":"Gateway","RegistrationDateTime":"2013-10-12T13:26:38.48","SerialNumber":"GW000000XXXX","UserName":"YOUR-USERNAME","UserConnectServerId":0,"UserCountryId":0,"Attributes":[{"Name":"deviceRecord.response","Value":"{\"id\":987654321,\"deviceCode\":{\"login\":\"XXXXXXXXXXX\",\"password\":\"XX\"},\"type\":{\"id\":47,\"nativeID\":131},\"version\":{\"major\":1,\"minor\":80,\"revision\":1024}}","UpdatedTime":"1382133086081","MyQDeviceTypeAttributeId":0,"IsDeviceProperty":false,"IsPersistent":false,"IsTimeSeries":false,"IsGlobal":false,"UpdatedDate":"0001-01-01T00:00:00"},{"Name":"learnmodestate","Value":"0","UpdatedTime":"1384058789400","MyQDeviceTypeAttributeId":3,"IsDeviceProperty":false,"IsPersistent":false,"IsTimeSeries":false,"IsGlobal":false,"UpdatedDate":"0001-01-01T00:00:00"},{"Name":"hwver","Value":"1.0","UpdatedTime":"1384990618614","MyQDeviceTypeAttributeId":34,"IsDeviceProperty":false,"IsPersistent":false,"IsTimeSeries":false,"IsGlobal":false,"UpdatedDate":"0001-01-01T00:00:00"},{"Name":"desc","Value":"YOUR-GATEWAY-NAME","UpdatedTime":"1382133367601","MyQDeviceTypeAttributeId":28,"IsDeviceProperty":false,"IsPersistent":false,"IsTimeSeries":false,"IsGlobal":false,"UpdatedDate":"0001-01-01T00:00:00"},{"Name":"enumeraterequired","Value":"0","UpdatedTime":"1384925170098","MyQDeviceTypeAttributeId":1,"IsDeviceProperty":false,"IsPersistent":false,"IsTimeSeries":false,"IsGlobal":false,"UpdatedDate":"0001-01-01T00:00:00"},{"Name":"devtype","Value":"6","UpdatedTime":"1384058783970","MyQDeviceTypeAttributeId":31,"IsDeviceProperty":false,"IsPersistent":false,"IsTimeSeries":false,"IsGlobal":false,"UpdatedDate":"0001-01-01T00:00:00"},{"Name":"fwver","Value":"3.0","UpdatedTime":"1384990618527","MyQDeviceTypeAttributeId":33,"IsDeviceProperty":false,"IsPersistent":false,"IsTimeSeries":false,"IsGlobal":false,"UpdatedDate":"0001-01-01T00:00:00"},{"Name":"devicetablechecksum","Value":"0","UpdatedTime":"1382133351232","MyQDeviceTypeAttributeId":5,"IsDeviceProperty":false,"IsPersistent":false,"IsTimeSeries":false,"IsGlobal":false,"UpdatedDate":"0001-01-01T00:00:00"},{"Name":"enumeratetimestamp","Value":"10/18/2013 4:51:24 PM","UpdatedTime":"1382133085152","MyQDeviceTypeAttributeId":7,"IsDeviceProperty":false,"IsPersistent":false,"IsTimeSeries":false,"IsGlobal":false,"UpdatedDate":"0001-01-01T00:00:00"},{"Name":"removeAllDevices.response","Value":"1","UpdatedTime":"1382133084644","MyQDeviceTypeAttributeId":0,"IsDeviceProperty":false,"IsPersistent":false,"IsTimeSeries":false,"IsGlobal":false,"UpdatedDate":"0001-01-01T00:00:00"},{"Name":"blver","Value":"1.0","UpdatedTime":"1384990618699","MyQDeviceTypeAttributeId":35,"IsDeviceProperty":false,"IsPersistent":false,"IsTimeSeries":false,"IsGlobal":false,"UpdatedDate":"0001-01-01T00:00:00"},{"Name":"devices","Value":"XXXXXXXXX","UpdatedTime":"1382133351238","MyQDeviceTypeAttributeId":25,"IsDeviceProperty":false,"IsPersistent":false,"IsTimeSeries":false,"IsGlobal":false,"UpdatedDate":"0001-01-01T00:00:00"},{"Name":"deviceCount.response","Value":"{\"checkSum\":381,\"deviceCount\":1}","UpdatedTime":"1382133085519","MyQDeviceTypeAttributeId":0,"IsDeviceProperty":false,"IsPersistent":false,"IsTimeSeries":false,"IsGlobal":false,"UpdatedDate":"0001-01-01T00:00:00"},{"Name":"desiredlearnmode","Value":"0","UpdatedTime":"1384058789403","MyQDeviceTypeAttributeId":2,"IsDeviceProperty":false,"IsPersistent":false,"IsTimeSeries":false,"IsGlobal":false,"UpdatedDate":"0001-01-01T00:00:00"},{"Name":"deviceName","Value":"987654321098","UpdatedTime":"","MyQDeviceTypeAttributeId":104,"IsDeviceProperty":false,"IsPersistent":false,"IsTimeSeries":false,"IsGlobal":false,"UpdatedDate":"0001-01-01T00:00:00"},{"Name":"customerName","Value":"987654321098","UpdatedTime":"","MyQDeviceTypeAttributeId":4,"IsDeviceProperty":false,"IsPersistent":false,"IsTimeSeries":false,"IsGlobal":false,"UpdatedDate":"0001-01-01T00:00:00"}],"UpdatedBy":"EXT_API","UpdatedDate":"2013-10-18T21:51:24.68"},{"MyQDeviceId":987654,"ParentMyQDeviceId":87654,"MyQDeviceTypeId":2,"MyQDeviceTypeName":"GarageDoorOpener","DeviceId":"XXXXXXXXX","DeviceName":"987654321098","TypeId":47,"TypeName":"Garage Door Opener","UserName":"YOUR-USERNAME","UserConnectServerId":0,"UserCountryId":0,"Attributes":[{"Name":"learnmode","Value":"0","UpdatedTime":"1385071490018","MyQDeviceTypeAttributeId":55,"IsDeviceProperty":false,"IsPersistent":false,"IsTimeSeries":false,"IsGlobal":false,"UpdatedDate":"0001-01-01T00:00:00"},{"Name":"aclossdetect","Value":"0","UpdatedTime":"1385071490018","MyQDeviceTypeAttributeId":57,"IsDeviceProperty":false,"IsPersistent":false,"IsTimeSeries":false,"IsGlobal":false,"UpdatedDate":"0001-01-01T00:00:00"},{"Name":"flasherconnect","Value":"0","UpdatedTime":"1385071490018","MyQDeviceTypeAttributeId":58,"IsDeviceProperty":false,"IsPersistent":false,"IsTimeSeries":false,"IsGlobal":false,"UpdatedDate":"0001-01-01T00:00:00"},{"Name":"worklightstate","Value":"1","UpdatedTime":"1385071490018","MyQDeviceTypeAttributeId":51,"IsDeviceProperty":false,"IsPersistent":false,"IsTimeSeries":false,"IsGlobal":false,"UpdatedDate":"0001-01-01T00:00:00"},{"Name":"gatewayID","Value":"XXXXXX","UpdatedTime":"1382133351237","MyQDeviceTypeAttributeId":49,"IsDeviceProperty":false,"IsPersistent":false,"IsTimeSeries":false,"IsGlobal":false,"UpdatedDate":"0001-01-01T00:00:00"},{"Name":"online","Value":"","UpdatedTime":"1384990647995","MyQDeviceTypeAttributeId":0,"IsDeviceProperty":false,"IsPersistent":false,"IsTimeSeries":false,"IsGlobal":false,"UpdatedDate":"0001-01-01T00:00:00"},{"Name":"desireddoorstate","Value":"","UpdatedTime":"1385071490018","MyQDeviceTypeAttributeId":41,"IsDeviceProperty":false,"IsPersistent":false,"IsTimeSeries":false,"IsGlobal":false,"UpdatedDate":"0001-01-01T00:00:00"},{"Name":"desc","Value":"Garage Door Opener","UpdatedTime":"1382133355790","MyQDeviceTypeAttributeId":50,"IsDeviceProperty":false,"IsPersistent":false,"IsTimeSeries":false,"IsGlobal":false,"UpdatedDate":"0001-01-01T00:00:00"},{"Name":"doorstate","Value":"2","UpdatedTime":"1385067858624","MyQDeviceTypeAttributeId":56,"IsDeviceProperty":false,"IsPersistent":false,"IsTimeSeries":false,"IsGlobal":false,"UpdatedDate":"0001-01-01T00:00:00"},{"Name":"controlledlightfeature","Value":"0","UpdatedTime":"1385071490018","MyQDeviceTypeAttributeId":43,"IsDeviceProperty":false,"IsPersistent":false,"IsTimeSeries":false,"IsGlobal":false,"UpdatedDate":"0001-01-01T00:00:00"},{"Name":"diagnosticerrorstate","Value":"0","UpdatedTime":"1385071490018","MyQDeviceTypeAttributeId":54,"IsDeviceProperty":false,"IsPersistent":false,"IsTimeSeries":false,"IsGlobal":false,"UpdatedDate":"0001-01-01T00:00:00"},{"Name":"addedtime","Value":"2013-10-18 21:55:51","UpdatedTime":"1382133351237","MyQDeviceTypeAttributeId":61,"IsDeviceProperty":false,"IsPersistent":false,"IsTimeSeries":false,"IsGlobal":false,"UpdatedDate":"0001-01-01T00:00:00"},{"Name":"vacationmode","Value":"0","UpdatedTime":"1385071490018","MyQDeviceTypeAttributeId":52,"IsDeviceProperty":false,"IsPersistent":false,"IsTimeSeries":false,"IsGlobal":false,"UpdatedDate":"0001-01-01T00:00:00"},{"Name":"radiolearnmode","Value":"0","UpdatedTime":"1385071490018","MyQDeviceTypeAttributeId":53,"IsDeviceProperty":false,"IsPersistent":false,"IsTimeSeries":false,"IsGlobal":false,"UpdatedDate":"0001-01-01T00:00:00"},{"Name":"isunattendedopenallowed","Value":"1","UpdatedTime":"1385071490018","MyQDeviceTypeAttributeId":77,"IsDeviceProperty":false,"IsPersistent":false,"IsTimeSeries":false,"IsGlobal":false,"UpdatedDate":"0001-01-01T00:00:00"},{"Name":"isunattendedcloseallowed","Value":"1","UpdatedTime":"1385071490018","MyQDeviceTypeAttributeId":78,"IsDeviceProperty":false,"IsPersistent":false,"IsTimeSeries":false,"IsGlobal":false,"UpdatedDate":"0001-01-01T00:00:00"},{"Name":"requestdevicestatus","Value":"","UpdatedTime":"1385071490018","MyQDeviceTypeAttributeId":59,"IsDeviceProperty":false,"IsPersistent":false,"IsTimeSeries":false,"IsGlobal":false,"UpdatedDate":"0001-01-01T00:00:00"},{"Name":"deviceName","Value":"987654321098","UpdatedTime":"","MyQDeviceTypeAttributeId":103,"IsDeviceProperty":false,"IsPersistent":false,"IsTimeSeries":false,"IsGlobal":false,"UpdatedDate":"0001-01-01T00:00:00"},{"Name":"customerName","Value":"987654321098","UpdatedTime":"","MyQDeviceTypeAttributeId":75,"IsDeviceProperty":false,"IsPersistent":false,"IsTimeSeries":false,"IsGlobal":false,"UpdatedDate":"0001-01-01T00:00:00"}],"UpdatedBy":"EXT_API","UpdatedDate":"2013-10-18T21:55:52.167"}],"ReturnCode":"0","ErrorMessage":""}
37
+
38
+ ## Toggle Device State [/Device/setDeviceAttribute]
39
+ ### Open or close the door (and turn lights on/off?) [PUT]
40
+
41
+ {
42
+ "AttributeName":"requestdevicestatus",
43
+ "DeviceId":"987654321098",
44
+ "ApplicationId":"APPID-FROM-CONSTANTS",
45
+ "AttributeValue":"1",
46
+ "SecurityToken":"YOUR-TOKEN"
47
+ }
48
+
49
+ + Response 200 (application/json)
50
+
51
+ {"UpdatedTime":"1385071721231","ReturnCode":"0"}
52
+
53
+ ## Check Device State [/Device/getDeviceAttribute?appId={appId}&securityToken={securityToken}&devId={deviceId}&name={command}]
54
+ ### Get the status of a particular device attribute [GET]
55
+ This can be used to check to see if a garage door is open, closed, opening, or closing. There are probably more uses that I have not yet needed.
56
+ + Parameters
57
+ + appId (required, string) ... This appears to be a static string associated with the mobile app.
58
+ + securityToken (required, string) ... This appears to be a static string associated with the mobile app.
59
+ + deviceId (required, string) ... This is the id or deviceId returned in the System Detail call to endpoint /api/UserDeviceDetails referenced above.
60
+ + command (required, string) ... I have only tried using 'doorstate'
61
+
62
+ + Response 200 (application/json)
63
+
64
+ {"AttributeValue":"2","UpdatedTime":"1385067858624","ReturnCode":"0","ErrorMessage":""}
65
+
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ruby_myq/version'
4
+ require 'ruby_myq/system'
5
+ require 'ruby_myq/device'
6
+
7
+ module RubyMyq
8
+ APP_ID = 'Vj8pQggXLhLy0WHahglCD4N1nAkkXQtGYpq2HrHD7H1nvmbT55KqtN6RSF4ILB%2Fi'
9
+ LOCALE = 'en'
10
+
11
+ API_VERSION = 'v5'
12
+ APP_VERSION = 'v5.1'
13
+
14
+ HOST_URI = 'api.myqdevice.com/api'
15
+ LOGIN_ENDPOINT = 'Login'
16
+ ACCOUNT_ENDPOINT = 'My'
17
+ DEVICE_LIST_ENDPOINT = 'Devices'
18
+ DEVICE_SET_ENDPOINT = 'Device/setDeviceAttribute'
19
+ DEVICE_STATUS_ENDPOINT = '/Device/getDeviceAttribute'
20
+
21
+ HEADERS = {
22
+ 'Content-Type' => 'application/json',
23
+ 'MyQApplicationId' => 'JVM/G9Nwih5BwKgNCjLxiFUQxQijAebyyg8QUHr7JOrP+tuPb8iHfRHKwTmDzHOu',
24
+ 'User-Agent' => 'okhttp/3.10.0',
25
+ 'BrandId' => '2',
26
+ 'Culture' => 'en'
27
+ }.freeze
28
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyMyq
4
+ module Device
5
+ end
6
+ end
7
+
8
+ require 'ruby_myq/device/base'
9
+ require 'ruby_myq/device/garage_door'
10
+ require 'ruby_myq/device/gateway'
11
+ require 'ruby_myq/device/light_switch'
@@ -0,0 +1,19 @@
1
+ module RubyMyq::Device
2
+ class Base
3
+
4
+ attr_reader :id, :name, :myq_id, :myq_name, :parent_system, :cached_hash
5
+
6
+ def initialize(device)
7
+ @cached_hash = device_hash
8
+ @parent_system = parent_system
9
+ @id = device_hash["DeviceId"]
10
+ device_hash["Attributes"].each do |elem|
11
+ @name = elem["Value"] if elem["Name"] == "desc"
12
+ end
13
+ @myq_id = device_hash["MyQDeviceId"]
14
+ @myq_name = device_hash["DeviceName"]
15
+ @device_type = device_hash["MyQDeviceTypeName"]
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ruby_myq/device'
4
+
5
+ module RubyMyq
6
+ module Device
7
+ class GarageDoor
8
+ def initialize(device, headers)
9
+ @device = device
10
+ @headers = headers
11
+ # API response includes incorrect verion number and http rather than https
12
+ @device_uri = @device['href'].gsub(/v5/, 'v5.1').gsub(/http/, 'https')
13
+ end
14
+
15
+ def name
16
+ @device['name']
17
+ end
18
+
19
+ def open
20
+ change_door_state('open')
21
+ end
22
+
23
+ def close
24
+ change_door_state('close')
25
+ end
26
+
27
+ def status
28
+ state = request_door_state
29
+ state['door_state']
30
+ end
31
+
32
+ def status_since
33
+ state = request_door_state
34
+ state['last_update']
35
+ end
36
+
37
+ private
38
+
39
+ def request_door_state
40
+ options = {
41
+ headers: @headers,
42
+ format: :json
43
+ # debug_output: STDOUT
44
+ }
45
+ response = HTTParty.get(@device_uri, options)
46
+ response['state']
47
+ end
48
+
49
+ def change_door_state(command)
50
+ action_uri = @device_uri + '/Actions'
51
+
52
+ options = {
53
+ headers: @headers,
54
+ body: { action_type: command }.to_json,
55
+ format: :json
56
+ # debug_output: STDOUT
57
+ }
58
+ HTTParty.put(action_uri, options)
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ruby_myq/device'
4
+
5
+ module RubyMyq
6
+ module Device
7
+ class Gateway < Base
8
+ def status; end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ruby_myq/device'
4
+
5
+ module RubyMyq
6
+ module Device
7
+ class LightSwitch < Base
8
+ def on; end
9
+
10
+ def off; end
11
+
12
+ def status; end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,115 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'uri'
4
+ require 'httparty'
5
+
6
+ module RubyMyq
7
+ class System
8
+ attr_reader :garage_doors
9
+ def initialize(user, pass)
10
+ @username = user
11
+ @password = pass
12
+ login(@username, @password)
13
+ request_account
14
+ discover_endpoints
15
+ end
16
+
17
+ def discover_endpoints
18
+ empty_device_arrays
19
+ response = request_device_list
20
+ devices = response['items']
21
+ devices.each do |device|
22
+ instantiate_device(device, @headers)
23
+ end
24
+ end
25
+
26
+ def find_door_by_id(id)
27
+ id = id.to_s
28
+ @garage_doors.each do |door|
29
+ return door if door.id == id
30
+ end
31
+ nil
32
+ end
33
+
34
+ def find_door_by_name(name)
35
+ @garage_doors.each do |door|
36
+ return door if door.name == name
37
+ end
38
+ nil
39
+ end
40
+
41
+ # private
42
+
43
+ def login_uri
44
+ uri = ''.dup
45
+ uri << "https://#{RubyMyq::HOST_URI}/"
46
+ uri << "#{RubyMyq::API_VERSION}/"
47
+ uri << RubyMyq::LOGIN_ENDPOINT
48
+ end
49
+
50
+ def request_account_uri
51
+ uri = ''.dup
52
+ uri << "https://#{RubyMyq::HOST_URI}/"
53
+ uri << "#{RubyMyq::API_VERSION}/"
54
+ uri << RubyMyq::ACCOUNT_ENDPOINT
55
+ end
56
+
57
+ def login(username, password)
58
+ options = {
59
+ headers: RubyMyq::HEADERS,
60
+ body: { username: username, password: password }.to_json,
61
+ format: :json
62
+ # debug_output: STDOUT
63
+ }
64
+
65
+ response = HTTParty.post(login_uri, options)
66
+ @security_token = response['SecurityToken']
67
+ @headers = {}.dup
68
+ @headers.merge!(RubyMyq::HEADERS)
69
+ @headers.merge!(SecurityToken: @security_token)
70
+ # @cached_login_response = response
71
+ # "logged in successfully"
72
+ end
73
+
74
+ def request_account
75
+ options = {
76
+ headers: @headers,
77
+ body: { expand: 'account' }.to_json,
78
+ format: :json
79
+ # debug_output: STDOUT
80
+ }
81
+
82
+ response = HTTParty.get(request_account_uri, options)
83
+ @account_uri = response['Account']['href'].gsub(/v5/, 'v5.1')
84
+ end
85
+
86
+ def request_device_list
87
+ uri = "#{@account_uri}/#{RubyMyq::DEVICE_LIST_ENDPOINT}"
88
+
89
+ options = {
90
+ headers: @headers,
91
+ format: :json
92
+ # debug_output: STDOUT
93
+ }
94
+
95
+ HTTParty.get(uri, options)
96
+ end
97
+
98
+ def empty_device_arrays
99
+ @gateways = []
100
+ @garage_doors = []
101
+ @lights = []
102
+ end
103
+
104
+ def instantiate_device(device, _headers)
105
+ if device['device_type'] == 'garagedooropener'
106
+ @garage_doors << RubyMyq::Device::GarageDoor.new(device, @headers)
107
+ # elsif device["device_type"] == "hub"
108
+ # @gateways << RubyMyq::Device::Gateway.new(device, self)
109
+ # elsif device["MyQDeviceTypeName"]=="???"
110
+ # I need a MyQ light switch to implement this feature
111
+ # @lights << RubyMyq::Device::LightSwitch.new(device)
112
+ end
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyMyq
4
+ VERSION = '0.0.1'
5
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'ruby_myq/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'ruby_myq'
9
+ spec.version = RubyMyq::VERSION
10
+ spec.authors = ['Jesse Gillies']
11
+ spec.email = ['jessegillies@gmail.com']
12
+ spec.description = 'Unofficial controller for Chamberlain/Liftmaster MyQ'
13
+ spec.summary = 'Gem to access and control the Chamberlain/Liftmaster MyQ garage door system.'
14
+ spec.homepage = 'http://github.com/jgillies/ruby_myq'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_dependency 'httparty', '~> 0.12.0'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.3'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby_myq
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jesse Gillies
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-10-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.12.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.12.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: Unofficial controller for Chamberlain/Liftmaster MyQ
56
+ email:
57
+ - jessegillies@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - apiary.apib
68
+ - lib/ruby_myq.rb
69
+ - lib/ruby_myq/device.rb
70
+ - lib/ruby_myq/device/base.rb
71
+ - lib/ruby_myq/device/garage_door.rb
72
+ - lib/ruby_myq/device/gateway.rb
73
+ - lib/ruby_myq/device/light_switch.rb
74
+ - lib/ruby_myq/system.rb
75
+ - lib/ruby_myq/version.rb
76
+ - ruby_myq.gemspec
77
+ homepage: http://github.com/jgillies/ruby_myq
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubygems_version: 3.0.3
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Gem to access and control the Chamberlain/Liftmaster MyQ garage door system.
100
+ test_files: []