1# Copyright 2017 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.
14import logging
15
16logging.warning(
17    'The module mobly.controllers.android_device_lib.snippet_event '
18    'is deprecated and will be removed in a future version. Use '
19    'module mobly.snippet.callback_event instead.'
20)
21
22
23def from_dict(event_dict):
24  """Create a SnippetEvent object from a dictionary.
25
26  DEPRECATED: Use mobly.snippet.callback_event.from_dict instead.
27
28  Args:
29    event_dict: a dictionary representing an event.
30
31  Returns:
32    A SnippetEvent object.
33  """
34  return SnippetEvent(
35      callback_id=event_dict['callbackId'],
36      name=event_dict['name'],
37      creation_time=event_dict['time'],
38      data=event_dict['data'],
39  )
40
41
42class SnippetEvent:
43  """The class that represents callback events for mobly snippet library.
44
45  DEPRECATED: Use mobly.snippet.callback_event.CallbackEvent instead.
46
47  Attributes:
48    callback_id: string, the callback ID associated with the event.
49    name: string, the name of the event.
50    creation_time: int, the epoch time when the event is created on the
51      Rpc server side.
52    data: dictionary, the data held by the event. Can be None.
53  """
54
55  def __init__(self, callback_id, name, creation_time, data):
56    self.callback_id = callback_id
57    self.name = name
58    self.creation_time = creation_time
59    self.data = data
60
61  def __repr__(self):
62    return (
63        'SnippetEvent(callback_id: %s, name: %s, creation_time: %s, data: %s)'
64    ) % (self.callback_id, self.name, self.creation_time, self.data)
65