@@ -452,6 +452,7 @@ def subscribe_to_ctls(self, function):
452
452
453
453
def _handle_ctl (self , message ):
454
454
the_good_part = message .get_payload ()[0 ][0 ]
455
+ _LOGGER .debug ('Message payload: ' + ET .tostring (the_good_part , method = 'xml' ).decode ())
455
456
as_dict = self ._ctl_to_dict (the_good_part )
456
457
if as_dict is not None :
457
458
for s in self .ctl_subscribers :
@@ -461,11 +462,29 @@ def _ctl_to_dict(self, xml):
461
462
result = xml .attrib .copy ()
462
463
if 'td' not in result :
463
464
# This happens for commands with no response data, such as PlaySound
464
- return
465
+ # Handle response data with no 'td'
465
466
466
- result ['event' ] = result .pop ('td' )
467
- if xml :
468
- result .update (xml [0 ].attrib )
467
+ # return
468
+ if 'type' in result : # single element with type and val
469
+ result ['event' ] = "LifeSpan" # seems to always ben LifeSpan type
470
+
471
+ else :
472
+ if len (xml ) > 0 : # case where there is child element
473
+ if 'clean' in xml [0 ].tag :
474
+ result ['event' ] = "CleanReport"
475
+ elif 'charge' in xml [0 ].tag :
476
+ result ['event' ] = "ChargeState"
477
+ elif 'battery' in xml [0 ].tag :
478
+ result ['event' ] = "BatteryInfo"
479
+ else :
480
+ return
481
+ result .update (xml [0 ].attrib )
482
+ else : # for non-'type' result with no child element, e.g., result of PlaySound
483
+ return
484
+ else : # response includes 'td'
485
+ result ['event' ] = result .pop ('td' )
486
+ if xml :
487
+ result .update (xml [0 ].attrib )
469
488
470
489
for key in result :
471
490
result [key ] = stringcase .snakecase (result [key ])
0 commit comments