casambi-bt-revamped 0.3.6.dev2__py3-none-any.whl → 0.3.6.dev4__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.
- CasambiBt/_client.py +48 -27
- {casambi_bt_revamped-0.3.6.dev2.dist-info → casambi_bt_revamped-0.3.6.dev4.dist-info}/METADATA +1 -1
- {casambi_bt_revamped-0.3.6.dev2.dist-info → casambi_bt_revamped-0.3.6.dev4.dist-info}/RECORD +6 -6
- {casambi_bt_revamped-0.3.6.dev2.dist-info → casambi_bt_revamped-0.3.6.dev4.dist-info}/WHEEL +0 -0
- {casambi_bt_revamped-0.3.6.dev2.dist-info → casambi_bt_revamped-0.3.6.dev4.dist-info}/licenses/LICENSE +0 -0
- {casambi_bt_revamped-0.3.6.dev2.dist-info → casambi_bt_revamped-0.3.6.dev4.dist-info}/top_level.txt +0 -0
CasambiBt/_client.py
CHANGED
|
@@ -424,17 +424,10 @@ class CasambiClient:
|
|
|
424
424
|
# Store raw encrypted packet for Android parser analysis
|
|
425
425
|
raw_encrypted_packet = data[:]
|
|
426
426
|
|
|
427
|
-
#
|
|
427
|
+
# Android parser comparison - disabled as protocols are incompatible
|
|
428
428
|
android_switch_event = None
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
# The Android parser expects unencrypted packets, but let's try anyway
|
|
432
|
-
# to see the structure
|
|
433
|
-
self._logger.debug(f"Attempting Android parser on raw packet: {b2a(raw_encrypted_packet)}")
|
|
434
|
-
android_result = AndroidPacketParser.parse_complete_packet(raw_encrypted_packet)
|
|
435
|
-
self._logger.debug(f"Android parser raw result: {android_result}")
|
|
436
|
-
except Exception as e:
|
|
437
|
-
self._logger.debug(f"Android parser on raw packet failed (expected): {e}")
|
|
429
|
+
# The Android parser expects a completely different packet format than what
|
|
430
|
+
# this implementation uses. Logging disabled to reduce noise.
|
|
438
431
|
|
|
439
432
|
try:
|
|
440
433
|
decrypted_data = self._encryptor.decryptAndVerify(data, data[:4] + self._nonce[4:])
|
|
@@ -443,17 +436,12 @@ class CasambiClient:
|
|
|
443
436
|
self._logger.error(f"Invalid signature for packet {b2a(data)}!")
|
|
444
437
|
return
|
|
445
438
|
|
|
446
|
-
#
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
android_switch_event = android_result['switch_event']
|
|
453
|
-
self._logger.info(f"Android parser found switch event: {android_switch_event['android_log']}")
|
|
454
|
-
self._logger.debug(f"Android parser decrypted result: {android_result}")
|
|
455
|
-
except Exception as e:
|
|
456
|
-
self._logger.debug(f"Android parser on decrypted packet failed: {e}")
|
|
439
|
+
# Protocol analysis: Current implementation vs Android
|
|
440
|
+
# These are fundamentally different protocols:
|
|
441
|
+
# - Current: Type 0x07 + message-based protocol (0x10/0x08 messages)
|
|
442
|
+
# - Android: Complex header with command types 29-36 for buttons
|
|
443
|
+
# No conversion possible - they're incompatible formats
|
|
444
|
+
android_switch_event = None
|
|
457
445
|
|
|
458
446
|
packetType = decrypted_data[0]
|
|
459
447
|
self._logger.debug(f"Incoming data of type {packetType}: {b2a(decrypted_data)}")
|
|
@@ -519,12 +507,15 @@ class CasambiClient:
|
|
|
519
507
|
"""Parse switch event packet which contains multiple message types"""
|
|
520
508
|
self._logger.info(f"Parsing incoming switch event packet... Data: {b2a(data)}")
|
|
521
509
|
|
|
522
|
-
#
|
|
523
|
-
if
|
|
524
|
-
self._logger.
|
|
510
|
+
# Special handling for message type 0x29 - not a switch event
|
|
511
|
+
if len(data) >= 1 and data[0] == 0x29:
|
|
512
|
+
self._logger.debug(f"Ignoring message type 0x29 (not a switch event): {b2a(data)}")
|
|
513
|
+
return
|
|
525
514
|
|
|
526
515
|
pos = 0
|
|
527
516
|
oldPos = 0
|
|
517
|
+
switch_events_found = 0
|
|
518
|
+
|
|
528
519
|
try:
|
|
529
520
|
while pos <= len(data) - 3:
|
|
530
521
|
oldPos = pos
|
|
@@ -536,6 +527,15 @@ class CasambiClient:
|
|
|
536
527
|
parameter = data[pos + 2] & 15
|
|
537
528
|
pos += 3
|
|
538
529
|
|
|
530
|
+
# Sanity check: message type should be reasonable
|
|
531
|
+
if message_type > 0x80:
|
|
532
|
+
self._logger.debug(
|
|
533
|
+
f"Skipping invalid message type 0x{message_type:02x} at position {oldPos}"
|
|
534
|
+
)
|
|
535
|
+
# Try to resync by looking for next valid message
|
|
536
|
+
pos = oldPos + 1
|
|
537
|
+
continue
|
|
538
|
+
|
|
539
539
|
# Check if we have enough data for the payload
|
|
540
540
|
if pos + length > len(data):
|
|
541
541
|
self._logger.debug(
|
|
@@ -550,11 +550,21 @@ class CasambiClient:
|
|
|
550
550
|
|
|
551
551
|
# Process based on message type
|
|
552
552
|
if message_type == 0x08 or message_type == 0x10: # Switch/button events
|
|
553
|
+
switch_events_found += 1
|
|
553
554
|
self._processSwitchMessage(message_type, flags, parameter, payload, data, oldPos, packet_seq, raw_packet, android_switch_event)
|
|
554
|
-
|
|
555
|
-
#
|
|
555
|
+
elif message_type == 0x29:
|
|
556
|
+
# This shouldn't happen due to check above, but just in case
|
|
557
|
+
self._logger.debug(f"Ignoring embedded type 0x29 message")
|
|
558
|
+
elif message_type in [0x00, 0x06, 0x09, 0x1f, 0x2a]:
|
|
559
|
+
# Known non-switch message types - log at debug level
|
|
556
560
|
self._logger.debug(
|
|
557
|
-
f"
|
|
561
|
+
f"Non-switch message type 0x{message_type:02x}: flags=0x{flags:02x}, "
|
|
562
|
+
f"param={parameter}, payload={b2a(payload)}"
|
|
563
|
+
)
|
|
564
|
+
else:
|
|
565
|
+
# Unknown message types - log at info level
|
|
566
|
+
self._logger.info(
|
|
567
|
+
f"Unknown message type 0x{message_type:02x}: flags=0x{flags:02x}, "
|
|
558
568
|
f"param={parameter}, payload={b2a(payload)}"
|
|
559
569
|
)
|
|
560
570
|
|
|
@@ -565,6 +575,9 @@ class CasambiClient:
|
|
|
565
575
|
f"Ran out of data while parsing switch event packet! "
|
|
566
576
|
f"Remaining data {b2a(data[oldPos:])} in {b2a(data)}."
|
|
567
577
|
)
|
|
578
|
+
|
|
579
|
+
if switch_events_found == 0:
|
|
580
|
+
self._logger.debug(f"No switch events found in packet: {b2a(data)}")
|
|
568
581
|
|
|
569
582
|
def _processSwitchMessage(self, message_type: int, flags: int, button: int, payload: bytes, full_data: bytes, start_pos: int, packet_seq: int = None, raw_packet: bytes = None, android_switch_event: dict = None) -> None:
|
|
570
583
|
"""Process a switch/button message (types 0x08 or 0x10)"""
|
|
@@ -581,6 +594,14 @@ class CasambiClient:
|
|
|
581
594
|
extra_data = b''
|
|
582
595
|
if len(payload) > 2:
|
|
583
596
|
extra_data = payload[2:]
|
|
597
|
+
|
|
598
|
+
# Validate extra data for type 0x10
|
|
599
|
+
if message_type == 0x10 and len(extra_data) >= 3:
|
|
600
|
+
# Expected pattern: [unit_id_echo][0x12 or similar][0x00]
|
|
601
|
+
if extra_data[0] != unit_id:
|
|
602
|
+
self._logger.warning(
|
|
603
|
+
f"Extra data validation failed: unit_id_echo {extra_data[0]} != unit_id {unit_id}"
|
|
604
|
+
)
|
|
584
605
|
|
|
585
606
|
event_string = "unknown"
|
|
586
607
|
|
{casambi_bt_revamped-0.3.6.dev2.dist-info → casambi_bt_revamped-0.3.6.dev4.dist-info}/RECORD
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
CasambiBt/__init__.py,sha256=TW445xSu5PV3TyMjJfwaA1JoWvQQ8LXhZgGdDTfWf3s,302
|
|
2
2
|
CasambiBt/_cache.py,sha256=KZ2xbiHAHXUPa8Gw_75Nw9NL4QSY_sTWHbyYXYUDaB0,3865
|
|
3
3
|
CasambiBt/_casambi.py,sha256=gLLkhEcObgapqTx5Mk7WRClyG29UyfZYZCCIhhOg4H4,23101
|
|
4
|
-
CasambiBt/_client.py,sha256=
|
|
4
|
+
CasambiBt/_client.py,sha256=sYK0PpgzhqRc164Q6E2miPK0pNtQmPLoXiZ69-Wxgxk,27667
|
|
5
5
|
CasambiBt/_client_android_parser.py,sha256=1lVkVYMO0Nhh9_nkNwgb68hlCS_uD8WxYQDir5hOdHs,7744
|
|
6
6
|
CasambiBt/_constants.py,sha256=_AxkG7Btxl4VeS6mO7GJW5Kc9dFs3s9sDmtJ83ZEKNw,359
|
|
7
7
|
CasambiBt/_discover.py,sha256=H7HpiFYIy9ELvmPXXd_ck-5O5invJf15dDIRk-vO5IE,1696
|
|
@@ -12,8 +12,8 @@ CasambiBt/_operation.py,sha256=-BuC1Bvtg-G-zSN_b_0JMvXdHZaR6LbTw0S425jg96c,842
|
|
|
12
12
|
CasambiBt/_unit.py,sha256=YiQWoHmMDWHHo4XAjtW8rHsBqIqpmp9MVdv1Mbu2xw4,17043
|
|
13
13
|
CasambiBt/errors.py,sha256=0JgDjaKlAKDes0poWzA8nrTUYQ8qdNfBb8dfaqqzCRA,1664
|
|
14
14
|
CasambiBt/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
15
|
-
casambi_bt_revamped-0.3.6.
|
|
16
|
-
casambi_bt_revamped-0.3.6.
|
|
17
|
-
casambi_bt_revamped-0.3.6.
|
|
18
|
-
casambi_bt_revamped-0.3.6.
|
|
19
|
-
casambi_bt_revamped-0.3.6.
|
|
15
|
+
casambi_bt_revamped-0.3.6.dev4.dist-info/licenses/LICENSE,sha256=TAIIitFxpxEDi6Iju7foW4TDQmWvC-IhLVLhl67jKmQ,11341
|
|
16
|
+
casambi_bt_revamped-0.3.6.dev4.dist-info/METADATA,sha256=IvmEQbo-l6PRaDjjfmO5CyG2jFsXRYsCL2JCZLOBHrU,3049
|
|
17
|
+
casambi_bt_revamped-0.3.6.dev4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
18
|
+
casambi_bt_revamped-0.3.6.dev4.dist-info/top_level.txt,sha256=uNbqLjtecFosoFzpGAC89-5icikWODKI8rOjbi8v_sA,10
|
|
19
|
+
casambi_bt_revamped-0.3.6.dev4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
{casambi_bt_revamped-0.3.6.dev2.dist-info → casambi_bt_revamped-0.3.6.dev4.dist-info}/top_level.txt
RENAMED
|
File without changes
|