From 3923c69a443b36e5a48783efadda3ca5b0afecac Mon Sep 17 00:00:00 2001 From: kylerw Date: Sun, 6 Nov 2016 16:39:26 -0700 Subject: [PATCH 1/3] Support for multiple doors allows for multiple doors and uses the name defined in the Chamberlain/Liftmaster app --- myq.py | 55 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/myq.py b/myq.py index 5e932be..af273d3 100644 --- a/myq.py +++ b/myq.py @@ -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) @@ -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()) @@ -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') @@ -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'] @@ -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): @@ -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'] @@ -210,9 +214,10 @@ 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 @@ -220,11 +225,11 @@ def set_state(self, device_id, state): 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'] @property def should_poll(self): From d98da6177e879097f1a8c5a734191e81ac77398b Mon Sep 17 00:00:00 2001 From: kylerw Date: Sun, 6 Nov 2016 21:23:11 -0700 Subject: [PATCH 2/3] Update to use update() method --- myq.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/myq.py b/myq.py index af273d3..b257e55 100644 --- a/myq.py +++ b/myq.py @@ -230,6 +230,7 @@ def __init__(self, myq, device): self.myq = myq self.device_id = device['deviceid'] self._name = device['name'] + self._status = None @property def should_poll(self): @@ -244,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): @@ -259,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) From 0b41c49bdde453f88bbce5bc422faa5dc5d6fbbf Mon Sep 17 00:00:00 2001 From: kylerw Date: Sun, 6 Nov 2016 21:26:00 -0700 Subject: [PATCH 3/3] fixing spacing issues --- myq.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/myq.py b/myq.py index b257e55..64456aa 100644 --- a/myq.py +++ b/myq.py @@ -230,7 +230,7 @@ def __init__(self, myq, device): self.myq = myq self.device_id = device['deviceid'] self._name = device['name'] - self._status = None + self._status = None @property def should_poll(self):