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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
# -*- coding: utf-8 -*-
"""
Constants used throughout the modules
"""
import asyncio
from typing import Any, Callable, List, NamedTuple, Optional, Union
#
# DEFAULT values
#
DEFAULT_CMD = 'vnd.logitech.connect'
DEFAULT_DISCOVER_STRING = '_logitech-reverse-bonjour._tcp.local.'
DEFAULT_XMPP_HUB_PORT = '5222'
DEFAULT_WS_HUB_PORT = '8088'
DEFAULT_HARMONY_MIME = 'vnd.logitech.harmony/vnd.logitech.harmony.engine'
WEBSOCKETS = 'WEBSOCKETS'
XMPP = 'XMPP'
PROTOCOL = Union[WEBSOCKETS, XMPP]
#
# The HUB commands that can be send
#
HUB_COMMANDS = {
'change_channel': {
'mime': 'harmony.engine',
'command': 'changeChannel'
},
'get_current_state': {
'mime': 'vnd.logitech.connect/vnd.logitech.statedigest',
'command': 'get'
},
'get_config': {
'mime': DEFAULT_HARMONY_MIME,
'command': 'config'
},
'get_current_activity': {
'mime': DEFAULT_HARMONY_MIME,
'command': 'getCurrentActivity'
},
'send_command': {
'mime': DEFAULT_HARMONY_MIME,
'command': 'holdAction'
},
'start_activity': {
'mime': 'harmony.activityengine',
'command': 'runactivity'
},
'sync': {
'mime': 'setup.sync',
'command': None
},
'provision_info': {
'mime': 'setup.account',
'command': 'getProvisionInfo'
},
'discovery': {
'mime': 'connect.discoveryinfo',
'command': 'get'
},
}
#
# Different types used within aioharmony
#
# Type for callback parameters
CallbackType = Union[
asyncio.Future,
asyncio.Event,
Callable[[object, Optional[Any]], Any]
]
ClientCallbackType = NamedTuple('ClientCallbackType',
[('connect', Optional[CallbackType]),
('disconnect', Optional[CallbackType]),
('new_activity_starting', Optional[CallbackType]),
('new_activity', Optional[CallbackType]),
('config_updated', Optional[CallbackType])
])
ConnectorCallbackType = NamedTuple('ConnectorCallbackType',
[('connect', Optional[CallbackType]),
('disconnect', Optional[CallbackType])
])
ClientConfigType = NamedTuple('ClientConfigType',
[('config', dict),
('info', dict),
('discover_info', dict),
('hub_state', dict),
('config_version', Optional[int]),
('activities', List[dict]),
('devices', List[dict])
])
# Type for a command to send to the HUB
SendCommandDevice = NamedTuple('SendCommandDevice',
[('device', int),
('command', str),
('delay', float)
])
# Type for send command to aioharmony,
SendCommand = Union[SendCommandDevice, Union[float, int]]
SendCommandArg = Union[SendCommand, List[SendCommand]]
# Response from send commands.
SendCommandResponse = NamedTuple('SendCommandResponse',
[('command', SendCommandDevice),
('code', str),
('msg', str)
])
|