zmc
2023-08-08 e792e9a60d958b93aef96050644f369feb25d61b
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# DO NOT EDIT THIS FILE!
#
# This file is generated from the CDP specification. If you need to make
# changes, edit the generator and regenerate all of the modules.
#
# CDP domain: DeviceAccess (experimental)
from __future__ import annotations
from .util import event_class, T_JSON_DICT
from dataclasses import dataclass
import enum
import typing
 
class RequestId(str):
    '''
    Device request id.
    '''
    def to_json(self) -> str:
        return self
 
    @classmethod
    def from_json(cls, json: str) -> RequestId:
        return cls(json)
 
    def __repr__(self):
        return 'RequestId({})'.format(super().__repr__())
 
 
class DeviceId(str):
    '''
    A device id.
    '''
    def to_json(self) -> str:
        return self
 
    @classmethod
    def from_json(cls, json: str) -> DeviceId:
        return cls(json)
 
    def __repr__(self):
        return 'DeviceId({})'.format(super().__repr__())
 
 
@dataclass
class PromptDevice:
    '''
    Device information displayed in a user prompt to select a device.
    '''
    id_: DeviceId
 
    #: Display name as it appears in a device request user prompt.
    name: str
 
    def to_json(self):
        json = dict()
        json['id'] = self.id_.to_json()
        json['name'] = self.name
        return json
 
    @classmethod
    def from_json(cls, json):
        return cls(
            id_=DeviceId.from_json(json['id']),
            name=str(json['name']),
        )
 
 
def enable() -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
    '''
    Enable events in this domain.
    '''
    cmd_dict: T_JSON_DICT = {
        'method': 'DeviceAccess.enable',
    }
    json = yield cmd_dict
 
 
def disable() -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
    '''
    Disable events in this domain.
    '''
    cmd_dict: T_JSON_DICT = {
        'method': 'DeviceAccess.disable',
    }
    json = yield cmd_dict
 
 
def select_prompt(
        id_: RequestId,
        device_id: DeviceId
    ) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
    '''
    Select a device in response to a DeviceAccess.deviceRequestPrompted event.
 
    :param id_:
    :param device_id:
    '''
    params: T_JSON_DICT = dict()
    params['id'] = id_.to_json()
    params['deviceId'] = device_id.to_json()
    cmd_dict: T_JSON_DICT = {
        'method': 'DeviceAccess.selectPrompt',
        'params': params,
    }
    json = yield cmd_dict
 
 
def cancel_prompt(
        id_: RequestId
    ) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
    '''
    Cancel a prompt in response to a DeviceAccess.deviceRequestPrompted event.
 
    :param id_:
    '''
    params: T_JSON_DICT = dict()
    params['id'] = id_.to_json()
    cmd_dict: T_JSON_DICT = {
        'method': 'DeviceAccess.cancelPrompt',
        'params': params,
    }
    json = yield cmd_dict
 
 
@event_class('DeviceAccess.deviceRequestPrompted')
@dataclass
class DeviceRequestPrompted:
    '''
    A device request opened a user prompt to select a device. Respond with the
    selectPrompt or cancelPrompt command.
    '''
    id_: RequestId
    devices: typing.List[PromptDevice]
 
    @classmethod
    def from_json(cls, json: T_JSON_DICT) -> DeviceRequestPrompted:
        return cls(
            id_=RequestId.from_json(json['id']),
            devices=[PromptDevice.from_json(i) for i in json['devices']]
        )