def tests_device_status_changes(self, m): """Tests that device status changes work as expected.""" # Set up URL's 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(mode=CONST.MODE_STANDBY)) m.get(CONST.DEVICES_URL, text=POWERSENSOR.device(devid=POWERSENSOR.DEVICE_ID, status=CONST.STATUS_OFF, low_battery=False, no_response=False)) # Logout to reset everything self.abode.logout() # Get our power switch device = self.abode.get_device(POWERSENSOR.DEVICE_ID) # Test that we have our device self.assertIsNotNone(device) self.assertEqual(device.status, CONST.STATUS_OFF) self.assertFalse(device.is_on) # Set up control url response control_url = CONST.BASE_URL + POWERSENSOR.CONTROL_URL m.put(control_url, text=DEVICES.status_put_response_ok(devid=POWERSENSOR.DEVICE_ID, status=CONST.STATUS_ON_INT)) # Change the mode to "on" self.assertTrue(device.switch_on()) self.assertEqual(device.status, CONST.STATUS_ON) self.assertTrue(device.is_on) # Change response m.put(control_url, text=DEVICES.status_put_response_ok(devid=POWERSENSOR.DEVICE_ID, status=CONST.STATUS_OFF_INT)) # Change the mode to "off" self.assertTrue(device.switch_off()) self.assertEqual(device.status, CONST.STATUS_OFF) self.assertFalse(device.is_on) # Test that an invalid device ID in response throws exception m.put(control_url, text=DEVICES.status_put_response_ok(devid='ZW:deadbeef', status=CONST.STATUS_OFF_INT)) with self.assertRaises(abodepy.AbodeException): device.switch_on() # Test that an invalid status in response throws exception m.put(control_url, text=DEVICES.status_put_response_ok(devid=POWERSENSOR.DEVICE_ID, status=CONST.STATUS_OFF_INT)) with self.assertRaises(abodepy.AbodeException): device.switch_on()
def tests_lock_device_mode_changes(self, m): """Tests that lock device changes work as expected.""" # 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=DOOR_LOCK.device(devid=DOOR_LOCK.DEVICE_ID, status=CONST.STATUS_LOCKCLOSED, low_battery=False, no_response=False)) # Logout to reset everything self.abode.logout() # Get our power switch device = self.abode.get_device(DOOR_LOCK.DEVICE_ID) # Test that we have our device self.assertIsNotNone(device) self.assertEqual(device.status, CONST.STATUS_LOCKCLOSED) self.assertTrue(device.is_locked) # Set up control url response control_url = CONST.BASE_URL + DOOR_LOCK.CONTROL_URL m.put(control_url, text=DEVICES.status_put_response_ok( devid=DOOR_LOCK.DEVICE_ID, status=CONST.STATUS_LOCKOPEN_INT)) # Change the mode to "on" self.assertTrue(device.unlock()) self.assertEqual(device.status, CONST.STATUS_LOCKOPEN) self.assertFalse(device.is_locked) # Change response m.put(control_url, text=DEVICES.status_put_response_ok( devid=DOOR_LOCK.DEVICE_ID, status=CONST.STATUS_LOCKCLOSED_INT)) # Change the mode to "off" self.assertTrue(device.lock()) self.assertEqual(device.status, CONST.STATUS_LOCKCLOSED) self.assertTrue(device.is_locked) # Test that an invalid status response throws exception m.put(control_url, text=DEVICES.status_put_response_ok( devid=DOOR_LOCK.DEVICE_ID, status=CONST.STATUS_LOCKCLOSED_INT)) with self.assertRaises(abodepy.AbodeException): device.unlock()
def tests_cover_status_changes(self, m): """Tests that cover device changes work as expected.""" # 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=COVER.device(devid=COVER.DEVICE_ID, status=CONST.STATUS_CLOSED, low_battery=False, no_response=False)) # Logout to reset everything self.abode.logout() # Get our power switch device = self.abode.get_device(COVER.DEVICE_ID) # Test that we have our device self.assertIsNotNone(device) self.assertEqual(device.status, CONST.STATUS_CLOSED) self.assertFalse(device.is_open) # Set up control url response control_url = CONST.BASE_URL + COVER.CONTROL_URL m.put(control_url, text=DEVICES.status_put_response_ok( devid=COVER.DEVICE_ID, status=CONST.STATUS_OPEN_INT)) # Change the cover to open self.assertTrue(device.open_cover()) self.assertEqual(device.status, CONST.STATUS_OPEN) self.assertTrue(device.is_open) # Change response m.put(control_url, text=DEVICES.status_put_response_ok( devid=COVER.DEVICE_ID, status=CONST.STATUS_CLOSED_INT)) # Change the mode to "off" self.assertTrue(device.close_cover()) self.assertEqual(device.status, CONST.STATUS_CLOSED) self.assertFalse(device.is_open)
def tests_hue_status_changes(self, m): """Tests that hue device changes work as expected.""" # 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=HUE.device(devid=HUE.DEVICE_ID, status=CONST.STATUS_OFF, level=0, saturation=57, hue=60, color_temp=6536, color_mode=CONST.COLOR_MODE_ON, low_battery=False, no_response=False)) # Logout to reset everything self.abode.logout() # Get our hue device device = self.abode.get_device(HUE.DEVICE_ID) # Test that we have our device self.assertIsNotNone(device) self.assertEqual(device.status, CONST.STATUS_OFF) self.assertFalse(device.is_on) # Set up control url response control_url = CONST.BASE_URL + HUE.CONTROL_URL m.put(control_url, text=DEVICES.status_put_response_ok( devid=HUE.DEVICE_ID, status=CONST.STATUS_ON_INT)) # Change the mode to "on" self.assertTrue(device.switch_on()) self.assertEqual(device.status, CONST.STATUS_ON) self.assertTrue(device.is_on) # Change response m.put(control_url, text=DEVICES.status_put_response_ok( devid=HUE.DEVICE_ID, status=CONST.STATUS_OFF_INT)) # Change the mode to "off" self.assertTrue(device.switch_off()) self.assertEqual(device.status, CONST.STATUS_OFF) self.assertFalse(device.is_on) # Test that an invalid status response throws exception m.put(control_url, text=DEVICES.status_put_response_ok( devid=HUE.DEVICE_ID, status=CONST.STATUS_OFF_INT)) with self.assertRaises(abodepy.AbodeException): device.switch_on()