@@ -781,6 +781,7 @@ def monitorLife(self):
781781 logging .info ("Life monitoring thread started" )
782782 # Poll DUT to see if it's still responsive, if not, raise timeout exception
783783 file_path = self .result_dir + os .sep + 'battery_level.txt'
784+ csv_path = self .result_dir + os .sep + 'battery_level.csv'
784785 while (True ):
785786 try :
786787 if self .platform .lower () == 'windows' :
@@ -795,13 +796,26 @@ def monitorLife(self):
795796 # logging.info("RTC Wake timer reset")
796797 time .sleep (900 )
797798 elif self .platform .lower () == 'macos' :
798- result = self ._call (["pmset" , "-g batt" ], blocking = True )
799- level = result .split ("\n " )[1 ].split ("\t " )[1 ].split ("%" )[0 ]
799+ # Get AppleRawCurrentCapacity level via ioreg
800+ raw_current_capacity_result = self ._call (["bash" , '-c "ioreg -r -c AppleSmartBattery -a | plutil -extract 0.AppleRawCurrentCapacity raw -"' ], blocking = True )
801+ raw_current_capacity_level = raw_current_capacity_result .strip ()
802+
803+ # Get AppleRawMaxCapacity level via ioreg
804+ raw_max_capacity_result = self ._call (["bash" , '-c "ioreg -r -c AppleSmartBattery -a | plutil -extract 0.AppleRawMaxCapacity raw -"' ], blocking = True )
805+ raw_max_capacity_level = raw_max_capacity_result .strip ()
806+
807+ # Calculate Battery level to 2 decimal places
808+ level = round (float (raw_current_capacity_level ) / float (raw_max_capacity_level ) * 100 , 2 )
809+
800810 current_time = datetime .now ()
801811 time_s = current_time .strftime ("%m/%d/%Y %I:%M:%S %p" )
802- logging .info (f"Battery level: { level } " )
812+ logging .info (f"Battery level : { str (level )} " )
813+
814+ # Write human-readable txt log
803815 with open (file_path , 'a' , newline = '' ) as f :
804- f .write (f"{ time_s } : total battery: { level } \n " )
816+ f .write (f"{ time_s } : total battery: { str (level )} \n " )
817+
818+
805819 if int (level ) <= int (self .stop_soc ):
806820 break
807821 time .sleep (int (self .poll_rate ))
0 commit comments