Example #1
0
    def tests_generic_device_refresh(self, m):
        """Check the generic Abode device class init's 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())

        # Set up online device
        device_text_online = '[' + \
            GLASS.device(status=CONST.STATUS_ONLINE) + ']'
        m.get(CONST.DEVICES_URL, text=device_text_online)

        # Set up offline device
        device_text_offline = '[' + \
            GLASS.device(status=CONST.STATUS_OFFLINE) + ']'
        device_url = str.replace(CONST.DEVICE_URL, '$DEVID$', GLASS.DEVICE_ID)
        m.get(device_url, text=device_text_offline)

        # Logout to reset everything
        self.abode.logout()

        # Get the first device and test
        device = self.abode.get_device(GLASS.DEVICE_ID)
        self.assertEqual(device.status, CONST.STATUS_ONLINE)

        # Refresh the device and test
        device = self.abode.get_device(GLASS.DEVICE_ID, refresh=True)
        self.assertEqual(device.status, CONST.STATUS_OFFLINE)
Example #2
0
    def tests_device_auto_naming(self):
        """Check the generic Abode device creates a name."""
        # Set up device
        device_text = GLASS.device(status=CONST.STATUS_ONLINE,
                                   low_battery=True,
                                   no_response=True,
                                   tampered=True,
                                   out_of_order=True)

        device_json = json.loads(device_text)

        device_json['name'] = ""
        device = abodepy.new_device(device_json, self.abode)
        generated_name = device.type + ' ' + device.device_id
        self.assertEqual(device.name, generated_name)

        device_json['name'] = None
        device = abodepy.new_device(device_json, self.abode)
        generated_name = device.type + ' ' + device.device_id
        self.assertEqual(device.name, generated_name)

        del device_json['name']
        device = abodepy.new_device(device_json, self.abode)
        generated_name = device.type + ' ' + device.device_id
        self.assertEqual(device.name, generated_name)
Example #3
0
    def tests_no_control_url(self, m):
        """Check that devices return false without control url's."""
        # 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())

        m.get(CONST.DEVICES_URL, text=GLASS.device(status=CONST.STATUS_ONLINE))

        # Logout to reset everything
        self.abode.logout()

        # Get device
        device = self.abode.get_device(GLASS.DEVICE_ID)

        self.assertIsNotNone(device)
        self.assertFalse(device.set_status('1'))
        self.assertFalse(device.set_level('99'))
Example #4
0
    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)
Example #5
0
    def tests_device_mapping_typetag(self):
        """Check the generic Abode device maps to none without typetag."""
        # Set up device
        device_text = GLASS.device(
            status=CONST.STATUS_ONLINE,
            low_battery=True, no_response=True,
            tampered=True, out_of_order=True)

        device_json = json.loads(device_text)

        with self.assertRaises(abodepy.AbodeException):
            device_json['type_tag'] = ""
            abodepy.new_device(device_json, self.abode)

        with self.assertRaises(abodepy.AbodeException):
            device_json['type_tag'] = None
            abodepy.new_device(device_json, self.abode)

        with self.assertRaises(abodepy.AbodeException):
            del device_json['type_tag']
            abodepy.new_device(device_json, self.abode)
Example #6
0
    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)
Example #7
0
    def tests_device_init(self, m):
        """Check the generic Abode device class init's properly."""
        # Set up URLs
        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 device
        device_text = '[' + GLASS.device(
            status=CONST.STATUS_ONLINE,
            low_battery=True, no_response=True,
            tampered=True, out_of_order=True,
            uuid='testuuid00000001') + ']'
        device_json = json.loads(device_text)

        m.get(CONST.DEVICES_URL, text=device_text)

        # Logout to reset everything
        self.abode.logout()

        # Get our specific device
        device = self.abode.get_device(GLASS.DEVICE_ID)

        # Check device states match
        self.assertIsNotNone(device)
        # pylint: disable=W0212
        self.assertEqual(device.name, device_json[0]['name'])
        self.assertEqual(device.type, device_json[0]['type'])
        self.assertEqual(device.type_tag, device_json[0]['type_tag'])
        self.assertEqual(device.device_id, device_json[0]['id'])
        self.assertEqual(device.device_uuid, device_json[0]['uuid'])
        self.assertEqual(device.status, CONST.STATUS_ONLINE)
        self.assertTrue(device.battery_low)
        self.assertTrue(device.no_response)
        self.assertTrue(device.tampered)
        self.assertTrue(device.out_of_order)
        self.assertIsNotNone(device.desc)
Example #8
0
    def tests_binary_sensor_properties(self, m):
        """Tests that binary sensor device 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))

        # Set up all Binary Sensor Devices in "off states"
        all_devices = '[' + \
            DOOR_CONTACT.device(devid=DOOR_CONTACT.DEVICE_ID,
                                status=CONST.STATUS_CLOSED,
                                low_battery=False,
                                no_response=False) + ',' + \
            GLASS.device(devid=GLASS.DEVICE_ID,
                         status=CONST.STATUS_OFFLINE,
                         low_battery=False,
                         no_response=False) + ',' + \
            KEYPAD.device(devid=KEYPAD.DEVICE_ID,
                          status=CONST.STATUS_OFFLINE,
                          low_battery=False,
                          no_response=False) + ',' + \
            REMOTE_CONTROLLER.device(devid=REMOTE_CONTROLLER.DEVICE_ID,
                                     status=CONST.STATUS_OFFLINE,
                                     low_battery=False,
                                     no_response=False) + ',' + \
            SIREN.device(devid=SIREN.DEVICE_ID,
                         status=CONST.STATUS_OFFLINE,
                         low_battery=False,
                         no_response=False) + ',' + \
            STATUS_DISPLAY.device(devid=STATUS_DISPLAY.DEVICE_ID,
                                  status=CONST.STATUS_OFFLINE,
                                  low_battery=False,
                                  no_response=False) + ',' + \
            WATER_SENSOR.device(devid=WATER_SENSOR.DEVICE_ID,
                                status=CONST.STATUS_OFFLINE,
                                low_battery=False,
                                no_response=False) + ']'

        m.get(CONST.DEVICES_URL, text=all_devices)

        # Logout to reset everything
        self.abode.logout()

        # Test our devices
        for device in self.abode.get_devices():
            # Skip alarm devices
            if device.type == CONST.DEVICE_ALARM:
                continue

            self.assertFalse(device.is_on, device.type + " is_on failed")
            self.assertFalse(device.battery_low,
                             device.type + " battery_low failed")
            self.assertFalse(device.no_response,
                             device.type + " no_response failed")

        # Set up all Binary Sensor Devices in "off states"
        all_devices = '[' + \
            DOOR_CONTACT.device(devid=DOOR_CONTACT.DEVICE_ID,
                                status=CONST.STATUS_OPEN,
                                low_battery=True,
                                no_response=True) + ',' + \
            GLASS.device(devid=GLASS.DEVICE_ID,
                         status=CONST.STATUS_ONLINE,
                         low_battery=True,
                         no_response=True) + ',' + \
            KEYPAD.device(devid=KEYPAD.DEVICE_ID,
                          status=CONST.STATUS_ONLINE,
                          low_battery=True,
                          no_response=True) + ',' + \
            REMOTE_CONTROLLER.device(devid=REMOTE_CONTROLLER.DEVICE_ID,
                                     status=CONST.STATUS_ONLINE,
                                     low_battery=True,
                                     no_response=True) + ',' + \
            SIREN.device(devid=SIREN.DEVICE_ID,
                         status=CONST.STATUS_ONLINE,
                         low_battery=True,
                         no_response=True) + ',' + \
            STATUS_DISPLAY.device(devid=STATUS_DISPLAY.DEVICE_ID,
                                  status=CONST.STATUS_ONLINE,
                                  low_battery=True,
                                  no_response=True) + ',' + \
            WATER_SENSOR.device(devid=WATER_SENSOR.DEVICE_ID,
                                status=CONST.STATUS_ONLINE,
                                low_battery=True,
                                no_response=True) + ']'

        m.get(CONST.DEVICES_URL, text=all_devices)

        # Refesh devices and test changes
        for device in self.abode.get_devices(refresh=True):
            # Skip alarm devices
            if device.type_tag == CONST.DEVICE_ALARM:
                continue

            self.assertTrue(device.is_on, device.type + " is_on failed")
            self.assertTrue(device.battery_low,
                            device.type + " battery_low failed")
            self.assertTrue(device.no_response,
                            device.type + " no_response failed")
Example #9
0
    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__))