pymammotion 0.0.37__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of pymammotion might be problematic. Click here for more details.

Files changed (106) hide show
  1. pymammotion/__init__.py +43 -0
  2. pymammotion/aliyun/cloud_gateway.py +549 -0
  3. pymammotion/aliyun/cloud_service.py +65 -0
  4. pymammotion/aliyun/dataclass/aep_response.py +18 -0
  5. pymammotion/aliyun/dataclass/connect_response.py +51 -0
  6. pymammotion/aliyun/dataclass/dev_by_account_response.py +43 -0
  7. pymammotion/aliyun/dataclass/login_by_oauth_response.py +65 -0
  8. pymammotion/aliyun/dataclass/regions_response.py +26 -0
  9. pymammotion/aliyun/dataclass/session_by_authcode_response.py +18 -0
  10. pymammotion/aliyun/tmp_constant.py +175 -0
  11. pymammotion/bluetooth/__init__.py +1 -0
  12. pymammotion/bluetooth/ble.py +74 -0
  13. pymammotion/bluetooth/ble_message.py +430 -0
  14. pymammotion/bluetooth/const.py +27 -0
  15. pymammotion/bluetooth/data/__init__.py +0 -0
  16. pymammotion/bluetooth/data/convert.py +26 -0
  17. pymammotion/bluetooth/data/framectrldata.py +40 -0
  18. pymammotion/bluetooth/data/notifydata.py +63 -0
  19. pymammotion/const.py +9 -0
  20. pymammotion/data/__init__.py +0 -0
  21. pymammotion/data/model/__init__.py +8 -0
  22. pymammotion/data/model/device.py +157 -0
  23. pymammotion/data/model/enums.py +67 -0
  24. pymammotion/data/model/excute_boarder_params.py +48 -0
  25. pymammotion/data/model/execute_boarder.py +36 -0
  26. pymammotion/data/model/generate_route_information.py +133 -0
  27. pymammotion/data/model/hash_list.py +17 -0
  28. pymammotion/data/model/mowing_modes.py +37 -0
  29. pymammotion/data/model/plan.py +58 -0
  30. pymammotion/data/model/rapid_state.py +45 -0
  31. pymammotion/data/model/region_data.py +99 -0
  32. pymammotion/data/mqtt/__init__.py +1 -0
  33. pymammotion/data/mqtt/event.py +90 -0
  34. pymammotion/data/mqtt/properties.py +140 -0
  35. pymammotion/data/mqtt/status.py +52 -0
  36. pymammotion/event/__init__.py +6 -0
  37. pymammotion/event/event.py +50 -0
  38. pymammotion/http/_init_.py +0 -0
  39. pymammotion/http/http.py +76 -0
  40. pymammotion/luba/_init_.py +0 -0
  41. pymammotion/luba/base.py +52 -0
  42. pymammotion/mammotion/__init__.py +0 -0
  43. pymammotion/mammotion/commands/__init__.py +0 -0
  44. pymammotion/mammotion/commands/abstract_message.py +7 -0
  45. pymammotion/mammotion/commands/mammotion_command.py +34 -0
  46. pymammotion/mammotion/commands/messages/__init__.py +0 -0
  47. pymammotion/mammotion/commands/messages/driver.py +108 -0
  48. pymammotion/mammotion/commands/messages/media.py +36 -0
  49. pymammotion/mammotion/commands/messages/navigation.py +535 -0
  50. pymammotion/mammotion/commands/messages/network.py +236 -0
  51. pymammotion/mammotion/commands/messages/ota.py +34 -0
  52. pymammotion/mammotion/commands/messages/system.py +266 -0
  53. pymammotion/mammotion/commands/messages/video.py +27 -0
  54. pymammotion/mammotion/control/__init__.py +0 -0
  55. pymammotion/mammotion/control/joystick.py +184 -0
  56. pymammotion/mammotion/devices/__init__.py +1 -0
  57. pymammotion/mammotion/devices/luba.py +564 -0
  58. pymammotion/mqtt/mqtt.py +230 -0
  59. pymammotion/proto/__init__.py +0 -0
  60. pymammotion/proto/common.proto +7 -0
  61. pymammotion/proto/common.py +12 -0
  62. pymammotion/proto/common_pb2.py +25 -0
  63. pymammotion/proto/common_pb2.pyi +13 -0
  64. pymammotion/proto/dev_net.proto +297 -0
  65. pymammotion/proto/dev_net.py +381 -0
  66. pymammotion/proto/dev_net_pb2.py +107 -0
  67. pymammotion/proto/dev_net_pb2.pyi +472 -0
  68. pymammotion/proto/luba_msg.proto +73 -0
  69. pymammotion/proto/luba_msg.py +80 -0
  70. pymammotion/proto/luba_msg_pb2.py +40 -0
  71. pymammotion/proto/luba_msg_pb2.pyi +93 -0
  72. pymammotion/proto/luba_mul.proto +68 -0
  73. pymammotion/proto/luba_mul.py +76 -0
  74. pymammotion/proto/luba_mul_pb2.py +45 -0
  75. pymammotion/proto/luba_mul_pb2.pyi +91 -0
  76. pymammotion/proto/mctrl_driver.proto +67 -0
  77. pymammotion/proto/mctrl_driver.py +100 -0
  78. pymammotion/proto/mctrl_driver_pb2.py +45 -0
  79. pymammotion/proto/mctrl_driver_pb2.pyi +112 -0
  80. pymammotion/proto/mctrl_nav.proto +485 -0
  81. pymammotion/proto/mctrl_nav.py +589 -0
  82. pymammotion/proto/mctrl_nav_pb2.py +116 -0
  83. pymammotion/proto/mctrl_nav_pb2.pyi +875 -0
  84. pymammotion/proto/mctrl_ota.proto +42 -0
  85. pymammotion/proto/mctrl_ota.py +48 -0
  86. pymammotion/proto/mctrl_ota_pb2.py +35 -0
  87. pymammotion/proto/mctrl_ota_pb2.pyi +65 -0
  88. pymammotion/proto/mctrl_pept.proto +29 -0
  89. pymammotion/proto/mctrl_pept.py +41 -0
  90. pymammotion/proto/mctrl_pept_pb2.py +31 -0
  91. pymammotion/proto/mctrl_pept_pb2.pyi +50 -0
  92. pymammotion/proto/mctrl_sys.proto +487 -0
  93. pymammotion/proto/mctrl_sys.py +574 -0
  94. pymammotion/proto/mctrl_sys_pb2.py +142 -0
  95. pymammotion/proto/mctrl_sys_pb2.pyi +787 -0
  96. pymammotion/py.typed +0 -0
  97. pymammotion/utility/constant/__init__.py +1 -0
  98. pymammotion/utility/constant/device_constant.py +238 -0
  99. pymammotion/utility/datatype_converter.py +80 -0
  100. pymammotion/utility/device_type.py +152 -0
  101. pymammotion/utility/periodic.py +41 -0
  102. pymammotion/utility/rocker_util.py +135 -0
  103. pymammotion-0.0.37.dist-info/LICENSE +674 -0
  104. pymammotion-0.0.37.dist-info/METADATA +92 -0
  105. pymammotion-0.0.37.dist-info/RECORD +106 -0
  106. pymammotion-0.0.37.dist-info/WHEEL +4 -0
@@ -0,0 +1,51 @@
1
+ from dataclasses import dataclass
2
+
3
+ from mashumaro.mixins.orjson import DataClassORJSONMixin
4
+
5
+
6
+ @dataclass
7
+ class DeviceData(DataClassORJSONMixin):
8
+ deviceId: str
9
+
10
+
11
+ @dataclass
12
+ class Device(DataClassORJSONMixin):
13
+ traceId: str
14
+ code: int
15
+ data: DeviceData
16
+ subCode: int
17
+ message: str
18
+ successful: str
19
+
20
+
21
+ @dataclass
22
+ class Config(DataClassORJSONMixin):
23
+ traceId: str
24
+ code: int
25
+ subCode: int
26
+ message: str
27
+ successful: str
28
+
29
+
30
+ @dataclass
31
+ class DataContent(DataClassORJSONMixin):
32
+ device: Device
33
+ config: Config
34
+
35
+
36
+ @dataclass
37
+ class InnerData(DataClassORJSONMixin):
38
+ traceId: str
39
+ vid: str
40
+ code: int
41
+ data: DataContent
42
+ subCode: int
43
+ message: str
44
+ successful: str
45
+
46
+
47
+ @dataclass
48
+ class ConnectResponse(DataClassORJSONMixin):
49
+ data: InnerData
50
+ success: str
51
+ api: str
@@ -0,0 +1,43 @@
1
+ from dataclasses import dataclass
2
+ from typing import List, Optional
3
+
4
+ from mashumaro.mixins.orjson import DataClassORJSONMixin
5
+
6
+
7
+ @dataclass
8
+ class Device(DataClassORJSONMixin):
9
+ productModel: str
10
+ gmtModified: int
11
+ netType: str
12
+ nickName: str
13
+ categoryKey: str
14
+ productKey: str
15
+ nodeType: str
16
+ isEdgeGateway: bool
17
+ deviceName: str
18
+ categoryName: str
19
+ identityAlias: str
20
+ productName: str
21
+ iotId: str
22
+ bindTime: int
23
+ owned: int
24
+ identityId: str
25
+ thingType: str
26
+ status: int
27
+ productImage: Optional[str] = None
28
+ categoryImage: Optional[str] = None
29
+
30
+
31
+ @dataclass
32
+ class Data(DataClassORJSONMixin):
33
+ total: int
34
+ data: List[Device]
35
+ pageNo: int
36
+ pageSize: int
37
+
38
+
39
+ @dataclass
40
+ class ListingDevByAccountResponse(DataClassORJSONMixin):
41
+ code: int
42
+ data: Optional[Data]
43
+ id: Optional[str] = None
@@ -0,0 +1,65 @@
1
+ from dataclasses import dataclass
2
+ from typing import Optional
3
+
4
+ from mashumaro.mixins.orjson import DataClassORJSONMixin
5
+
6
+
7
+ @dataclass
8
+ class OpenAccount(DataClassORJSONMixin):
9
+ displayName: str
10
+ openId: str
11
+ hasPassword: str
12
+ subAccount: str
13
+ pwdVersion: int
14
+ mobileConflictAccount: str
15
+ id: int
16
+ mobileLocationCode: str
17
+ avatarUrl: str
18
+ domainId: int
19
+ enableDevice: str
20
+ status: int
21
+ country: Optional[str] = None
22
+
23
+
24
+ @dataclass
25
+ class OauthOtherInfo(DataClassORJSONMixin):
26
+ SidExpiredTime: int
27
+
28
+
29
+ @dataclass
30
+ class LoginSuccessResult(DataClassORJSONMixin):
31
+ reTokenExpireIn: int
32
+ uidToken: str
33
+ openAccount: OpenAccount
34
+ initPwd: str
35
+ sidExpireIn: int
36
+ oauthOtherInfo: OauthOtherInfo
37
+ refreshToken: str
38
+ sid: str
39
+ token: str
40
+
41
+
42
+ @dataclass
43
+ class InnerDataContent(DataClassORJSONMixin):
44
+ loginSuccessResult: LoginSuccessResult
45
+ mobileBindRequired: str
46
+
47
+
48
+ @dataclass
49
+ class InnerData(DataClassORJSONMixin):
50
+ traceId: str
51
+ vid: str
52
+ code: int
53
+ data: InnerDataContent
54
+ subCode: int
55
+ message: str
56
+ deviceId: str
57
+ successful: str
58
+
59
+
60
+ @dataclass
61
+ class LoginByOAuthResponse(DataClassORJSONMixin):
62
+ data: InnerData
63
+ success: str
64
+ api: str
65
+ errorMsg: str
@@ -0,0 +1,26 @@
1
+ from dataclasses import dataclass
2
+ from typing import Optional, TypeVar
3
+
4
+ from mashumaro import DataClassDictMixin
5
+ from mashumaro.mixins.orjson import DataClassORJSONMixin
6
+
7
+ DataT = TypeVar("DataT")
8
+
9
+
10
+ @dataclass
11
+ class RegionResponseData(DataClassORJSONMixin):
12
+ shortRegionId: str
13
+ oaApiGatewayEndpoint: str
14
+ regionId: str
15
+ mqttEndpoint: str
16
+ pushChannelEndpoint: str
17
+ regionEnglishName: str
18
+ apiGatewayEndpoint: str
19
+
20
+
21
+ @dataclass
22
+ class RegionResponse(DataClassDictMixin):
23
+ data: RegionResponseData
24
+ code: int
25
+ id: Optional[str] = None
26
+ msg: Optional[str] = None
@@ -0,0 +1,18 @@
1
+ from dataclasses import dataclass
2
+
3
+ from mashumaro.mixins.orjson import DataClassORJSONMixin
4
+
5
+
6
+ @dataclass
7
+ class TokenData(DataClassORJSONMixin):
8
+ identityId: str
9
+ refreshTokenExpire: int
10
+ iotToken: str
11
+ iotTokenExpire: int
12
+ refreshToken: str
13
+
14
+
15
+ @dataclass
16
+ class SessionByAuthCodeResponse(DataClassORJSONMixin):
17
+ code: int
18
+ data: TokenData
@@ -0,0 +1,175 @@
1
+ class tmp_constant:
2
+ ALGECC = "ecc"
3
+ ALGHMACMD5 = "hmacmd5"
4
+ ALGNONE = "none"
5
+ ALINK_SECURE_URI_SCHEME = "coaps"
6
+ ALINK_URI_SCHEME = "coap"
7
+ AUTH_VER = "1.0"
8
+ CONFIG_TYPE_CLIENT = "ClientAuthInfo"
9
+ CONFIG_TYPE_PROVISION_RECEIVER = "SetupData"
10
+ CONFIG_TYPE_SERVER = "ServerAuthInfo"
11
+ DATA_KEY_DEVICENAME = "MAC"
12
+ DATA_KEY_DEVICE_WIFI_STATUS = "wifiEnabled"
13
+ DEFAULT_COAP_SECURE_PORT = 5684
14
+ DEFAULT_COAP_UDP_PORT = 5683
15
+ DEFAULT_MULTI_CAST_ADDRESS = "224.0.1.187"
16
+ DEVICES = "devices"
17
+ DEVICE_DATA_FORMAT_ALINK = "ALINK_FORMAT"
18
+ DEVICE_IOTID = "iotId"
19
+ DEVICE_MODEL = "deviceModel"
20
+ DEVICE_MODEL_EVENTS = "events"
21
+ DEVICE_MODEL_PROPERTIES = "properties"
22
+ DEVICE_MODEL_SERVICES = "services"
23
+ DEVICE_MODEL_TYPE = "model"
24
+ DEVICE_NAME = "deviceName"
25
+ DEVICE_NAME_POSITION = 2
26
+ DEVICE_PRODUCT_KEY = "productKey"
27
+ DEVICE_PROFILE = "profile"
28
+ EVENT_PROPERTY_URI_POST = "post"
29
+ EVENT_PROPERTY_URI_POST_REPLY = "post_reply"
30
+ EVENT_PROPERTY_URI_PRE = "thing/event/property"
31
+ EVENT_URI_POST = "post"
32
+ EVENT_URI_PRE = "thing/event"
33
+ EXPAND_SPLITE = "."
34
+ GROUP_CLOUD_ROLE_COTROLLER = "COTROLLER"
35
+ GROUP_CLOUD_ROLE_DEVICE = "DEVICE"
36
+ GROUP_DEVICE_LOCAL_STATUS_OFFLINE = 3
37
+ GROUP_DEVICE_LOCAL_STATUS_ONLINE = 1
38
+ GROUP_LOCAL_SATUS_ALLOFFLINE = 2
39
+ GROUP_LOCAL_SATUS_ALLONLINE = 0
40
+ GROUP_LOCAL_SATUS_PARTONLINE = 1
41
+ GROUP_OP_ADD = "add"
42
+ GROUP_OP_DEL = "del"
43
+ GROUP_ROLE_CONTROLLER = "cloud_ctl"
44
+ GROUP_ROLE_DEVICE = "cloud_dev"
45
+ GROUP_ROLE_UNKNOWN = "null"
46
+ HEARTBEAT_DEFAULT_TIME = 600000
47
+ HEARTBEAT_MAX_RETRY_TIME = 3
48
+ IDENTIFIER_DEVICENOTIFY = "devnotify"
49
+ IDENTIFIER_RAW_DATA_DOWN = "raw_data_down"
50
+ IDENTIFIER_SETUP = "setup"
51
+ IDENTITY_ADMIN = "0"
52
+ IDENTITY_GUEST = "1"
53
+ IDENTITY_PROVISION = "2"
54
+ KEY_CLIENT_ID = "clientId"
55
+ KEY_IOT_NeedRsp = "NeedRsp"
56
+ KEY_IOT_NeedRsp_EX = "NeedRspEx"
57
+ KEY_IOT_PERFORMANCE_EVENT_REQ = "req"
58
+ KEY_IOT_PERFORMANCE_EVENT_RES = "res"
59
+ KEY_IOT_PERFORMANCE_ID = "IotPerformanceId"
60
+ KEY_IOT_QOS = "QosLevel"
61
+ KEY_IOT_QOS_EX = "QosLevelEx"
62
+ KEY_SIGN_METHOD = "signMethod"
63
+ KEY_SIGN_VALUE = "sign"
64
+ LINK_DEFAULT_CONNECT_ID = "LINK_DEAFULT"
65
+ MAX_BLOCK_SIZE = 3072
66
+ MAX_DEVICE_MODEL_LENGTH = 3072
67
+ METHOD_AUTH_USER = "core.service.user"
68
+ METHOD_DEVICE_NOTIFY = "core.service.notify"
69
+ METHOD_HEART_BEAT = "core.service.heartBeat"
70
+ METHOD_IDENTIFIER_DEV = "dev"
71
+ METHOD_PROPERTY_GET = "thing.service.property.get"
72
+ METHOD_PROPERTY_POST = "thing.event.property.post"
73
+ METHOD_PROPERTY_SET = "thing.service.property.set"
74
+ METHOD_SERVICE_AUTH = "core.service.auth"
75
+ METHOD_SERVICE_AUTH_INFO = "core.service.auth_info"
76
+ METHOD_SERVICE_DISCOVERY = "core.service.dev"
77
+ METHOD_SERVICE_PRE = "thing.service."
78
+ METHOD_SETUP = "core.service.setup"
79
+ METHOD_TSL_TEMPLATE = "thing.dsltemplate.get"
80
+ METHOD_URI_PRE = "thing/service"
81
+ METHOD_USER_SERVICE = "core.service.user"
82
+ MODEL_TYPE_ALI_LCA_CLOUD = "4"
83
+ MODE_VALUE_RANDW = "rw"
84
+ MODE_VALUE_READ = "r"
85
+ MODE_VALUE_WRITE = "w"
86
+ MQTT_NOTIFY_TOPIC_PREFIX = "/app/down/_thing"
87
+ MQTT_TOPIC_EVENTS = "/app/down/thing/events"
88
+ MQTT_TOPIC_NOTIFY = "/app/down/_thing/event/notify"
89
+ MQTT_TOPIC_PREFIX = "/app/down/thing"
90
+ MQTT_TOPIC_PROPERTIES = "/app/down/thing/properties"
91
+ MQTT_TOPIC_SERVICE_REPLY = "/app/down/thing/service/invoke/reply"
92
+ MQTT_TOPIC_STATUS = "/app/down/thing/status"
93
+ OPTIONNUMREGISTRY_ACCESSKEY = 36 # deprecated
94
+ PATH_DISCOVERY = "/dev/core/service/dev"
95
+ PATH_GROUP_PRE = "/thing/service/"
96
+ PATH_NOTIFY = "/dev/core/service/notify"
97
+ PATH_SETUP = "/core/service/setup"
98
+ PAYLOAD_CODE = "code"
99
+ PRODUCT_KEY_POSITION = 1
100
+ PROPERTY_IDENTIFIER = "identifier"
101
+ PROPERTY_IDENTIFIER_GET = "get"
102
+ PROPERTY_IDENTIFIER_SET = "set"
103
+ PROPERTY_NAME = "name"
104
+ PROPERTY_TIME = "time"
105
+ PROPERTY_URI_PRE = "thing/service/property"
106
+ PROPERTY_VALUE = "value"
107
+ REQUEST_DELAYTIME = "delayTime"
108
+ REQUEST_ID = "id"
109
+ REQUEST_METHOD = "method"
110
+ REQUEST_PARAMS = "params"
111
+ REQUEST_SESSIONKEY = "sessionKey"
112
+ REQUEST_VERSION = "version"
113
+ RESULT_FAIL = "Failed"
114
+ RESULT_OK = "Success"
115
+ RRESPONSE_DATA = "data"
116
+ RRESPONSE_MESSAGEID = "messageId"
117
+ SERVICE_CALLTYPE = "callType"
118
+ SERVICE_DESC = "desc"
119
+ SERVICE_IDENTIFIER = "identifier"
120
+ SERVICE_INPUTDATA = "inputData"
121
+ SERVICE_METHOD = "method"
122
+ SERVICE_NAME = "name"
123
+ SERVICE_OUTPUTDATA = "outputData"
124
+ SESSION_VALID_TIME = 86400 # deprecated
125
+ TAG = "[Tmp]"
126
+ THING_WIFI_STATUS_NOTIFY = "thing/wifi/status/notify"
127
+ TMP_MODEL_TYPE_ALI_BREEZE = "breeze"
128
+ TMP_MODEL_TYPE_ALI_LCA_CLOUD = "cloudlca"
129
+ TMP_MODEL_TYPE_ALI_THIRD_PART = "third"
130
+ TMP_MODEL_TYPE_ALI_WIFI = "wifi"
131
+ TYPE_VALUE_ARRAY = "array"
132
+ TYPE_VALUE_BOOLEAN = "bool"
133
+ TYPE_VALUE_DATE = "date"
134
+ TYPE_VALUE_DOUBLE = "double"
135
+ TYPE_VALUE_ENUM = "enum"
136
+ TYPE_VALUE_FLOAT = "float"
137
+ TYPE_VALUE_INTEGER = "int"
138
+ TYPE_VALUE_STRING = "string"
139
+ TYPE_VALUE_STRUCT = "struct"
140
+ TYPE_VALUE_TEXT = "text"
141
+ UNKNOWN_CODE = 0 # deprecated
142
+ URI_ALINK_DEVICE_DATA = "alink/deviceStatus" # deprecated
143
+ URI_ALINK_SERVICE = "alink/service" # deprecated
144
+ URI_AUTH = "/auth" # deprecated
145
+ URI_AUTHEN_REGISTER = "/sys/{productKey}/{deviceName}/thing/authen/sub/register"
146
+ URI_AUTHEN_REGISTER_REPLY = (
147
+ "/sys/{productKey}/{deviceName}/thing/authen/sub/register_reply"
148
+ )
149
+ URI_BLACKLIST_UPDATE_POST = "/thing/lan/blacklist/update"
150
+ URI_BLACKLIST_UPDATE_REPLY_POST = "/thing/lan/blacklist/update_reply"
151
+ URI_DEVICE = "/device/core/dev"
152
+ URI_DEV_PATH_PRE = "dev"
153
+ URI_METHOD = "/device/core/method"
154
+ URI_MODEL = "/model"
155
+ URI_PATH_SPLITER = "/"
156
+ URI_PERMISSION = "/permission"
157
+ URI_PREFIX_ALCS_SERVICE = "core/service"
158
+ URI_PREFIX_UPDATE_POST = "/thing/lan/prefix/update"
159
+ URI_PREFIX_UPDATE_REPLY_POST = "/thing/lan/prefix/update_reply"
160
+ URI_PRODUCT_DEVICE_REPLACE = "{deviceName}"
161
+ URI_PRODUCT_PRODUCT_REPLACE = "{productKey}"
162
+ URI_PROPERTY_SET = "/thing/service/property/set"
163
+ URI_SYS_PATH_PRE = "sys"
164
+ URI_THING = "/thing"
165
+ URI_TOPIC_LOCALDEVICE_STATECHANGE = "group/localstatechange"
166
+ URI_TOPIC_REPLY_POST = "_reply"
167
+ URI_UPDATE_DEVICE_INFO = "/sys/{productKey}/{deviceName}/thing/deviceinfo/update"
168
+ URI_UPDATE_DEVICE_INFO_REPLY = (
169
+ "/sys/{productKey}/{deviceName}/thing/deviceinfo/update_reply"
170
+ )
171
+ URI_USER = "/user"
172
+ VALUE_SHA256 = "sha256"
173
+ VERSION = "1.0"
174
+ WIFI_STATUS_KEY = "status"
175
+ WIFI_STATUS_NOTIFY_PARAMS = "params"
@@ -0,0 +1 @@
1
+ from .ble_message import BleMessage
@@ -0,0 +1,74 @@
1
+ from bleak import BleakClient, BleakScanner, BLEDevice
2
+ from bleak.backends.characteristic import BleakGATTCharacteristic
3
+
4
+ from pyluba.bluetooth.const import (
5
+ SERVICE_CHANGED_CHARACTERISTIC,
6
+ UUID_NOTIFICATION_CHARACTERISTIC,
7
+ )
8
+ from pyluba.event.event import BleNotificationEvent
9
+
10
+ # TODO setup for each Luba
11
+ address = "90:38:0C:6E:EE:9E"
12
+
13
+
14
+ class LubaBLE:
15
+ client: BleakClient
16
+
17
+ def __init__(self, bleEvt: BleNotificationEvent):
18
+ self._bleEvt = bleEvt
19
+
20
+ async def scanForLubaAndConnect(self) -> bool:
21
+ scanner = BleakScanner()
22
+
23
+ def scanCallback(device, advertising_data):
24
+ # TODO: do something with incoming data
25
+ print(device)
26
+ print(advertising_data)
27
+ if device.address == "90:38:0C:6E:EE:9E":
28
+ return True
29
+ if advertising_data.local_name and "Luba-" in advertising_data.local_name:
30
+ return True
31
+ return False
32
+
33
+ device = await scanner.find_device_by_filter(scanCallback)
34
+ if device is not None:
35
+ return await self.create_client(device)
36
+
37
+ async def create_client(self, device: BLEDevice):
38
+ self.client = BleakClient(device.address)
39
+ return await self.connect()
40
+
41
+ async def connect(self) -> bool:
42
+ if self.client is not None:
43
+ return await self.client.connect()
44
+
45
+ async def disconnect(self) -> bool:
46
+ if self.client is not None:
47
+ return await self.client.disconnect()
48
+
49
+ async def notification_handler(
50
+ self, _characteristic: BleakGATTCharacteristic, data: bytearray
51
+ ):
52
+ """Simple notification handler which prints the data received."""
53
+ await self._bleEvt.BleNotification(data)
54
+
55
+ def service_changed_handler(
56
+ self, characteristic: BleakGATTCharacteristic, data: bytearray
57
+ ):
58
+ """Simple notification handler which prints the data received."""
59
+ print(f"Response 2 {characteristic.description}: {data}")
60
+ print(data.decode("utf-8"))
61
+ # BlufiNotifyData
62
+ # run an event handler back to somewhere
63
+
64
+ async def notifications(self):
65
+ if self.client.is_connected:
66
+ await self.client.start_notify(
67
+ UUID_NOTIFICATION_CHARACTERISTIC, self.notification_handler
68
+ )
69
+ await self.client.start_notify(
70
+ SERVICE_CHANGED_CHARACTERISTIC, self.service_changed_handler
71
+ )
72
+
73
+ def getClient(self):
74
+ return self.client