3737OCTOPUS_DAY_RATE_END_HOUR = 0
3838OCTOPUS_DAY_RATE_END_MINUTE = 30
3939
40+
4041def is_active (now_utc , activeFrom , activeTo ):
4142 if not activeFrom :
4243 return False
@@ -699,16 +700,16 @@ async def async_get_day_night_rates(self, url):
699700 current_night_rate = None
700701 for rate in result_day :
701702 valid_from_stamp = rate .get ("valid_from" , "" )
702- # Convert from string to datetime
703+ # Convert from string to datetime
703704 valid_from_stamp = datetime .strptime (valid_from_stamp , DATE_TIME_STR_FORMAT )
704705 if valid_from_stamp <= self .now_utc :
705- current_day_rate = rate .get (' value_inc_vat' , None )
706+ current_day_rate = rate .get (" value_inc_vat" , None )
706707 for rate in result_night :
707708 valid_from_stamp = rate .get ("valid_from" , "" )
708- # Convert from string to datetime
709+ # Convert from string to datetime
709710 valid_from_stamp = datetime .strptime (valid_from_stamp , DATE_TIME_STR_FORMAT )
710711 if valid_from_stamp <= self .now_utc :
711- current_night_rate = rate .get (' value_inc_vat' , None )
712+ current_night_rate = rate .get (" value_inc_vat" , None )
712713 self .log ("Info: Current day rate {} night rate {}" .format (current_day_rate , current_night_rate ))
713714 if current_day_rate is not None and current_night_rate is not None :
714715 # Now create a combined list of rates, start from 2 days back and go forward 3 days with the day and night rates
@@ -724,9 +725,9 @@ async def async_get_day_night_rates(self, url):
724725 night_start_time += timedelta (days = 1 )
725726 night_end_time += timedelta (days = 1 )
726727 day_start_time += timedelta (days = 1 )
727- day_end_time += timedelta (days = 1 )
728+ day_end_time += timedelta (days = 1 )
728729 return mdata
729-
730+
730731 async def async_download_octopus_url (self , url ):
731732 """
732733 Download octopus rates directly from a URL
@@ -748,10 +749,10 @@ async def async_download_octopus_url(self, url):
748749 self .failures_total += 1
749750 self .log ("Warn: Error downloading Octopus data from URL {} (JSONDecodeError)" .format (url ))
750751 return {}
751-
752+
752753 if r .status_code == 400 :
753754 detail = data .get ("detail" , "" )
754- if ' This tariff has day and night rates' in detail :
755+ if " This tariff has day and night rates" in detail :
755756 self .log ("Info: Octopus tariff has day and night rates, fetching both" )
756757 mdata = await self .async_get_day_night_rates (url )
757758 if mdata :
@@ -824,7 +825,7 @@ async def fetch_tariffs(self, tariffs):
824825 tariff_type = "gas"
825826 else :
826827 tariff_type = "electricity"
827- tariffs [tariff ]["data" ] = await self .fetch_url_cached (f"https://api.octopus.energy/v1/products/{ product_code } /{ tariff_type } -tariffs/{ tariff_code } /standard-unit-rates/" )
828+ tariffs [tariff ]["data" ] = await self .fetch_url_cached (f"https://api.octopus.energy/v1/products/{ product_code } /{ tariff_type } -tariffs/{ tariff_code } /standard-unit-rates/" )
828829 tariffs [tariff ]["standing" ] = await self .fetch_url_cached (f"https://api.octopus.energy/v1/products/{ product_code } /{ tariff_type } -tariffs/{ tariff_code } /standing-charges/" )
829830
830831 entity_id = "sensor.predbat_octopus_" + self .account_id .replace ("-" , "_" ) + "_" + tariff
0 commit comments