-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
74 lines (69 loc) · 2.1 KB
/
main.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
from xiaomi_ndef import *
from xiaomi_ndef import xiaomi, handoff
BYTES_DATA = bytes.fromhex(
"0a4b0801100d2201032a094d492d4e4643544147380f4a3127" +
"1700000003000e5441475f444953434f564552454465064d49" +
"52524f52011130303a30303a30303a30303a30303a30306a02" +
"fa7f"
)
NEW_DATA = tag.NfcTagAppData(
major_version=1,
minor_version=0,
write_time=0000000000,
flags=0,
records=(
tag.NfcTagDeviceRecord(
device_type=tag.DeviceType.MI_SOUND_BOX,
flags=0,
device_number=0,
attributes_map=tag.NfcTagDeviceRecord.new_attributes_map(
[
tag.DeviceAttribute.BLUETOOTH_MAC_ADDRESS.new_pair(b"\x00\x00\x00\x00\x00\x01")
]
)
),
tag.NfcTagActionRecord(
action=tag.Action.AUTO,
condition=tag.Condition.AUTO,
device_number=0,
flags=0,
condition_parameters=None,
)
)
)
def main() -> None:
mi_connect_data = MiConnectData.parse(BYTES_DATA)
print(mi_connect_data)
nfc_protocol = mi_connect_data.get_nfc_protocol()
print(nfc_protocol)
nfc_payload = mi_connect_data.to_xiaomi_nfc_payload(nfc_protocol)
print(nfc_payload)
print(NEW_DATA)
print(NEW_DATA.encode().hex())
print(
MiConnectData.from_nfc_payload(
XiaomiNfcPayload(
major_version=1,
minor_version=0,
id_hash=None,
protocol=V1NfcProtocol,
appData=NEW_DATA
)
).to_bytes().hex()
)
print(MiConnectData.from_nfc_payload(
xiaomi.new_handoff_screen_mirror(
device_type=handoff.DeviceType.PC,
bluetooth_mac="00:00:00:00:00:00",
enable_lyra=True
)[1]
).to_bytes().hex())
print(MiConnectData.from_nfc_payload(
xiaomi.new_handoff_screen_mirror(
device_type=handoff.DeviceType.PC,
bluetooth_mac="00:00:00:00:00:00",
enable_lyra=False
)[1]
).to_bytes().hex())
if __name__ == "__main__":
main()