@@ -42,6 +42,7 @@ class MyQAPI:
4242 LOGIN_ENDPOINT = "api/v4/User/Validate"
4343 DEVICE_LIST_ENDPOINT = "api/v4/UserDeviceDetails/Get"
4444 DEVICE_SET_ENDPOINT = "api/v4/DeviceAttribute/PutDeviceAttribute"
45+ DEVICE_ATTRIBUTE_GET_ENDPOINT = "api/v4/DeviceAttribute/getDeviceAttribute"
4546 USERAGENT = "Chamberlain/3773 (iPhone; iOS 11.0.3; Scale/2.00)"
4647
4748 REQUEST_TIMEOUT = 3.0
@@ -56,6 +57,7 @@ class MyQAPI:
5657 '7' : STATE_UNKNOWN ,
5758 '8' : STATE_TRANSITION ,
5859 '9' : STATE_OPEN ,
60+ '0' : STATE_UNKNOWN
5961 }
6062
6163 logger = logging .getLogger (__name__ )
@@ -127,7 +129,7 @@ def get_devices(self):
127129 )
128130
129131 devices .raise_for_status ()
130-
132+
131133 except requests .exceptions .HTTPError as ex :
132134 self .logger .error ("MyQ - API Error[get_devices] %s" , ex )
133135 return False
@@ -138,7 +140,7 @@ def get_devices(self):
138140 except KeyError :
139141 self .logger .error ("MyQ - Login security token may have expired, will attempt relogin on next update" )
140142 self ._logged_in = False
141-
143+
142144
143145 def get_garage_doors (self ):
144146 """List only MyQ garage door devices."""
@@ -165,19 +167,47 @@ def get_garage_doors(self):
165167
166168 def get_status (self , device_id ):
167169 """List only MyQ garage door devices."""
168- devices = self .get_devices ()
170+ #devices = self.get_devices()
171+
172+ if not self ._logged_in :
173+ self ._logged_in = self .is_login_valid ()
169174
170175 garage_state = False
171176
172- if devices != False :
173- for device in devices :
174- if device ['MyQDeviceTypeName' ] in self .SUPPORTED_DEVICE_TYPE_NAMES and device ['MyQDeviceId' ] == device_id :
175- dev = {}
176- for attribute in device ['Attributes' ]:
177- if attribute ['AttributeDisplayName' ] == 'doorstate' :
178- myq_garage_state = attribute ['Value' ]
179- garage_state = self .DOOR_STATE [myq_garage_state ]
177+ # if devices != False:
178+ # for device in devices:
179+ # if device['MyQDeviceTypeName'] in self.SUPPORTED_DEVICE_TYPE_NAMES and device['MyQDeviceId'] == device_id:
180+ # dev = {}
181+ # for attribute in device['Attributes']:
182+ # if attribute['AttributeDisplayName'] == 'doorstate':
183+ # myq_garage_state = attribute['Value']
184+ # garage_state = self.DOOR_STATE[myq_garage_state]
185+
186+ try :
187+ doorstate = requests .get (
188+ 'https://{host_uri}/{device_attribute_get_endpoint}' .format (
189+ host_uri = self .HOST_URI ,
190+ device_attribute_get_endpoint = self .DEVICE_ATTRIBUTE_GET_ENDPOINT ),
191+ headers = {
192+ 'MyQApplicationId' : self .BRAND_MAPPINGS [self .brand ][self .APP_ID ],
193+ 'SecurityToken' : self .security_token
194+ },
195+ query = {
196+ 'AttributName' : 'doorstate' ,
197+ 'MyQDeviceId' : device_id
198+ }
199+ )
200+
201+ doorstate .raise_for_status ()
202+
203+ except requests .exceptions .HTTPError as ex :
204+ self .logger .error ("MyQ - API Error[get_status] %s" , ex )
205+ return False
206+
207+ doorstate = doorstate ['AttributeValue' ]
180208
209+ garage_state = self .DOOR_STATE [doorstate ]
210+
181211 return garage_state
182212
183213 def close_device (self , device_id ):
0 commit comments