diff --git a/custom_components/apiEnedis/const.py b/custom_components/apiEnedis/const.py index 792181b..d96ad9f 100644 --- a/custom_components/apiEnedis/const.py +++ b/custom_components/apiEnedis/const.py @@ -1,6 +1,6 @@ """ Constants """ # attention updater aussi manifest.json -__VERSION__ = "1.4.0.3" +__VERSION__ = "1.4.0.4" __name__ = "myEnedis" try: diff --git a/custom_components/apiEnedis/manifest.json b/custom_components/apiEnedis/manifest.json index e0d6ee2..67013d0 100644 --- a/custom_components/apiEnedis/manifest.json +++ b/custom_components/apiEnedis/manifest.json @@ -5,7 +5,7 @@ "issue_tracker": "https://github.com/saniho/apiEnedis/issues", "iot_class": "cloud_polling", "config_flow": true, - "version": "1.4.0.3", + "version": "1.4.0.4", "requirements": [ "packaging>=20.8" ], diff --git a/custom_components/apiEnedis/sensorEnedis.py b/custom_components/apiEnedis/sensorEnedis.py index c6eaa17..23014d4 100644 --- a/custom_components/apiEnedis/sensorEnedis.py +++ b/custom_components/apiEnedis/sensorEnedis.py @@ -149,7 +149,7 @@ def getStatusEnergyDetailHours(self, typeSensor=_consommation): valeurHC = DateHeureDetailHC[clefDate] total = valeurHP + valeurHC - state = "{:.3f}".format(0.001 * total) + state = f"{0.001 * total:.3f}" lastResetIso = lastReset.isoformat() return lastResetIso, status_counts, state @@ -176,80 +176,64 @@ def getStatusEnergyDetailHoursCost(self, typeSensor=_consommation): if clefDate in DateHeureDetailHC.keys(): valeurHC = DateHeureDetailHC[clefDate] - costHC = "{:.3f}".format(0.001 * self._myDataEnedis.getHCCost(valeurHC)) - costHP = "{:.3f}".format(0.001 * self._myDataEnedis.getHPCost(valeurHP)) + costHC = f"{0.001 * self._myDataEnedis.getHCCost(valeurHC):.3f}" + costHP = f"{0.001 * self._myDataEnedis.getHPCost(valeurHP):.3f}" cost = self._myDataEnedis.getHCCost( valeurHC ) + self._myDataEnedis.getHPCost(valeurHP) - state = "{:.3f}".format(0.001 * cost) + state = f"{0.001 * cost:.3f}" lastResetIso = lastReset.isoformat() return lastResetIso, status_counts, state def getStatus(self, typeSensor=_consommation): + # Raccourci pour self._myDataEnedit (lignes plus court) + data = self._myDataEnedis + state = "unavailable" - status_counts = defaultdict(int) - status_counts["version"] = self.version - status_counts["versionGit"] = self._myDataEnedis.getGitVersion() - status_counts["versionUpdateAvailable"] = self.getExistsRecentVersion( - self.version, self._myDataEnedis.getGitVersion() + status = defaultdict(int) + status["version"] = self.version + status["versionGit"] = data.getGitVersion() + status["versionUpdateAvailable"] = self.getExistsRecentVersion( + self.version, data.getGitVersion() ) - if self._myDataEnedis.getTimeLastCall() is not None: + if data.getTimeLastCall() is not None: self._LOGGER.info( - "-- ** on va mettre à jour : %s" - % self._myDataEnedis.getContract().get_PDL_ID() + "-- ** on va mettre à jour : %s" % data.getContract().get_PDL_ID() ) - status_counts["nbCall"] = self._myDataEnedis.getNbCall() - status_counts["typeCompteur"] = typeSensor - status_counts["numPDL"] = self._myDataEnedis.getContract().get_PDL_ID() - status_counts["horaireMinCall"] = self._myDataEnedis.getHoraireMin() - status_counts[ - "activationDate" - ] = self._myDataEnedis.getContract().getLastActivationDate() - if self._myDataEnedis.isConsommation(): - status_counts["lastUpdate"] = self._myDataEnedis.getLastUpdate() - status_counts["timeLastCall"] = self._myDataEnedis.getTimeLastCall() + status["nbCall"] = data.getNbCall() + status["typeCompteur"] = typeSensor + status["numPDL"] = data.getContract().get_PDL_ID() + status["horaireMinCall"] = data.getHoraireMin() + status["activationDate"] = data.getContract().getLastActivationDate() + if data.isConsommation(): + status["lastUpdate"] = data.getLastUpdate() + status["timeLastCall"] = data.getTimeLastCall() # à supprimer car doublon avec j_1 - status_counts[ - "yesterday" - ] = self._myDataEnedis.getYesterday().getValue() - status_counts["last_week"] = self._myDataEnedis.getLastWeek().getValue() + status["yesterday"] = data.getYesterday().getValue() + status["last_week"] = data.getLastWeek().getValue() - if 1: # self._myDataEnedis.getStatusLastCall(): # update avec statut ok + if 1: # data.getStatusLastCall(): # update avec statut ok try: # typesensor ... fonction de ? - if ( - typeSensor == _consommation - ): # self._myDataEnedis.isConsommation(): - - status_counts["lastUpdate"] = self._myDataEnedis.getLastUpdate() - status_counts[ - "timeLastCall" - ] = self._myDataEnedis.getTimeLastCall() + if typeSensor == _consommation: # data.isConsommation(): + + status["lastUpdate"] = data.getLastUpdate() + status["timeLastCall"] = data.getTimeLastCall() # à supprimer car doublon avec j_1 - status_counts[ - "yesterday" - ] = self._myDataEnedis.getYesterday().getValue() - status_counts[ - "yesterdayDate" - ] = self._myDataEnedis.getYesterday().getDateDeb() - status_counts[ + status["yesterday"] = data.getYesterday().getValue() + status["yesterdayDate"] = data.getYesterday().getDateDeb() + status[ "yesterdayLastYear" - ] = self._myDataEnedis.getYesterdayLastYear().getValue() - status_counts[ + ] = data.getYesterdayLastYear().getValue() + status[ "yesterdayLastYearDate" - ] = self._myDataEnedis.getYesterday().getDateDeb() - status_counts[ + ] = data.getYesterday().getDateDeb() + status[ "yesterdayConsumptionMaxPower" - ] = ( - self._myDataEnedis.getYesterdayConsumptionMaxPower().getValue() - ) - status_counts[ - "last_week" - ] = self._myDataEnedis.getLastWeek().getValue() - last7daysHP = ( - self._myDataEnedis.getLast7DaysDetails().getDaysHP() - ) + ] = data.getYesterdayConsumptionMaxPower().getValue() + status["last_week"] = data.getLastWeek().getValue() + last7daysHP = data.getLast7DaysDetails().getDaysHP() listeClef = list(last7daysHP.keys()) listeClef.reverse() @@ -264,17 +248,15 @@ def getStatus(self, typeSensor=_consommation): valeur = -1 if clef in last7daysHP.keys(): valeur = last7daysHP[clef] - status_counts["day_%s_HP" % (niemejour)] = valeur - last7daysHC = ( - self._myDataEnedis.getLast7DaysDetails().getDaysHC() - ) + status["day_%s_HP" % (niemejour)] = valeur + last7daysHC = data.getLast7DaysDetails().getDaysHC() niemejour = 0 for clef in listeClef: niemejour += 1 valeur = -1 if clef in last7daysHC.keys(): valeur = last7daysHC[clef] - status_counts["day_%s_HC" % (niemejour)] = valeur + status["day_%s_HC" % (niemejour)] = valeur # gestion du cout par jour .... niemejour = 0 @@ -286,26 +268,22 @@ def getStatus(self, typeSensor=_consommation): clef in last7daysHC.keys() and clef in last7daysHP.keys() ): - valeur = 0.001 * self._myDataEnedis.getHCCost( + valeur = 0.001 * data.getHCCost( last7daysHC[clef] - ) + 0.001 * self._myDataEnedis.getHPCost( - last7daysHP[clef] - ) - valeur = "{:.2f}".format(valeur) + ) + 0.001 * data.getHPCost(last7daysHP[clef]) + valeur = f"{valeur:.2f}" cout.append(valeur) - status_counts["dailyweek_cost"] = cout + status["dailyweek_cost"] = cout niemejour = 0 coutHC = [] for clef in listeClef: niemejour += 1 valeur = -1 if clef in last7daysHC.keys(): - valeur = 0.001 * self._myDataEnedis.getHCCost( - last7daysHC[clef] - ) - valeur = "{:.2f}".format(valeur) + valeur = 0.001 * data.getHCCost(last7daysHC[clef]) + valeur = f"{valeur:.2f}" coutHC.append(valeur) - status_counts["dailyweek_costHC"] = coutHC + status["dailyweek_costHC"] = coutHC niemejour = 0 dailyHC = [] @@ -313,23 +291,21 @@ def getStatus(self, typeSensor=_consommation): niemejour += 1 valeur = -1 if clef in last7daysHC.keys(): - valeur = "{:.3f}".format(0.001 * last7daysHC[clef]) + valeur = f"{0.001 * last7daysHC[clef]:.3f}" dailyHC.append(valeur) - status_counts["dailyweek_HC"] = dailyHC + status["dailyweek_HC"] = dailyHC - status_counts["dailyweek"] = [(day) for day in listeClef] + status["dailyweek"] = [(day) for day in listeClef] niemejour = 0 coutHP = [] for clef in listeClef: niemejour += 1 valeur = -1 if clef in last7daysHP.keys(): - valeur = 0.001 * self._myDataEnedis.getHPCost( - last7daysHP[clef] - ) - valeur = "{:.2f}".format(valeur) + valeur = 0.001 * data.getHPCost(last7daysHP[clef]) + valeur = f"{valeur:.2f}" coutHP.append(valeur) - status_counts["dailyweek_costHP"] = coutHP + status["dailyweek_costHP"] = coutHP # gestion du format : "{:.2f}".format(a) niemejour = 0 @@ -339,9 +315,9 @@ def getStatus(self, typeSensor=_consommation): valeur = -1 if clef in last7daysHP.keys(): valeur = last7daysHP[clef] - valeur = "{:.3f}".format(0.001 * valeur) + valeur = f"{0.001 * valeur:.3f}" dailyHP.append(valeur) - status_counts["dailyweek_HP"] = dailyHP + status["dailyweek_HP"] = dailyHP niemejour = 0 daily = [] @@ -353,256 +329,164 @@ def getStatus(self, typeSensor=_consommation): and clef in last7daysHC.keys() ): somme = last7daysHP[clef] + last7daysHC[clef] - somme = "{:.2f}".format(0.001 * somme) - status_counts["day_%s" % (niemejour)] = somme + somme = f"{0.001 * somme:.2f}" + status["day_%s" % (niemejour)] = somme daily.append(somme) - status_counts["daily"] = daily + status["daily"] = daily - status_counts["halfhourly"] = [] - status_counts["offpeak_hours"] = "{:.3f}".format( - self._myDataEnedis.getYesterdayHCHP().getHC() * 0.001 - ) - status_counts["peak_hours"] = "{:.3f}".format( - self._myDataEnedis.getYesterdayHCHP().getHP() * 0.001 - ) - if ( - self._myDataEnedis.getYesterdayHCHP().getHC() - + self._myDataEnedis.getYesterdayHCHP().getHP() - ) != 0: - valeur = ( - self._myDataEnedis.getYesterdayHCHP().getHP() * 100 - ) / ( - self._myDataEnedis.getYesterdayHCHP().getHC() - + self._myDataEnedis.getYesterdayHCHP().getHP() - ) - status_counts["peak_offpeak_percent"] = "{:.2f}".format( - valeur - ) + status["halfhourly"] = [] + + # Intermediate variables + prevDayHC = data.getYesterdayHCHP().getHC() + prevDayHCCost = data.getHCCost(prevDayHC) * 0.001 + prevDayHP = data.getYesterdayHCHP().getHP() + prevDayHPCost = data.getHPCost(prevDayHP) * 0.001 + prevDailyCost = prevDayHCCost + prevDayHPCost + + status["offpeak_hours"] = f"{prevDayHC * 0.001:.3f}" + status["peak_hours"] = f"{prevDayHP * 0.001:.3f}" + + # Get Yesterday's HP/(HP+HC) in % + prevDayHPHC = prevDayHC + prevDayHP + if prevDayHPHC != 0: # Pas de division par 0 + valeur = (prevDayHP * 100) / prevDayHPHC + status["peak_offpeak_percent"] = f"{valeur:.2f}" else: - status_counts["peak_offpeak_percent"] = 0 - status_counts["yesterday_HC_cost"] = "{:.3f}".format( - 0.001 - * self._myDataEnedis.getHCCost( - self._myDataEnedis.getYesterdayHCHP().getHC() - ) - ) - status_counts["yesterday_HP_cost"] = "{:.3f}".format( - 0.001 - * self._myDataEnedis.getHPCost( - self._myDataEnedis.getYesterdayHCHP().getHP() - ) - ) - status_counts["daily_cost"] = "{:.2f}".format( - 0.001 - * self._myDataEnedis.getHCCost( - self._myDataEnedis.getYesterdayHCHP().getHC() - ) - + 0.001 - * self._myDataEnedis.getHPCost( - self._myDataEnedis.getYesterdayHCHP().getHP() - ) - ) - status_counts["yesterday_HC"] = "{:.3f}".format( - self._myDataEnedis.getYesterdayHCHP().getHC() * 0.001 - ) - status_counts["yesterday_HP"] = "{:.3f}".format( - self._myDataEnedis.getYesterdayHCHP().getHP() * 0.001 - ) - status_counts["yesterday_HCHP"] = "{:.3f}".format( - ( - self._myDataEnedis.getYesterdayHCHP().getHC() - + self._myDataEnedis.getYesterdayHCHP().getHP() - ) - * 0.001 - ) - if status_counts["yesterday"] == 0: - status_counts["yesterday"] = ( - self._myDataEnedis.getYesterdayHCHP().getHC() - + self._myDataEnedis.getYesterdayHCHP().getHP() - ) - status_counts["current_week"] = "{:.3f}".format( - self._myDataEnedis.getCurrentWeek().getValue() * 0.001 + status["peak_offpeak_percent"] = 0 + + status["yesterday_HC_cost"] = f"{prevDayHCCost:.3f}" + status["yesterday_HP_cost"] = f"{prevDayHPCost:.3f}" + status["daily_cost"] = f"{prevDailyCost:.2f}" + status["yesterday_HC"] = f"{prevDayHC * 0.001:.3f}" + status["yesterday_HP"] = f"{prevDayHP * 0.001:.3f}" + status["yesterday_HCHP"] = f"{prevDayHPHC * 0.001:.3f}" + + if status["yesterday"] == 0: + status["yesterday"] = prevDayHPHC + + status["current_week"] = "{:.3f}".format( + data.getCurrentWeek().getValue() * 0.001 ) - if self._myDataEnedis.getCurrentWeek().getDateDeb() is not None: - status_counts[ + if data.getCurrentWeek().getDateDeb() is not None: + status[ "current_week_number" ] = datetime.datetime.fromisoformat( - self._myDataEnedis.getCurrentWeek().getDateDeb() + data.getCurrentWeek().getDateDeb() ).isocalendar()[ 1 ] - status_counts["current_week_last_year"] = "{:.3f}".format( - self._myDataEnedis.getCurrentWeekLastYear().getValue() - * 0.001 + status["current_week_last_year"] = "{:.3f}".format( + data.getCurrentWeekLastYear().getValue() * 0.001 ) - status_counts["last_month"] = "{:.3f}".format( - self._myDataEnedis.getLastMonth().getValue() * 0.001 + status["last_month"] = "{:.3f}".format( + data.getLastMonth().getValue() * 0.001 ) - status_counts["last_month_last_year"] = "{:.3f}".format( - self._myDataEnedis.getLastMonthLastYear().getValue() * 0.001 + status["last_month_last_year"] = "{:.3f}".format( + data.getLastMonthLastYear().getValue() * 0.001 ) - status_counts["current_month"] = "{:.3f}".format( - self._myDataEnedis.getCurrentMonth().getValue() * 0.001 + status["current_month"] = "{:.3f}".format( + data.getCurrentMonth().getValue() * 0.001 ) - status_counts["current_month_last_year"] = "{:.3f}".format( - self._myDataEnedis.getCurrentMonthLastYear().getValue() - * 0.001 + status["current_month_last_year"] = "{:.3f}".format( + data.getCurrentMonthLastYear().getValue() * 0.001 ) - status_counts["last_year"] = "{:.3f}".format( - self._myDataEnedis.getLastYear().getValue() * 0.001 + status["last_year"] = "{:.3f}".format( + data.getLastYear().getValue() * 0.001 ) - status_counts["current_year"] = "{:.3f}".format( - self._myDataEnedis.getCurrentYear().getValue() * 0.001 + status["current_year"] = "{:.3f}".format( + data.getCurrentYear().getValue() * 0.001 ) - status_counts[ - "errorLastCall" - ] = self._myDataEnedis.getCardErrorLastCall() - status_counts[ - "errorLastCallInterne" - ] = self._myDataEnedis.getErrorLastCall() + status["errorLastCall"] = data.getCardErrorLastCall() + status["errorLastCallInterne"] = data.getErrorLastCall() if ( - ( - self._myDataEnedis.getLastMonthLastYear().getValue() - is not None - ) - and ( - self._myDataEnedis.getLastMonthLastYear().getValue() - != 0 - ) - and ( - self._myDataEnedis.getLastMonth().getValue() is not None - ) + (data.getLastMonthLastYear().getValue() is not None) + and (data.getLastMonthLastYear().getValue() != 0) + and (data.getLastMonth().getValue() is not None) ): valeur = ( ( - self._myDataEnedis.getLastMonth().getValue() - - self._myDataEnedis.getLastMonthLastYear().getValue() + data.getLastMonth().getValue() + - data.getLastMonthLastYear().getValue() ) - / self._myDataEnedis.getLastMonthLastYear().getValue() + / data.getLastMonthLastYear().getValue() ) * 100 - status_counts["monthly_evolution"] = "{:.3f}".format(valeur) + status["monthly_evolution"] = f"{valeur:.3f}" else: - status_counts["monthly_evolution"] = 0 + status["monthly_evolution"] = 0 if ( - ( - self._myDataEnedis.getCurrentWeekLastYear().getValue() - is not None - ) - and ( - self._myDataEnedis.getCurrentWeekLastYear().getValue() - != 0 - ) - and ( - self._myDataEnedis.getCurrentWeek().getValue() - is not None - ) + (data.getCurrentWeekLastYear().getValue() is not None) + and (data.getCurrentWeekLastYear().getValue() != 0) + and (data.getCurrentWeek().getValue() is not None) ): valeur = ( ( - self._myDataEnedis.getCurrentWeek().getValue() - - self._myDataEnedis.getCurrentWeekLastYear().getValue() + data.getCurrentWeek().getValue() + - data.getCurrentWeekLastYear().getValue() ) - / self._myDataEnedis.getCurrentWeekLastYear().getValue() + / data.getCurrentWeekLastYear().getValue() ) * 100 - status_counts["current_week_evolution"] = "{:.3f}".format( - valeur - ) + status["current_week_evolution"] = f"{valeur:.3f}" else: - status_counts["current_week_evolution"] = 0 + status["current_week_evolution"] = 0 if ( - ( - self._myDataEnedis.getCurrentMonthLastYear().getValue() - is not None - ) - and ( - self._myDataEnedis.getCurrentMonthLastYear().getValue() - != 0 - ) - and ( - self._myDataEnedis.getCurrentMonth().getValue() - is not None - ) + (data.getCurrentMonthLastYear().getValue() is not None) + and (data.getCurrentMonthLastYear().getValue() != 0) + and (data.getCurrentMonth().getValue() is not None) ): valeur = ( ( - self._myDataEnedis.getCurrentMonth().getValue() - - self._myDataEnedis.getCurrentMonthLastYear().getValue() + data.getCurrentMonth().getValue() + - data.getCurrentMonthLastYear().getValue() ) - / self._myDataEnedis.getCurrentMonthLastYear().getValue() + / data.getCurrentMonthLastYear().getValue() ) * 100 - status_counts["current_month_evolution"] = "{:.3f}".format( - valeur - ) + status["current_month_evolution"] = f"{valeur:.3f}" else: - status_counts["current_month_evolution"] = 0 + status["current_month_evolution"] = 0 if ( - ( - self._myDataEnedis.getYesterdayLastYear().getValue() - is not None - ) - and ( - self._myDataEnedis.getYesterdayLastYear().getValue() - != 0 - ) - and ( - self._myDataEnedis.getYesterday().getValue() is not None - ) + (data.getYesterdayLastYear().getValue() is not None) + and (data.getYesterdayLastYear().getValue() != 0) + and (data.getYesterday().getValue() is not None) ): valeur = ( ( - self._myDataEnedis.getYesterday().getValue() - - self._myDataEnedis.getYesterdayLastYear().getValue() + data.getYesterday().getValue() + - data.getYesterdayLastYear().getValue() ) - / self._myDataEnedis.getYesterdayLastYear().getValue() + / data.getYesterdayLastYear().getValue() ) * 100 - status_counts["yesterday_evolution"] = "{:.3f}".format( - valeur - ) + status["yesterday_evolution"] = f"{valeur:.3f}" else: - status_counts["yesterday_evolution"] = 0 - status_counts[ + status["yesterday_evolution"] = 0 + status[ "subscribed_power" - ] = self._myDataEnedis.getContract().getsubscribed_power() - status_counts[ + ] = data.getContract().getsubscribed_power() + status[ "offpeak_hours_enedis" - ] = self._myDataEnedis.getContract().getoffpeak_hours() - status_counts[ - "offpeak_hours" - ] = self._myDataEnedis.getContract().getHeuresCreuses() + ] = data.getContract().getoffpeak_hours() + status["offpeak_hours"] = data.getContract().getHeuresCreuses() if typeSensor == _production: - status_counts[ + status[ "yesterday_production" - ] = self._myDataEnedis.getProductionYesterday().getValue() - status_counts[ - "errorLastCall" - ] = self._myDataEnedis.getCardErrorLastCall() - status_counts[ - "errorLastCallInterne" - ] = self._myDataEnedis.getErrorLastCall() - status_counts["lastUpdate"] = self._myDataEnedis.getLastUpdate() - status_counts[ - "timeLastCall" - ] = self._myDataEnedis.getTimeLastCall() - if status_counts["yesterday"] is None: - status_counts["yesterday"] = 0 - if status_counts["yesterday_production"] is None: - status_counts["yesterday_production"] = 0 - if ( - typeSensor == _consommation - ): # self._myDataEnedis.isConsommation(): - valeurstate = status_counts["yesterday"] * 0.001 + ] = data.getProductionYesterday().getValue() + status["errorLastCall"] = data.getCardErrorLastCall() + status["errorLastCallInterne"] = data.getErrorLastCall() + status["lastUpdate"] = data.getLastUpdate() + status["timeLastCall"] = data.getTimeLastCall() + if status["yesterday"] is None: + status["yesterday"] = 0 + if status["yesterday_production"] is None: + status["yesterday_production"] = 0 + if typeSensor == _consommation: # data.isConsommation(): + valeurstate = status["yesterday"] * 0.001 else: - valeurstate = status_counts["yesterday_production"] * 0.001 - state = "{:.3f}".format(valeurstate) + valeurstate = status["yesterday_production"] * 0.001 + state = f"{valeurstate:.3f}" except Exception: - status_counts[ - "errorLastCall" - ] = self._myDataEnedis.getCardErrorLastCall() - status_counts[ - "errorLastCallInterne" - ] = self._myDataEnedis.getErrorLastCall() + status["errorLastCall"] = data.getCardErrorLastCall() + status["errorLastCallInterne"] = data.getErrorLastCall() self._LOGGER.error("-" * 60) exc_type, exc_value, exc_traceback = sys.exc_info() self._LOGGER.error(sys.exc_info()) @@ -612,24 +496,18 @@ def getStatus(self, typeSensor=_consommation): self._LOGGER.error(msg) self._LOGGER.error( - "errorLastCall : %s " % (self._myDataEnedis.getErrorLastCall()) + "errorLastCall : %s " % (data.getErrorLastCall()) ) else: - status_counts[ - "errorLastCall" - ] = self._myDataEnedis.getCardErrorLastCall() - status_counts[ - "errorLastCallInterne" - ] = self._myDataEnedis.getErrorLastCall() + status["errorLastCall"] = data.getCardErrorLastCall() + status["errorLastCallInterne"] = data.getErrorLastCall() else: - status_counts["errorLastCall"] = self._myDataEnedis.getCardErrorLastCall() - status_counts[ - "errorLastCallInterne" - ] = self._myDataEnedis.getErrorLastCall() + status["errorLastCall"] = data.getCardErrorLastCall() + status["errorLastCallInterne"] = data.getErrorLastCall() - return status_counts, state + return status, state def logSensorState(status_counts): for x in status_counts.keys(): - print(" %s : %s" % (x, status_counts[x])) + print(f" {x} : {status_counts[x]}")