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_switch_device_properties(self, m): """Tests that switch devices properties 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=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 our device self.assertIsNotNone(device) self.assertEqual(device.status, CONST.STATUS_OFF) self.assertFalse(device.battery_low) self.assertFalse(device.no_response) self.assertFalse(device.is_on) # Set up our direct device get url device_url = str.replace(CONST.DEVICE_URL, '$DEVID$', POWERSENSOR.DEVICE_ID) # Change device properties m.get(device_url, text=POWERSENSOR.device(devid=POWERSENSOR.DEVICE_ID, status=CONST.STATUS_ON, low_battery=True, no_response=True)) # Refesh device and test changes device.refresh() self.assertEqual(device.status, CONST.STATUS_ON) self.assertTrue(device.battery_low) self.assertTrue(device.no_response) self.assertTrue(device.is_on)
def tests_device_category_filter(self, m): """Tests that device category filter returns requested results.""" # 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)) # Set up a list of devices dev_list = '[' + \ POWERSENSOR.device(devid='ps1', status=CONST.STATUS_OFF, low_battery=False, no_response=False) + "," + \ POWERSENSOR.device(devid='ps2', status=CONST.STATUS_OFF, low_battery=False, no_response=False) + "," + \ GLASS.device(devid='gb1', status=CONST.STATUS_OFF, low_battery=False, no_response=False) + ']' m.get(CONST.DEVICES_URL, text=dev_list) # Logout to reset everything self.abode.logout() # Get our glass devices devices = self.abode.get_devices( generic_type=(CONST.TYPE_CONNECTIVITY)) self.assertIsNotNone(devices) self.assertEqual(len(devices), 1) # Get our power switch devices devices = self.abode.get_devices( generic_type=(CONST.TYPE_SWITCH)) self.assertIsNotNone(devices) self.assertEqual(len(devices), 2)
def tests_multiple_devices(self, m): """Tests that multiple devices are returned properly.""" # 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)) # Set up a list of devices dev_list = '[' + \ POWERSENSOR.device() + "," + \ DOOR_CONTACT.device() + "," + \ GLASS.device() + ']' m.get(CONST.DEVICES_URL, text=dev_list) # Logout to reset everything self.abode.logout() # Get our devices devices = self.abode.get_devices() # Assert four devices - three from above + 1 alarm self.assertIsNotNone(devices) self.assertEqual(len(devices), 4) # Get each individual device by device ID psd = self.abode.get_device(POWERSENSOR.DEVICE_ID) self.assertIsNotNone(psd) # Get each individual device by device ID psd = self.abode.get_device(DOOR_CONTACT.DEVICE_ID) self.assertIsNotNone(psd) # Get each individual device by device ID psd = self.abode.get_device(GLASS.DEVICE_ID) self.assertIsNotNone(psd)
def tests_all_devices(self, m): """Tests that all mocked devices are mapped correctly.""" # 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)) # Create all devices all_devices = '[' + \ DOOR_CONTACT.device() + ',' + \ DOOR_LOCK.device() + ',' + \ GLASS.device() + ',' + \ IR_CAMERA.device() + ',' + \ KEYPAD.device() + ',' + \ PIR.device() + ',' + \ POWERMETER.device() + ',' + \ POWERSENSOR.device() + ',' + \ REMOTE_CONTROLLER.device() + ',' + \ SECUREBARRIER.device() + ',' + \ SIREN.device() + ',' + \ STATUS_DISPLAY.device() + ',' + \ WATER_SENSOR.device() + ']' m.get(CONST.DEVICES_URL, text=all_devices) # Logout to reset everything self.abode.logout() # Loop through all devices for device in self.abode.get_devices(): class_type = { # Alarm CONST.TYPE_ALARM: AbodeAlarm, # Binary Sensors CONST.TYPE_CONNECTIVITY: AbodeBinarySensor, CONST.TYPE_MOISTURE: AbodeBinarySensor, CONST.TYPE_OPENING: AbodeBinarySensor, CONST.TYPE_MOTION: AbodeBinarySensor, CONST.TYPE_OCCUPANCY: AbodeBinarySensor, # Camera CONST.TYPE_CAMERA: AbodeDevice, # Cover CONST.TYPE_COVER: AbodeCover, # Dimmer CONST.TYPE_LIGHT: AbodeLight, # Lock CONST.TYPE_LOCK: AbodeLock, # Switch CONST.TYPE_SWITCH: AbodeSwitch }.get(device.generic_type) self.assertIsNotNone(class_type, device.type + ' is not mapped.') self.assertTrue( isinstance(device, class_type), device.type + ' is of class ' + str(device.__class__.__name__) + ' but mapped to ' + str(class_type.__name__))
def tests_device_level_changes(self, m): """Tests that device level 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)) # TODO: Test with a device that supports levels 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.level_put_response_ok(devid=POWERSENSOR.DEVICE_ID, level='100')) # Change the level to int 100 self.assertTrue(device.set_level(100)) # self.assertEqual(device.level, '100') # Change response control_url = CONST.BASE_URL + POWERSENSOR.CONTROL_URL m.put(control_url, text=DEVICES.level_put_response_ok(devid=POWERSENSOR.DEVICE_ID, level='25')) # Change the level to str '25' self.assertTrue(device.set_level('25')) # self.assertEqual(device.level, '25') # Test that an invalid device ID in response throws exception m.put(control_url, text=DEVICES.level_put_response_ok(devid='ZW:deadbeef', level='25')) with self.assertRaises(abodepy.AbodeException): device.set_level(25) # Test that an invalid level in response throws exception m.put(control_url, text=DEVICES.level_put_response_ok(devid=POWERSENSOR.DEVICE_ID, level='98')) with self.assertRaises(abodepy.AbodeException): device.set_level('28')