Ejemplo n.º 1
0
    def get_lock_door_status(self, access_token, lock_id, lock_status=False):
        json_dict = self._dict_to_api(
            self._build_get_lock_status_request(access_token, lock_id)).json()

        if lock_status:
            return (
                determine_door_state(json_dict.get("doorState")),
                determine_lock_status(json_dict.get("status")),
            )

        return determine_door_state(json_dict.get("doorState"))
Ejemplo n.º 2
0
    async def async_get_lock_door_status(self,
                                         access_token,
                                         lock_id,
                                         lock_status=False):
        response = await self._async_dict_to_api(
            self._build_get_lock_status_request(access_token, lock_id))
        json_dict = await response.json()

        if lock_status:
            return (
                determine_door_state(json_dict.get("doorState")),
                determine_lock_status(json_dict.get("status")),
            )

        return determine_door_state(json_dict.get("doorState"))
Ejemplo n.º 3
0
def update_lock_details_from_pubnub_message(lock_detail, date_time, message):
    """Update lock details from pubnub."""
    updated = False

    if LOCK_STATUS_KEY in message and lock_detail.lock_status_datetime < date_time:
        lock_status = determine_lock_status(message[LOCK_STATUS_KEY])
        if lock_status != LockStatus.UNKNOWN:
            lock_detail.lock_status = determine_lock_status(
                message[LOCK_STATUS_KEY])
            lock_detail.lock_status_datetime = date_time
            updated = True

    if DOOR_STATE_KEY in message and lock_detail.door_state_datetime < date_time:
        door_state = determine_door_state(message[DOOR_STATE_KEY])
        if door_state != LockDoorStatus.UNKNOWN:
            lock_detail.door_state = determine_door_state(
                message[DOOR_STATE_KEY])
            lock_detail.door_state_datetime = date_time
            updated = True

    return updated
Ejemplo n.º 4
0
def _convert_lock_result_to_activities(lock_json_dict):
    activities = []
    lock_info_json_dict = lock_json_dict.get("info", {})
    lock_id = lock_info_json_dict.get("lockID")
    lock_action_text = lock_info_json_dict.get("action")
    activity_epoch = _datetime_string_to_epoch(
        lock_info_json_dict.get("startTime"))
    activity_lock_dict = _map_lock_result_to_activity(lock_id, activity_epoch,
                                                      lock_action_text)
    activities.append(activity_lock_dict)

    door_state = determine_door_state(lock_json_dict.get("doorState"))
    if door_state != LockDoorStatus.UNKNOWN:
        activity_door_dict = _map_lock_result_to_activity(
            lock_id, activity_epoch, door_state_to_string(door_state))
        activities.append(activity_door_dict)

    return activities