Skip to content

Commit

Permalink
Issue 183: Fix brokeness in CustomMode
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreydwalter committed Jan 4, 2022
1 parent cf3a4b7 commit 50d14cf
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions arlo.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,12 +529,12 @@ def GetCalendar(self, basestation):
def DeleteMode(self, device, mode):
""" device can be any object that has parentId == deviceId. i.e., not a camera """
parentId = device.get('parentId', None)
if device['deviceType'] == 'arlobridge':
if device.get('deviceType') == 'arlobridge':
return self.request.delete(f'https://{self.BASE_URL}/hmsweb/users/locations/'+device.get('uniqueId')+'/modes/'+mode)
elif not parentId or device.get('deviceId') == parentId:
return self.NotifyAndGetResponse(device, {"action":"delete","resource":"modes/"+mode,"publishResponse":True})
else:
raise Exception('Only parent device modes and schedules can be deleted.');
raise Exception('Only parent device modes and schedules can be deleted.')

def GetModes(self, basestation):
""" DEPRECATED: This is the older API for getting the "mode". It still works, but GetModesV2 is the way the Arlo software does it these days. """
Expand All @@ -550,10 +550,13 @@ def GetModesV2(self):

def CustomMode(self, device, mode, schedules=[]):
""" device can be any object that has parentId == deviceId. i.e., not a camera """
if(device["deviceType"].startswith("arloq")):
parentId = device.get('parentId', None)
if device.get('deviceType') == 'arlobridge':
return self.request.post(f'https://{self.BASE_URL}/hmsweb/users/devices/automation/active', {'activeAutomations':[{'deviceId':device.get('deviceId'),'timestamp':self.to_timestamp(datetime.now()),'activeModes':[mode],'activeSchedules':schedules}]})
elif not parentId or device.get('deviceId') == parentId:
return self.NotifyAndGetResponse(device, {"from":self.user_id+"_web", "to": device.get("parentId"), "action":"set","resource":"modes", "transId": self.genTransId(),"publishResponse":True,"properties":{"active":mode}})
else:
return self.request.post(f'https://{self.BASE_URL}/hmsweb/users/devices/automation/active', {'activeAutomations':[{'deviceId':device.get('deviceId'),'timestamp':self.to_timestamp(datetime.now()),'activeModes':[mode],'activeSchedules':schedules}]})
raise Exception('Only parent device modes and schedules can be modified.')

def Arm(self, device):
return self.CustomMode(device, "mode1")
Expand Down Expand Up @@ -1048,7 +1051,7 @@ def Geofencing(self, location_id, active=True):

def GetDevice(self, device_name):
def is_device(device):
return device['deviceName'] == device_name
return device.get('deviceName') == device_name
return list(filter(is_device, self.GetDevices()))[0]

def GetDevices(self, device_type=None, filter_provisioned=None):
Expand All @@ -1059,7 +1062,7 @@ def GetDevices(self, device_type=None, filter_provisioned=None):
"""
devices = self.request.get(f'https://{self.BASE_URL}/hmsweb/users/devices')
if device_type:
devices = [ device for device in devices if device['deviceType'] in device_type]
devices = [ device for device in devices if device.get('deviceType') in device_type]

if filter_provisioned is not None:
if filter_provisioned:
Expand Down

0 comments on commit 50d14cf

Please sign in to comment.