diff --git a/abodepy/__init__.py b/abodepy/__init__.py index d1d19a0..09b9ee8 100644 --- a/abodepy/__init__.py +++ b/abodepy/__init__.py @@ -261,7 +261,7 @@ def get_device(self, device_id, refresh=False): return device - def get_automations(self, refresh=False, generic_type=None): + def get_automations(self, refresh=False): """Get all automations.""" if refresh or self._automations is None: if self._automations is None: @@ -289,14 +289,6 @@ def get_automations(self, refresh=False, generic_type=None): automation = AbodeAutomation(self, automation_json) self._automations[automation.automation_id] = automation - if generic_type: - automations = [] - for automation in self._automations.values(): - if (automation.generic_type is not None and - automation.generic_type in generic_type): - automations.append(automation) - return automations - return list(self._automations.values()) def get_automation(self, automation_id, refresh=False): diff --git a/abodepy/automation.py b/abodepy/automation.py index 4133942..ddbe597 100644 --- a/abodepy/automation.py +++ b/abodepy/automation.py @@ -1,11 +1,14 @@ """Representation of an automation configured in Abode.""" import json +import logging from abodepy.exceptions import AbodeException import abodepy.helpers.constants as CONST import abodepy.helpers.errors as ERROR +_LOGGER = logging.getLogger(__name__) + class AbodeAutomation: """Class for viewing and controlling automations.""" @@ -15,16 +18,15 @@ def __init__(self, abode, automation): self._abode = abode self._automation = automation - def set_active(self, active): - """Activate and deactivate an automation.""" - url = CONST.AUTOMATION_EDIT_URL - url = url.replace( - '$AUTOMATIONID$', self.automation_id) + def enable(self, enable): + """Enable or disable the automation.""" + url = str.replace(CONST.AUTOMATION_ID_URL, '$AUTOMATIONID$', + self.automation_id) - self._automation['is_active'] = str(int(active)) + self._automation['enabled'] = enable response = self._abode.send_request( - method="put", url=url, data=self._automation) + method="patch", url=url, data={'enabled': enable}) response_object = json.loads(response.text) @@ -32,32 +34,33 @@ def set_active(self, active): response_object = response_object[0] if (str(response_object['id']) != str(self._automation['id']) or - response_object['is_active'] != self._automation['is_active']): + str(response_object['enabled']) != + str(self._automation['enabled'])): raise AbodeException((ERROR.INVALID_AUTOMATION_EDIT_RESPONSE)) self.update(response_object) + _LOGGER.info("Set automation %s enable to: %s", self.name, + self.is_enabled) + _LOGGER.debug("Automation response: %s", response.text) + return True - def trigger(self, only_manual=True): - """Trigger a quick-action automation.""" - if not self.is_quick_action and only_manual: - raise AbodeException((ERROR.TRIGGER_NON_QUICKACTION)) + def trigger(self): + """Trigger the automation.""" + url = str.replace(CONST.AUTOMATION_APPLY_URL, '$AUTOMATIONID$', + self.automation_id) - url = CONST.AUTOMATION_APPLY_URL - url = url.replace( - '$AUTOMATIONID$', self.automation_id) + self._abode.send_request(method="post", url=url) - self._abode.send_request( - method="put", url=url, data=self._automation) + _LOGGER.info("Automation triggered: %s", self.name) return True def refresh(self): """Refresh the automation.""" - url = CONST.AUTOMATION_ID_URL - url = url.replace( - '$AUTOMATIONID$', self.automation_id) + url = str.replace(CONST.AUTOMATION_ID_URL, '$AUTOMATIONID$', + self.automation_id) response = self._abode.send_request(method="get", url=url) response_object = json.loads(response.text) @@ -86,40 +89,12 @@ def name(self): return self._automation['name'] @property - def generic_type(self): - """Get the generic type of the automation.""" - if self.is_quick_action: - return CONST.TYPE_QUICK_ACTION - - return CONST.TYPE_AUTOMATION - - @property - def type(self): - """Get the type of the automation.""" - return self._automation['type'] - - @property - def sub_type(self): - """Get the sub type of the automation.""" - return self._automation['sub_type'] - - @property - def is_active(self): - """Return if the automation is active.""" - return int(self._automation.get('is_active', '0')) == 1 - - @property - def is_quick_action(self): - """Return if the automation is a quick action.""" - return self.type == CONST.AUTOMATION_TYPE_MANUAL + def is_enabled(self): + """Return True if the automation is enabled.""" + return self._automation['enabled'] @property def desc(self): """Get a short description of the automation.""" - # Auto Away (1) - Location - Enabled - active = 'inactive' - if self.is_active: - active = 'active' - - return '{0} (ID: {1}) - {2} - {3}'.format( - self.name, self.automation_id, self.type, active) + return '{0} (ID: {1}, Enabled: {2})'.format( + self.name, self.automation_id, self.is_enabled) diff --git a/abodepy/helpers/constants.py b/abodepy/helpers/constants.py index 84b0c64..e630a45 100644 --- a/abodepy/helpers/constants.py +++ b/abodepy/helpers/constants.py @@ -72,9 +72,8 @@ def get_panel_mode_url(area, mode): SOUNDS_URL = BASE_URL + 'api/v1/sounds' SIREN_URL = BASE_URL + 'api/v1/siren' -AUTOMATION_URL = BASE_URL + 'api/v1/automation/' +AUTOMATION_URL = BASE_URL + 'integrations/v1/automations/' AUTOMATION_ID_URL = AUTOMATION_URL + '$AUTOMATIONID$/' -AUTOMATION_EDIT_URL = AUTOMATION_ID_URL + 'edit' AUTOMATION_APPLY_URL = AUTOMATION_ID_URL + 'apply' TIMELINE_IMAGES_ID_URL = BASE_URL + \ @@ -125,17 +124,8 @@ def get_panel_mode_url(area, mode): COLOR_MODE_ON = 0 COLOR_MODE_OFF = 2 -AUTOMATION_TYPE_MANUAL = 'manual' -AUTOMATION_TYPE_LOCATION = 'location' -AUTOMATION_TYPE_SCHEDULE = 'schedule' -AUTOMATION_TYPE_STATUS = 'status' - -AUTOMATION_SUBTYPE_ENTERING_HOME = 'entering_home' -AUTOMATION_SUBTYPE_LEAVING_HOME = 'leaving_home' - # GENERIC ABODE DEVICE TYPES TYPE_ALARM = "alarm" -TYPE_AUTOMATION = "automation" TYPE_CAMERA = "camera" TYPE_CONNECTIVITY = "connectivity" TYPE_COVER = "cover" @@ -145,7 +135,6 @@ def get_panel_mode_url(area, mode): TYPE_MOTION = "motion" TYPE_OCCUPANCY = "occupancy" TYPE_OPENING = "door" -TYPE_QUICK_ACTION = "quick_action" TYPE_SENSOR = "sensor" TYPE_SWITCH = "switch" TYPE_VALVE = "valve" @@ -155,8 +144,6 @@ def get_panel_mode_url(area, mode): BINARY_SENSOR_TYPES = [TYPE_CONNECTIVITY, TYPE_MOISTURE, TYPE_MOTION, TYPE_OCCUPANCY, TYPE_OPENING] -AUTOMATION_TYPES = [TYPE_AUTOMATION, TYPE_QUICK_ACTION] - # DEVICE TYPE_TAGS # Alarm DEVICE_ALARM = 'device_type.alarm' diff --git a/abodepy/helpers/errors.py b/abodepy/helpers/errors.py index c36d164..70cfbc1 100644 --- a/abodepy/helpers/errors.py +++ b/abodepy/helpers/errors.py @@ -40,8 +40,8 @@ INVALID_AUTOMATION_EDIT_RESPONSE = ( 16, "Automation edit response did not match expected values.") -TRIGGER_NON_QUICKACTION = ( - 17, "Can not trigger an automation that is not a manual quick-action.") +# TRIGGER_NON_QUICKACTION = ( +# 17, "Can not trigger an automation that is not a manual quick-action.") UNABLE_TO_MAP_DEVICE = ( 18, "Unable to map device json to device class - no type tag found.") diff --git a/abodepy/helpers/timeline.py b/abodepy/helpers/timeline.py index 51be4bc..74787e8 100644 --- a/abodepy/helpers/timeline.py +++ b/abodepy/helpers/timeline.py @@ -505,3 +505,8 @@ def map_event_code(event_code): 'event_code': '5204', 'event_type': 'Quick Action' } + +AUTOMATION = { + 'event_code': '5206', + 'event_type': 'Automation' +} diff --git a/tests/mock/automation.py b/tests/mock/automation.py index 923c861..49c26bc 100644 --- a/tests/mock/automation.py +++ b/tests/mock/automation.py @@ -1,15 +1,36 @@ """Mock Abode Automation.""" -def get_response_ok(aid, name, is_active, the_type, sub_type=""): +def get_response_ok(name, enabled, aid): """Return automation json.""" return '''{ - "id": ''' + str(int(aid)) + ''', "name": "''' + name + '''", - "actions": "a=1&m=2;", - "condition": "HHMM_2300_2300", - "is_active": "''' + str(int(is_active)) + '''", - "sub_type": "''' + sub_type + '''", - "type": "''' + the_type + '''", - "notify_msg": null - }''' + "enabled": "''' + str(enabled) + '''", + "version": 2, + "id": "''' + aid + '''", + "subType": "", + "actions": [{ + "directive": { + "trait": "panel.traits.panelMode", + "name": "panel.directives.arm", + "state": { + "panelMode": "AWAY" + } + } + }], + "conditions": {}, + "triggers": { + "operator": "OR", + "expressions": [{ + "mobileDevices": ["89381", "658"], + "property": { + "trait": "mobile.traits.location", + "name": "location", + "rule": { + "location": "31675", + "equalTo": "LAST_OUT" + } + } + }] + } + }''' diff --git a/tests/test_automation.py b/tests/test_automation.py index 3aa8727..eba9dc4 100644 --- a/tests/test_automation.py +++ b/tests/test_automation.py @@ -18,8 +18,12 @@ USERNAME = 'foobar' PASSWORD = 'deadbeef' +AID_1 = '47fae27488f74f55b964a81a066c3a01' +AID_2 = '47fae27488f74f55b964a81a066c3a02' +AID_3 = '47fae27488f74f55b964a81a066c3a03' +@requests_mock.Mocker() class TestDevice(unittest.TestCase): """Test the generic AbodePy device class.""" @@ -33,7 +37,6 @@ def tearDown(self): """Clean up after test.""" self.abode = None - @requests_mock.mock() def tests_automation_init(self, m): """Check the Abode automation class init's properly.""" # Set up URLs @@ -44,11 +47,10 @@ def tests_automation_init(self, m): # Set up automation automation_text = AUTOMATION.get_response_ok( - aid=1, - name='Test Automation', - is_active=True, - the_type=CONST.AUTOMATION_TYPE_LOCATION, - sub_type=CONST.AUTOMATION_SUBTYPE_ENTERING_HOME) + name='Auto Away', + enabled=True, + aid=AID_1 + ) automation_json = json.loads(automation_text) @@ -58,23 +60,18 @@ def tests_automation_init(self, m): self.abode.logout() # Get our specific automation - automation = self.abode.get_automation(1) + automation = self.abode.get_automation(AID_1) # Check automation states match self.assertIsNotNone(automation) # pylint: disable=W0212 self.assertEqual(automation._automation, automation_json) - self.assertEqual(automation.name, automation_json['name']) - self.assertEqual(automation.type, automation_json['type']) - self.assertEqual(automation.sub_type, automation_json['sub_type']) self.assertEqual(automation.automation_id, str(automation_json['id'])) - self.assertEqual(automation.is_active, True) - self.assertEqual(automation.is_quick_action, False) - self.assertEqual(automation.generic_type, CONST.TYPE_AUTOMATION) + self.assertEqual(automation.name, automation_json['name']) + self.assertEqual(automation.is_enabled, automation_json['enabled']) self.assertIsNotNone(automation.desc) - @requests_mock.mock() def tests_automation_refresh(self, m): """Check the automation Abode class refreshes.""" # Set up URL's @@ -86,11 +83,9 @@ def tests_automation_refresh(self, m): # Set up automation automation_text = '[' + \ AUTOMATION.get_response_ok( - aid=1, name='Test Automation', - is_active=True, - the_type=CONST.AUTOMATION_TYPE_LOCATION, - sub_type=CONST.AUTOMATION_SUBTYPE_ENTERING_HOME) + ']' + enabled=True, + aid=AID_1) + ']' automation_json = json.loads(automation_text) @@ -99,24 +94,23 @@ def tests_automation_refresh(self, m): # Set up refreshed automation automation_text_changed = '[' + \ AUTOMATION.get_response_ok( - aid=1, name='Test Automation Changed', - is_active=False, - the_type=CONST.AUTOMATION_TYPE_SCHEDULE, - sub_type="Foobar") + ']' + enabled=False, + aid=AID_1) + ']' automation_json_changed = json.loads(automation_text_changed) automation_id_url = str.replace(CONST.AUTOMATION_ID_URL, '$AUTOMATIONID$', str(automation_json[0]['id'])) + m.get(automation_id_url, text=automation_text_changed) # Logout to reset everything self.abode.logout() # Get the first automation and test - automation = self.abode.get_automation(1) + automation = self.abode.get_automation(AID_1) # Check automation states match # pylint: disable=W0212 @@ -130,34 +124,31 @@ def tests_automation_refresh(self, m): # Refresh with get_automation() and test automation_text_changed = '[' + \ AUTOMATION.get_response_ok( - aid=1, name='Test Automation Changed Again', - is_active=True, - the_type=CONST.AUTOMATION_TYPE_MANUAL, - sub_type="Deadbeef") + ']' + enabled=True, + aid=AID_1) + ']' automation_json_changed = json.loads(automation_text_changed) m.get(automation_id_url, text=automation_text_changed) # Refresh and retest - automation = self.abode.get_automation(1, refresh=True) + automation = self.abode.get_automation(AID_1, refresh=True) + self.assertEqual(automation._automation, automation_json_changed[0]) # Test refresh returning an incorrect ID throws exception # Set up refreshed automation automation_text_changed = '[' + \ AUTOMATION.get_response_ok( - aid=2, name='Test Automation Changed', - is_active=False, - the_type=CONST.AUTOMATION_TYPE_SCHEDULE) + ']' + enabled=False, + aid='47fae27488f74f55b964a81a066c3a11') + ']' m.get(automation_id_url, text=automation_text_changed) with self.assertRaises(abodepy.AbodeException): automation.refresh() - @requests_mock.mock() def tests_multiple_automations(self, m): """Check that multiple automations work and return correctly.""" # Set up URL's @@ -169,21 +160,17 @@ def tests_multiple_automations(self, m): # Set up automations automation_text = '[' + \ AUTOMATION.get_response_ok( - aid=1, - name='Test Automation Uno', - is_active=True, - the_type=CONST.AUTOMATION_TYPE_LOCATION, - sub_type=CONST.AUTOMATION_SUBTYPE_ENTERING_HOME) + ',' + \ + name='Test Automation One', + enabled=True, + aid=AID_1) + ',' + \ AUTOMATION.get_response_ok( - aid=2, - name='Test Automation Dos', - is_active=True, - the_type=CONST.AUTOMATION_TYPE_STATUS) + ',' + \ + name='Test Automation Two', + enabled=True, + aid=AID_2) + ',' + \ AUTOMATION.get_response_ok( - aid=3, - name='Test Automation Tres', - is_active=True, - the_type=CONST.AUTOMATION_TYPE_SCHEDULE) + ']' + name='Test Automation Three', + enabled=True, + aid=AID_3) + ']' automation_json = json.loads(automation_text) @@ -198,19 +185,18 @@ def tests_multiple_automations(self, m): # Get the first automation and test # pylint: disable=W0212 - automation_1 = self.abode.get_automation(1) + automation_1 = self.abode.get_automation(AID_1) self.assertIsNotNone(automation_1) self.assertEqual(automation_1._automation, automation_json[0]) - automation_2 = self.abode.get_automation(2) + automation_2 = self.abode.get_automation(AID_2) self.assertIsNotNone(automation_2) self.assertEqual(automation_2._automation, automation_json[1]) - automation_3 = self.abode.get_automation(3) + automation_3 = self.abode.get_automation(AID_3) self.assertIsNotNone(automation_3) self.assertEqual(automation_3._automation, automation_json[2]) - @requests_mock.mock() def tests_automation_class_reuse(self, m): """Check that automations reuse the same classes when refreshed.""" # Set up URL's @@ -222,16 +208,13 @@ def tests_automation_class_reuse(self, m): # Set up automations automation_text = '[' + \ AUTOMATION.get_response_ok( - aid=1, - name='Test Automation Uno', - is_active=True, - the_type=CONST.AUTOMATION_TYPE_LOCATION, - sub_type=CONST.AUTOMATION_SUBTYPE_ENTERING_HOME) + ',' + \ + name='Test Automation One', + enabled=True, + aid=AID_1) + ',' + \ AUTOMATION.get_response_ok( - aid=2, - name='Test Automation Dos', - is_active=True, - the_type=CONST.AUTOMATION_TYPE_STATUS) + ']' + name='Test Automation Two', + enabled=True, + aid=AID_2) + ']' automation_json = json.loads(automation_text) @@ -246,32 +229,28 @@ def tests_automation_class_reuse(self, m): # Get the automations and test # pylint: disable=W0212 - automation_1 = self.abode.get_automation(1) + automation_1 = self.abode.get_automation(AID_1) self.assertIsNotNone(automation_1) self.assertEqual(automation_1._automation, automation_json[0]) - automation_2 = self.abode.get_automation(2) + automation_2 = self.abode.get_automation(AID_2) self.assertIsNotNone(automation_2) self.assertEqual(automation_2._automation, automation_json[1]) # Update the automations automation_text = '[' + \ AUTOMATION.get_response_ok( - aid=1, - name='Test Automation Uno Changed', - is_active=False, - the_type=CONST.AUTOMATION_TYPE_LOCATION, - sub_type=CONST.AUTOMATION_SUBTYPE_ENTERING_HOME) + ',' + \ + name='Test Automation One Changed', + enabled=False, + aid=AID_1) + ',' + \ AUTOMATION.get_response_ok( - aid=2, - name='Test Automation Dos Changed', - is_active=False, - the_type=CONST.AUTOMATION_TYPE_STATUS) + ',' + \ + name='Test Automation Two Changed', + enabled=False, + aid=AID_2) + ',' + \ AUTOMATION.get_response_ok( - aid=3, - name='Test Automation Tres New', - is_active=True, - the_type=CONST.AUTOMATION_TYPE_SCHEDULE) + ']' + name='Test Automation Three New', + enabled=True, + aid=AID_3) + ']' automation_json_changed = json.loads(automation_text) @@ -283,26 +262,25 @@ def tests_automation_class_reuse(self, m): # Check that the original two automations have updated # and are using the same class - automation_1_changed = self.abode.get_automation(1) + automation_1_changed = self.abode.get_automation(AID_1) self.assertIsNotNone(automation_1_changed) self.assertEqual(automation_1_changed._automation, automation_json_changed[0]) self.assertIs(automation_1, automation_1_changed) - automation_2_changed = self.abode.get_automation(2) + automation_2_changed = self.abode.get_automation(AID_2) self.assertIsNotNone(automation_2_changed) self.assertEqual(automation_2_changed._automation, automation_json_changed[1]) self.assertIs(automation_2, automation_2_changed) # Check that the third new automation is correct - automation_3 = self.abode.get_automation(3) + automation_3 = self.abode.get_automation(AID_3) self.assertIsNotNone(automation_3) self.assertEqual(automation_3._automation, automation_json_changed[2]) - @requests_mock.mock() - def tests_automation_set_active(self, m): - """Check that automations can change their active state.""" + def tests_automation_enable(self, m): + """Check that automations can change their enable state.""" # Set up URL's m.post(CONST.LOGIN_URL, text=LOGIN.post_response_ok()) m.get(CONST.OAUTH_TOKEN_URL, text=OAUTH_CLAIMS.get_response_ok()) @@ -312,11 +290,9 @@ def tests_automation_set_active(self, m): # Set up automation automation_text = '[' + \ AUTOMATION.get_response_ok( - aid=1, - name='Test Automation Uno', - is_active=True, - the_type=CONST.AUTOMATION_TYPE_LOCATION, - sub_type=CONST.AUTOMATION_SUBTYPE_ENTERING_HOME) + ']' + name='Test Automation One', + enabled=True, + aid=AID_1) + ']' automation_json = json.loads(automation_text) @@ -327,65 +303,57 @@ def tests_automation_set_active(self, m): # Get the automation and test # pylint: disable=W0212 - automation = self.abode.get_automation(1) + automation = self.abode.get_automation(AID_1) self.assertIsNotNone(automation) self.assertEqual(automation._automation, automation_json[0]) - self.assertTrue(automation.is_active) + self.assertTrue(automation.is_enabled) # Set up our active state change and URL - set_active_url = str.replace(CONST.AUTOMATION_EDIT_URL, + set_active_url = str.replace(CONST.AUTOMATION_ID_URL, '$AUTOMATIONID$', str(automation_json[0]['id'])) - m.put(set_active_url, - text=AUTOMATION.get_response_ok( - aid=1, - name='Test Automation Uno', - is_active=False, - the_type=CONST.AUTOMATION_TYPE_LOCATION, - sub_type=CONST.AUTOMATION_SUBTYPE_ENTERING_HOME)) + + m.patch(set_active_url, + text=AUTOMATION.get_response_ok( + name='Test Automation One', + enabled=False, + aid=AID_1)) # Test the changed state - automation.set_active(False) - self.assertFalse(automation.is_active) + automation.enable(False) + self.assertFalse(automation.is_enabled) # Change the state back, this time with an array response - m.put(set_active_url, - text='[' + AUTOMATION.get_response_ok( - aid=1, - name='Test Automation Uno', - is_active=True, - the_type=CONST.AUTOMATION_TYPE_LOCATION, - sub_type=CONST.AUTOMATION_SUBTYPE_ENTERING_HOME) + ']') + m.patch(set_active_url, + text='[' + AUTOMATION.get_response_ok( + name='Test Automation One', + enabled=True, + aid=AID_1) + ']') # Test the changed state - automation.set_active(True) - self.assertTrue(automation.is_active) + automation.enable(True) + self.assertTrue(automation.is_enabled) # Test that the response returns the wrong state - m.put(set_active_url, - text='[' + AUTOMATION.get_response_ok( - aid=1, - name='Test Automation Uno', - is_active=True, - the_type=CONST.AUTOMATION_TYPE_LOCATION, - sub_type=CONST.AUTOMATION_SUBTYPE_ENTERING_HOME) + ']') + m.patch(set_active_url, + text='[' + AUTOMATION.get_response_ok( + name='Test Automation One', + enabled=True, + aid=AID_1) + ']') with self.assertRaises(abodepy.AbodeException): - automation.set_active(False) + automation.enable(False) # Test that the response returns the wrong id - m.put(set_active_url, - text='[' + AUTOMATION.get_response_ok( - aid=2, - name='Test Automation Uno', - is_active=True, - the_type=CONST.AUTOMATION_TYPE_LOCATION, - sub_type=CONST.AUTOMATION_SUBTYPE_ENTERING_HOME) + ']') + m.patch(set_active_url, + text='[' + AUTOMATION.get_response_ok( + name='Test Automation One', + enabled=True, + aid=AID_2) + ']') with self.assertRaises(abodepy.AbodeException): - automation.set_active(True) + automation.enable(True) - @requests_mock.mock() def tests_automation_trigger(self, m): """Check that automations can be triggered.""" # Set up URL's @@ -397,11 +365,9 @@ def tests_automation_trigger(self, m): # Set up automation automation_text = '[' + \ AUTOMATION.get_response_ok( - aid=1, - name='Test Automation', - is_active=True, - the_type=CONST.AUTOMATION_TYPE_LOCATION, - sub_type=CONST.AUTOMATION_SUBTYPE_ENTERING_HOME) + ']' + name='Test Automation One', + enabled=True, + aid=AID_1) + ']' m.get(CONST.AUTOMATION_URL, text=automation_text) @@ -410,65 +376,14 @@ def tests_automation_trigger(self, m): # Get the automation and test # pylint: disable=W0212 - automation = self.abode.get_automation(1) + automation = self.abode.get_automation(AID_1) self.assertIsNotNone(automation) - # Test that non-quick-actions will throw an exception - self.assertFalse(automation.is_quick_action) - - with self.assertRaises(abodepy.AbodeException): - automation.trigger() - - # Set up our quick action reply + # Set up our automation trigger reply set_active_url = str.replace(CONST.AUTOMATION_APPLY_URL, '$AUTOMATIONID$', automation.automation_id) - m.put(set_active_url, text=MOCK.generic_response_ok()) + m.post(set_active_url, text=MOCK.generic_response_ok()) # Test triggering - self.assertTrue(automation.trigger(only_manual=False)) - - @requests_mock.mock() - def tests_automation_filtering(self, m): - """Check that automations can be filtered by generic type.""" - # Set up URL's - m.post(CONST.LOGIN_URL, text=LOGIN.post_response_ok()) - m.get(CONST.OAUTH_TOKEN_URL, text=OAUTH_CLAIMS.get_response_ok()) - m.post(CONST.LOGOUT_URL, text=LOGOUT.post_response_ok()) - m.get(CONST.PANEL_URL, text=PANEL.get_response_ok()) - - # Set up automations - automation_text = '[' + \ - AUTOMATION.get_response_ok( - aid=1, - name='Test Automation Uno', - is_active=False, - the_type=CONST.AUTOMATION_TYPE_LOCATION, - sub_type=CONST.AUTOMATION_SUBTYPE_ENTERING_HOME) + ',' + \ - AUTOMATION.get_response_ok( - aid=2, - name='Test Automation Dos', - is_active=True, - the_type=CONST.AUTOMATION_TYPE_MANUAL) + ']' - - automation_json = json.loads(automation_text) - - m.get(CONST.AUTOMATION_URL, text=automation_text) - - # Logout to reset everything - self.abode.logout() - - # Get the automation and test - automations = self.abode.get_automations( - generic_type=CONST.TYPE_AUTOMATION) - - quick_actions = self.abode.get_automations( - generic_type=CONST.TYPE_QUICK_ACTION) - - # Tests - self.assertTrue(len(automations), 1) - self.assertTrue(len(quick_actions), 1) - - # pylint: disable=W0212 - self.assertEqual(automations[0]._automation, automation_json[0]) - self.assertEqual(quick_actions[0]._automation, automation_json[1]) + self.assertTrue(automation.trigger())