• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2022 Google Inc.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14"""The class that represents callback events for Mobly Snippet Lib."""
15
16
17def from_dict(event_dict):
18  """Creates a CallbackEvent object from a dictionary.
19
20  Args:
21    event_dict: dict, a dictionary representing an event.
22
23  Returns:
24    A CallbackEvent object.
25  """
26  return CallbackEvent(
27      callback_id=event_dict['callbackId'],
28      name=event_dict['name'],
29      creation_time=event_dict['time'],
30      data=event_dict['data'],
31  )
32
33
34class CallbackEvent:
35  """The class that represents callback events for Mobly Snippet Library.
36
37  Attributes:
38    callback_id: str, the callback ID associated with the event.
39    name: str, the name of the event.
40    creation_time: int, the epoch time when the event is created on the
41      RPC server side.
42    data: dict, the data held by the event. Can be None.
43  """
44
45  def __init__(self, callback_id, name, creation_time, data):
46    self.callback_id = callback_id
47    self.name = name
48    self.creation_time = creation_time
49    self.data = data
50
51  def __repr__(self):
52    return (
53        f'CallbackEvent(callback_id: {self.callback_id}, name: {self.name}, '
54        f'creation_time: {self.creation_time}, data: {self.data})'
55    )
56