Skip to content

Support for multiple doors #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 7, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 35 additions & 27 deletions myq.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up the MyQ garage door."""

name = config.get(CONF_NAME) if \
CONF_NAME else DEFAULT_NAME
# name = config.get(CONF_NAME) if \
# CONF_NAME else DEFAULT_NAME

username = config.get(CONF_USERNAME)
password = config.get(CONF_PASSWORD)
Expand All @@ -66,7 +66,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):

myq = MyQAPI(username, password, brand, logger)

add_devices(MyQCoverDevice(myq, door, name) for door
add_devices(MyQCoverDevice(myq, door) for door
in myq.get_garage_doors())


Expand Down Expand Up @@ -113,9 +113,10 @@ def login(self):
host_uri=self.brand[HOST_URI],
login_endpoint=self.LOGIN_ENDPOINT),
params=params,
headers={
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.47 Safari/537.36'
})
headers={
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.47 Safari/537.36'
}
)
auth = login.json()
self.security_token = auth['SecurityToken']
self._logger.debug('Logged in to MyQ API')
Expand All @@ -137,9 +138,10 @@ def get_devices(self):
host_uri=self.brand[HOST_URI],
device_list_endpoint=self.DEVICE_LIST_ENDPOINT),
params=params,
headers={
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.47 Safari/537.36'
})
headers={
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.47 Safari/537.36'
}
)

devices = devices.json()['Devices']

Expand All @@ -154,13 +156,14 @@ def get_garage_doors(self):

for device in devices:
if device['MyQDeviceTypeName'] == 'GarageDoorOpener':
garage_doors.append(device['DeviceId'])
# This looks like it expects a generic garage door operer name
# for attribute in device['Attributes']:
# if attribute['AttributeDisplayName'] == 'desc' and \
# attribute['Value'] == 'Garage Door Opener':
# garage_doors.append(device['DeviceId'])

dev = {}
for attribute in device['Attributes']:
if attribute['AttributeDisplayName'] == 'desc':
dev['deviceid'] = device['DeviceId']
dev['name'] = attribute['Value']
garage_doors.append(dev)


return garage_doors

def get_status(self, device_id):
Expand All @@ -178,9 +181,10 @@ def get_status(self, device_id):
host_uri=self.brand[HOST_URI],
device_status_endpoint=self.DEVICE_STATUS_ENDPOINT),
params=params,
headers={
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.47 Safari/537.36'
})
headers={
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.47 Safari/537.36'
}
)

attval = device_status.json()['AttributeValue']

Expand Down Expand Up @@ -210,21 +214,23 @@ def set_state(self, device_id, state):
host_uri=self.brand[HOST_URI],
device_set_endpoint=self.DEVICE_SET_ENDPOINT),
data=payload,
headers={
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.47 Safari/537.36'
})
headers={
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.47 Safari/537.36'
}
)

return device_action.status_code == 200


class MyQCoverDevice(CoverDevice):
"""Representation of a MyQ cover."""

def __init__(self, myq, device_id, name):
def __init__(self, myq, device):
"""Initialize with API object, device id, and name."""
self.myq = myq
self.device_id = device_id
self._name = name
self.device_id = device['deviceid']
self._name = device['name']
self._status = None

@property
def should_poll(self):
Expand All @@ -239,8 +245,7 @@ def name(self):
@property
def is_closed(self):
"""Return True if cover is closed, else False."""
status = self.myq.get_status(self.device_id)
return status == STATE_CLOSED
return self._status == STATE_CLOSED

@property
def current_cover_position(self):
Expand All @@ -254,3 +259,6 @@ def close_cover(self):
def open_cover(self):
"""Issue open command to cover."""
self.myq.open_device(self.device_id)

def update(self):
self._status = self.myq.get_status(self.device_id)