def tests_siren_settings(self, m): """Check that device panel siren settings are working.""" 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()) m.put(CONST.SIREN_URL, text=MOCK.generic_response_ok()) try: self.abode.set_setting(CONST.SETTING_SIREN_ENTRY_EXIT_SOUNDS, CONST.SETTING_ENABLE) self.abode.set_setting(CONST.SETTING_SIREN_CONFIRM_SOUNDS, CONST.SETTING_ENABLE) self.abode.set_setting(CONST.SETTING_SIREN_TAMPER_SOUNDS, CONST.SETTING_ENABLE) except abodepy.AbodeException: self.fail("set_setting() raised AbodeException unexpectedly") with self.assertRaises(abodepy.AbodeException): self.abode.set_setting(CONST.SETTING_SIREN_ENTRY_EXIT_SOUNDS, "foobar") with self.assertRaises(abodepy.AbodeException): self.abode.set_setting(CONST.SETTING_SIREN_CONFIRM_SOUNDS, "foobar") with self.assertRaises(abodepy.AbodeException): self.abode.set_setting(CONST.SETTING_SIREN_TAMPER_SOUNDS, "foobar")
def tests_area_settings(self, m): """Check that device panel areas settings are working.""" 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()) m.put(CONST.AREAS_URL, text=MOCK.generic_response_ok()) try: self.abode.set_setting(CONST.SETTING_ENTRY_DELAY_AWAY, CONST.SETTING_ENTRY_EXIT_DELAY_10SEC) self.abode.set_setting(CONST.SETTING_EXIT_DELAY_AWAY, CONST.SETTING_ENTRY_EXIT_DELAY_30SEC) except abodepy.AbodeException: self.fail("set_setting() raised AbodeException unexpectedly") with self.assertRaises(abodepy.AbodeException): self.abode.set_setting(CONST.SETTING_ENTRY_DELAY_AWAY, "foobar") # 10 seconds is invalid here with self.assertRaises(abodepy.AbodeException): self.abode.set_setting(CONST.SETTING_EXIT_DELAY_AWAY, CONST.SETTING_ENTRY_EXIT_DELAY_10SEC)
def tests_sound_settings(self, m): """Check that device panel sound settings are working.""" 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()) m.put(CONST.SOUNDS_URL, text=MOCK.generic_response_ok()) try: self.abode.set_setting(CONST.SETTING_DOOR_CHIME, CONST.SETTING_SOUND_LOW) self.abode.set_setting(CONST.SETTING_ALARM_LENGTH, CONST.SETTING_ALARM_LENGTH_2MIN) self.abode.set_setting(CONST.SETTING_FINAL_BEEPS, CONST.SETTING_FINAL_BEEPS_3SEC) except abodepy.AbodeException: self.fail("set_setting() raised AbodeException unexpectedly") with self.assertRaises(abodepy.AbodeException): self.abode.set_setting(CONST.SETTING_DOOR_CHIME, "foobar") with self.assertRaises(abodepy.AbodeException): self.abode.set_setting(CONST.SETTING_ALARM_LENGTH, "foobar") with self.assertRaises(abodepy.AbodeException): self.abode.set_setting(CONST.SETTING_FINAL_BEEPS, "foobar")
def tests_general_settings(self, m): """Check that device panel general settings are working.""" 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()) m.put(CONST.SETTINGS_URL, text=MOCK.generic_response_ok()) try: self.abode.set_setting(CONST.SETTING_CAMERA_RESOLUTION, CONST.SETTING_CAMERA_RES_640_480) self.abode.set_setting(CONST.SETTING_CAMERA_GRAYSCALE, CONST.SETTING_ENABLE) self.abode.set_setting(CONST.SETTING_SILENCE_SOUNDS, CONST.SETTING_ENABLE) except abodepy.AbodeException: self.fail("set_setting() raised AbodeException unexpectedly") with self.assertRaises(abodepy.AbodeException): self.abode.set_setting(CONST.SETTING_CAMERA_RESOLUTION, "foobar") with self.assertRaises(abodepy.AbodeException): self.abode.set_setting(CONST.SETTING_CAMERA_GRAYSCALE, "foobar") with self.assertRaises(abodepy.AbodeException): self.abode.set_setting(CONST.SETTING_SILENCE_SOUNDS, "foobar")
def tests_automation_trigger(self, m): """Check that automations can be triggered.""" # 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 automation automation_text = '[' + \ AUTOMATION.get_response_ok( name='Test Automation One', enabled=True, aid=AID_1) + ']' m.get(CONST.AUTOMATION_URL, text=automation_text) # Logout to reset everything self.abode.logout() # Get the automation and test # pylint: disable=W0212 automation = self.abode.get_automation(AID_1) self.assertIsNotNone(automation) # Set up our automation trigger reply set_active_url = str.replace(CONST.AUTOMATION_APPLY_URL, '$AUTOMATIONID$', automation.automation_id) m.post(set_active_url, text=MOCK.generic_response_ok()) # Test triggering self.assertTrue(automation.trigger())
def tests_settings_validation(self, m): """Check that device panel general settings are working.""" m.post(CONST.LOGIN_URL, text=LOGIN.post_response_ok()) m.post(CONST.LOGOUT_URL, text=LOGOUT.post_response_ok()) m.get(CONST.PANEL_URL, text=PANEL.get_response_ok()) m.get(CONST.SETTINGS_URL, text=MOCK.generic_response_ok()) with self.assertRaises(abodepy.AbodeException): self.abode.set_setting("fliptrix", "foobar")
def tests_camera_capture(self, m): """Tests that camera devices capture new images.""" # 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(mode=CONST.MODE_STANDBY)) m.get(CONST.DEVICES_URL, text=self.all_devices) # Test our camera devices for device in self.abode.get_devices(): # Skip alarm devices if device.type_tag == CONST.DEVICE_ALARM: continue # Specify which device module to use based on type_tag cam_type = set_cam_type(device.type_tag) # Test that we have the camera devices self.assertIsNotNone(device) self.assertEqual(device.status, CONST.STATUS_ONLINE) # Determine URL based on device type if device.type_tag == CONST.DEVICE_IP_CAM: url = CONST.BASE_URL + cam_type.CONTROL_URL_SNAPSHOT elif device.type_tag == CONST.DEVICE_MOTION_CAMERA: url = CONST.BASE_URL + cam_type.CONTROL_URL # Set up capture URL response m.put(url, text=MOCK.generic_response_ok()) # Capture an image self.assertTrue(device.capture()) # Change capture URL responses m.put(url, text=cam_type.get_capture_timeout(), status_code=600) # Capture an image with a failure self.assertFalse(device.capture()) # Remove control URLs from JSON to test if Abode makes # changes to JSON # pylint: disable=protected-access for key in list(device._json_state.keys()): if key.startswith("control_url"): # pylint: disable=protected-access del device._json_state[key] # Test that AbodeException is raised with no control URLs with self.assertRaises(AbodeException) as exc: device.capture() self.assertEqual(str(exc.exception), ERROR.MISSING_CONTROL_URL)
def tests_automation_trigger(self, m): """Check that automations can be triggered.""" # 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 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) + ']' m.get(CONST.AUTOMATION_URL, text=automation_text) # Logout to reset everything self.abode.logout() # Get the automation and test # pylint: disable=W0212 automation = self.abode.get_automation(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_active_url = str.replace(CONST.AUTOMATION_APPLY_URL, '$AUTOMATIONID$', automation.automation_id) m.put(set_active_url, text=MOCK.generic_response_ok()) # Test triggering self.assertTrue(automation.trigger(only_manual=False))
def tests_camera_capture(self, m): """Tests that camera devices capture new images.""" # 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(mode=CONST.MODE_STANDBY)) m.get(CONST.DEVICES_URL, text=IRCAMERA.device(devid=IRCAMERA.DEVICE_ID, status=CONST.STATUS_ONLINE, low_battery=False, no_response=False)) # Logout to reset everything self.abode.logout() # Get our camera device = self.abode.get_device(IRCAMERA.DEVICE_ID) # Test that we have our device self.assertIsNotNone(device) self.assertEqual(device.status, CONST.STATUS_ONLINE) # Set up capture url response url = str.replace(CONST.CAMS_ID_CAPTURE_URL, '$DEVID$', IRCAMERA.DEVICE_ID) m.put(url, text=MOCK.generic_response_ok()) # Capture the image self.assertTrue(device.capture()) # Change response m.put(url, text=IRCAMERA.get_capture_timeout(), status_code=600) # Capture the image with failure self.assertFalse(device.capture())