-
Notifications
You must be signed in to change notification settings - Fork 2
/
ui.py
59 lines (43 loc) · 1.71 KB
/
ui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""Protocol that defines how to interact with the User Interface."""
from typing import Protocol, Optional
from .sp_dev import SPDev
class UI(Protocol):
"""
Python protocol class for an User Interface.
"""
def on_broker_connected(self, result) -> None:
"""Called when the connection to the broker is established or has failed.
:param result: The connection result: 0 if successful or an error code."""
def on_broker_disconnected(self, result) -> None:
"""Called when the connection to the broker is lost.
:param result: O if the disconnection was requested,
another value if was unexpected."""
def on_device_added(self, sp_dev: SPDev) -> None:
"""Called when a device is added."""
def on_device_removed(self, sp_dev: SPDev) -> None:
"""Called when a device is removed."""
def on_metric_updated(self, sp_dev: SPDev, metric) -> None:
"""Called when a metric is updated."""
def run(self) -> Optional[int]:
"""
Starts the UI loop.
Should block until exit.
May return an exit code.
"""
class UIStub:
"""UI Stub class that does nothing."""
def __init__(self):
"""Does nothing."""
def on_broker_connected(self, _result) -> None:
"""Does nothing."""
def on_broker_disconnected(self, _result) -> None:
"""Does nothing."""
def on_device_added(self, sp_dev: SPDev) -> None:
"""Does nothing."""
def on_device_removed(self, sp_dev: SPDev) -> None:
"""Does nothing."""
def on_metric_updated(self, sp_dev: SPDev, metric) -> None:
"""Does nothing."""
def run(self) -> Optional[int]:
"""Does nothing."""
return 0