Skip to content

Commit

Permalink
update endpoints, update APP_IDs, change supported brands
Browse files Browse the repository at this point in the history
  • Loading branch information
arraylabs committed Feb 14, 2017
1 parent 3ed6e1b commit 3b9b25d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 36 deletions.
65 changes: 30 additions & 35 deletions pymyq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,37 @@ class MyQAPI:

LIFTMASTER = 'liftmaster'
CHAMBERLAIN = 'chamberlain'
CRAFTMASTER = 'craftmaster'
CRAFTSMAN = 'craftsman'
MERLIN = 'merlin'

SUPPORTED_BRANDS = [LIFTMASTER, CHAMBERLAIN, CRAFTMASTER]
SUPPORTED_BRANDS = [LIFTMASTER, CHAMBERLAIN, CRAFTSMAN, MERLIN]
SUPPORTED_DEVICE_TYPE_NAMES = ['GarageDoorOpener', 'Garage Door Opener WGDO', 'VGDO']

APP_ID = 'app_id'
HOST_URI = 'host_uri'
HOST_URI = 'myqexternal.myqdevice.com'

BRAND_MAPPINGS = {
LIFTMASTER: {
APP_ID: 'JVM/G9Nwih5BwKgNCjLxiFUQxQijAebyyg8QUHr7JOrP+tuPb8iHfRHKwTmDzHOu',
HOST_URI: 'myqexternal.myqdevice.com'
APP_ID: 'Vj8pQggXLhLy0WHahglCD4N1nAkkXQtGYpq2HrHD7H1nvmbT55KqtN6RSF4ILB/i'
},
CHAMBERLAIN: {
APP_ID: 'JVM/G9Nwih5BwKgNCjLxiFUQxQijAebyyg8QUHr7JOrP+tuPb8iHfRHKwTmDzHOu', #Vj8pQggXLhLy0WHahglCD4N1nAkkXQtGYpq2HrHD7H1nvmbT55KqtN6RSF4ILB%2Fi
HOST_URI: 'myqexternal.myqdevice.com'
APP_ID: 'OA9I/hgmPHFp9RYKJqCKfwnhh28uqLJzZ9KOJf1DXoo8N2XAaVX6A1wcLYyWsnnv'
},
CRAFTMASTER: {
APP_ID: 'eU97d99kMG4t3STJZO/Mu2wt69yTQwM0WXZA5oZ74/ascQ2xQrLD/yjeVhEQccBZ',
HOST_URI: 'craftexternal.myqdevice.com'
CRAFTSMAN: {
APP_ID: 'YmiMRRS1juXdSd0KWsuKtHmQvh5RftEp5iewHdCvsNB77FnQbY+vjCVn2nMdIeN8'
},
MERLIN: {
APP_ID: '3004cac4e920426c823fa6c2ecf0cc28ef7d4a7b74b6470f8f0d94d6c39eb718'
}
}

STATE_OPEN = 'open'
STATE_CLOSED = 'closed'

LOGIN_ENDPOINT = "api/v4/user/validate"
DEVICE_LIST_ENDPOINT = "api/v4/userdevicedetails/get"
LOGIN_ENDPOINT = "api/v4/User/Validate"
DEVICE_LIST_ENDPOINT = "api/v4/UserDeviceDetails/Get"
DEVICE_SET_ENDPOINT = "api/v4/DeviceAttribute/PutDeviceAttribute"
HEADERS = {'User-Agent': 'Chamberlain/3773 (iPhone; iOS 10.0.1; Scale/2.00)'}
USERAGENT = "Chamberlain/3773 (iPhone; iOS 10.0.1; Scale/2.00)"

REQUEST_TIMEOUT = 3.0

Expand Down Expand Up @@ -72,20 +73,18 @@ def is_login_valid(self):
"""Log in to the MyQ service."""
params = {
'username': self.username,
'password': self.password,
'appId': self.BRAND_MAPPINGS[self.brand][self.APP_ID],
'culture': self.LOCALE
'password': self.password
}

try:
login = requests.post(
'https://{host_uri}/{login_endpoint}'.format(
host_uri=self.BRAND_MAPPINGS[self.brand][self.HOST_URI],
host_uri=self.HOST_URI,
login_endpoint=self.LOGIN_ENDPOINT),
json=params,
headers={
'MyQApplicationId': 'JVM/G9Nwih5BwKgNCjLxiFUQxQijAebyyg8QUHr7JOrP+tuPb8iHfRHKwTmDzHOu',
'User-Agent': 'Chamberlain/3773 (iPhone; iOS 10.0.1; Scale/2.00)'
'MyQApplicationId': self.BRAND_MAPPINGS[self.brand][self.APP_ID],
'User-Agent': self.USERAGENT
},
timeout=self.REQUEST_TIMEOUT
)
Expand All @@ -107,18 +106,16 @@ def get_devices(self):
if not self._logged_in:
self._logged_in = self.is_login_valid()

params = {
'appId': self.BRAND_MAPPINGS[self.brand][self.APP_ID],
'securityToken': self.security_token
}

try:
devices = requests.get(
'https://{host_uri}/{device_list_endpoint}'.format(
host_uri=self.BRAND_MAPPINGS[self.brand][self.HOST_URI],
host_uri=self.HOST_URI,
device_list_endpoint=self.DEVICE_LIST_ENDPOINT),
params=params,
headers=self.HEADERS
headers={
'MyQApplicationId': self.BRAND_MAPPINGS[self.brand][self.APP_ID],
'SecurityToken': self.security_token,
'User-Agent': self.USERAGENT
}
)

devices.raise_for_status()
Expand Down Expand Up @@ -175,22 +172,21 @@ def open_device(self, device_id):
def set_state(self, device_id, state):
"""Set device state."""
payload = {
'AttributeName': 'desireddoorstate',
'MyQDeviceId': device_id,
'ApplicationId': 'JVM/G9Nwih5BwKgNCjLxiFUQxQijAebyyg8QUHr7JOrP+tuPb8iHfRHKwTmDzHOu',
'attributeName': 'desireddoorstate',
'myQDeviceId': device_id,
'AttributeValue': state,
'SecurityToken': self.security_token,
}

try:
device_action = requests.put(
'https://{host_uri}/{device_set_endpoint}'.format(
host_uri=self.BRAND_MAPPINGS[self.brand][self.HOST_URI],
host_uri=self.HOST_URI,
device_set_endpoint=self.DEVICE_SET_ENDPOINT),
data=payload,
headers={
'MyQApplicationId': 'JVM/G9Nwih5BwKgNCjLxiFUQxQijAebyyg8QUHr7JOrP+tuPb8iHfRHKwTmDzHOu',
'SecurityToken': self.security_token
'MyQApplicationId': self.BRAND_MAPPINGS[self.brand][self.APP_ID],
'SecurityToken': self.security_token,
'User-Agent': self.USERAGENT
}
)

Expand All @@ -200,4 +196,3 @@ def set_state(self, device_id, state):
return False

return device_action.status_code == 200

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(
name='pymyq',
version='0.0.2',
version='0.0.4',
description='Python package for controlling MyQ-Enabled Garage Door',
author='Chris Campbell',
author_email='[email protected]',
Expand Down

0 comments on commit 3b9b25d

Please sign in to comment.