Skip to content

Commit cca6269

Browse files
[pre-commit.ci lite] apply automatic fixes
1 parent 1df60ab commit cca6269

3 files changed

Lines changed: 17 additions & 13 deletions

File tree

‎apps/predbat/octopus.py‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
OCTOPUS_DAY_RATE_END_HOUR = 0
3838
OCTOPUS_DAY_RATE_END_MINUTE = 30
3939

40+
4041
def 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

‎apps/predbat/unit_test.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9140,16 +9140,17 @@ def test_download_octopus_url_wrapper(my_predbat):
91409140
"""
91419141
return asyncio.run(test_download_octopus_url(my_predbat))
91429142

9143+
91439144
async def test_download_octopus_url(my_predbat):
91449145
"""
91459146
Test the download_octopus_url function
91469147
"""
91479148
print("**** Running download_octopus_url tests ****")
91489149
failed = False
9149-
9150+
91509151
# Test URL for VAR-22-11-01 tariff
91519152
test_url = "https://api.octopus.energy/v1/products/VAR-22-11-01/electricity-tariffs/E-2R-VAR-22-11-01-A/standard-unit-rates/"
9152-
9153+
91539154
# Test the download function
91549155
api = OctopusAPI("", "", my_predbat)
91559156
api.now_utc = my_predbat.now_utc

‎apps/predbat/web_helper.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ def get_entity_control_css():
4444
}
4545
</style>
4646
"""
47-
return html
47+
return html
48+
4849

4950
def get_entity_toggle_js():
5051
"""
@@ -80,9 +81,10 @@ def get_entity_toggle_js():
8081
}});
8182
}}
8283
</script>
83-
"""
84+
"""
8485
return html
8586

87+
8688
def get_apps_js(all_states_json):
8789
text = (
8890
f"""

0 commit comments

Comments
 (0)