Beispiel #1
0
    def tests_lock_device_properties(self, m):
        """Tests that lock 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=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 lock
        device = self.abode.get_device(DOOR_LOCK.DEVICE_ID)

        # Test our device
        self.assertIsNotNone(device)
        self.assertEqual(device.status, CONST.STATUS_LOCKCLOSED)
        self.assertFalse(device.battery_low)
        self.assertFalse(device.no_response)
        self.assertTrue(device.is_locked)

        # Set up our direct device get url
        device_url = str.replace(CONST.DEVICE_URL, '$DEVID$',
                                 DOOR_LOCK.DEVICE_ID)

        # Change device properties
        m.get(device_url,
              text=DOOR_LOCK.device(devid=DOOR_LOCK.DEVICE_ID,
                                    status=CONST.STATUS_LOCKOPEN,
                                    low_battery=True,
                                    no_response=True))

        # Refesh device and test changes
        device.refresh()

        self.assertEqual(device.status, CONST.STATUS_LOCKOPEN)
        self.assertTrue(device.battery_low)
        self.assertTrue(device.no_response)
        self.assertFalse(device.is_locked)
Beispiel #2
0
    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()
Beispiel #3
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__))