Exemple #1
0
    def _update_from_data(self):
        """Get the latest state of the sensor and update activity."""
        door_activity = self._data.activity_stream.get_latest_device_activity(
            self._device_id, [ActivityType.DOOR_OPERATION])

        if door_activity is not None:
            update_lock_detail_from_activity(self._detail, door_activity)
Exemple #2
0
    def _update_from_data(self):
        """Get the latest state of the sensor and update activity."""
        lock_activity = self._data.activity_stream.get_latest_device_activity(
            self._device_id, [ActivityType.LOCK_OPERATION])

        if lock_activity is not None:
            self._changed_by = lock_activity.operated_by
            update_lock_detail_from_activity(self._detail, lock_activity)

        self._update_lock_status_from_detail()
Exemple #3
0
    async def _call_lock_operation(self, lock_operation):
        activities = await lock_operation(self._device_id)
        for lock_activity in activities:
            update_lock_detail_from_activity(self._detail, lock_activity)

        if self._update_lock_status_from_detail():
            _LOGGER.debug(
                "async_signal_device_id_update (from lock operation): %s",
                self._device_id,
            )
            self._data.async_signal_device_id_update(self._device_id)
Exemple #4
0
    def test_update_lock_with_activity(self):
        lock = LockDetail(
            json.loads(load_fixture("get_lock.online_with_doorsense.json")))
        self.assertEqual("ABC", lock.device_id)
        self.assertEqual(LockStatus.LOCKED, lock.lock_status)
        self.assertEqual(LockDoorStatus.OPEN, lock.door_state)
        self.assertEqual(dateutil.parser.parse("2017-12-10T04:48:30.272Z"),
                         lock.lock_status_datetime)
        self.assertEqual(dateutil.parser.parse("2017-12-10T04:48:30.272Z"),
                         lock.door_state_datetime)

        lock_operation_activity = LockOperationActivity(
            json.loads(load_fixture("lock_activity.json")))
        unlock_operation_activity = LockOperationActivity(
            json.loads(load_fixture("unlock_activity.json")))
        open_operation_activity = DoorOperationActivity(
            json.loads(load_fixture("door_open_activity.json")))
        closed_operation_activity = DoorOperationActivity(
            json.loads(load_fixture("door_closed_activity.json")))
        closed_operation_wrong_deviceid_activity = DoorOperationActivity(
            json.loads(
                load_fixture("door_closed_activity_wrong_deviceid.json")))
        closed_operation_wrong_houseid_activity = DoorOperationActivity(
            json.loads(
                load_fixture("door_closed_activity_wrong_houseid.json")))

        self.assertTrue(
            update_lock_detail_from_activity(lock, unlock_operation_activity))
        self.assertEqual(LockStatus.UNLOCKED, lock.lock_status)
        self.assertEqual(
            as_utc_from_local(
                datetime.datetime.fromtimestamp(1582007217000 / 1000)),
            lock.lock_status_datetime,
        )

        self.assertTrue(
            update_lock_detail_from_activity(lock, lock_operation_activity))
        self.assertEqual(LockStatus.LOCKED, lock.lock_status)
        self.assertEqual(
            as_utc_from_local(
                datetime.datetime.fromtimestamp(1582007218000 / 1000)),
            lock.lock_status_datetime,
        )

        # returns false we send an older activity
        self.assertFalse(
            update_lock_detail_from_activity(lock, unlock_operation_activity))

        self.assertTrue(
            update_lock_detail_from_activity(lock, closed_operation_activity))
        self.assertEqual(LockDoorStatus.CLOSED, lock.door_state)
        self.assertEqual(
            as_utc_from_local(
                datetime.datetime.fromtimestamp(1582007217000 / 1000)),
            lock.door_state_datetime,
        )

        self.assertTrue(
            update_lock_detail_from_activity(lock, open_operation_activity))
        self.assertEqual(LockDoorStatus.OPEN, lock.door_state)
        self.assertEqual(
            as_utc_from_local(
                datetime.datetime.fromtimestamp(1582007219000 / 1000)),
            lock.door_state_datetime,
        )

        # returns false we send an older activity
        self.assertFalse(
            update_lock_detail_from_activity(lock, closed_operation_activity))

        with self.assertRaises(ValueError):
            update_lock_detail_from_activity(
                lock, closed_operation_wrong_deviceid_activity)

        # We do not always have the houseid so we do not throw
        # as long as the deviceid is correct since they are unique
        self.assertFalse(
            update_lock_detail_from_activity(
                lock, closed_operation_wrong_houseid_activity))

        self.assertEqual(LockDoorStatus.OPEN, lock.door_state)
        self.assertEqual(LockStatus.LOCKED, lock.lock_status)
        activities = _convert_lock_result_to_activities(
            json.loads(load_fixture("unlock.json")))
        for activity in activities:
            self.assertTrue(update_lock_detail_from_activity(lock, activity))
        self.assertEqual(LockDoorStatus.CLOSED, lock.door_state)
        self.assertEqual(LockStatus.UNLOCKED, lock.lock_status)