Example #1
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 #2
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__))