22from datetime import datetime
33import logging
44import sys
5- from ..utils .utils import pretty_print_except
5+ from ..utils .utils import pretty_json_string_except
66
77from typing import TYPE_CHECKING , Dict , List , Optional
88
@@ -940,17 +940,12 @@ def get_historical_data_for_register(
940940 # Print debug data
941941 ###########################################################################
942942
943- def debug (self ):
944- print ( "Creating debug file" )
943+ def debug (self ) -> str :
944+ debug_str = "########## DEBUG START ########## \n "
945945
946- original_stdout = sys .stdout
947- f = open ("debug.txt" , "w" )
948- sys .stdout = f
946+ debug_str += "self.__info:\n "
949947
950- print ("########## DEBUG START ##########" )
951-
952- print ("self.__info:" )
953- pretty_print_except (
948+ debug_str += pretty_json_string_except (
954949 self .__info ,
955950 [
956951 "address" ,
@@ -964,11 +959,13 @@ def debug(self):
964959 ],
965960 )
966961
967- print ("self.__status:" )
968- pretty_print_except (self .__status )
962+ debug_str += "self.__status:\n "
963+
964+ debug_str += pretty_json_string_except (self .__status )
965+
966+ debug_str += "self.__device_data:\n "
969967
970- print ("self.__device_data:" )
971- pretty_print_except (
968+ debug_str += pretty_json_string_except (
972969 self .__device_data ,
973970 ["macAddress" , "owner" , "retailerAccess" , "retailerId" , "id" , "status" ],
974971 )
@@ -982,20 +979,18 @@ def debug(self):
982979 installation_profile_id
983980 )
984981 if all_available_groups is not None :
985- print ( "All available groups:" )
986- pretty_print_except (all_available_groups )
982+ debug_str += "All available groups:\n "
983+ debug_str += pretty_json_string_except (all_available_groups )
987984
988985 for group in all_available_groups :
989986 group_name = group .get ("name" )
990987 if group_name is not None :
991- print ( "Group " + group_name + ":" )
988+ debug_str += "Group " + group_name + ":\n "
992989 group_data = self .__api_interface .get_register_group_json (
993990 self .__device_id , group_name
994991 )
995- pretty_print_except (group_data )
992+ debug_str += pretty_json_string_except (group_data )
996993
997- print ( "########## DEBUG END ##########" )
994+ debug_str += "########## DEBUG END ##########\n "
998995
999- sys .stdout = original_stdout
1000- f .close ()
1001- print ("Debug file created" )
996+ return debug_str
0 commit comments