Skip to content

Commit c900c30

Browse files
bootcclaude
andcommitted
fix(octopus): name the car charging rate setting with the entity prefix in use (#5438)
The ambiguous-charger warning told the user to set input_number.predbat_car_charging_rate, but the entity prefix is configurable (apps.yaml prefix), so with a custom prefix it named an entity that doesn't exist. It now uses the component's own prefix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent ed9c417 commit c900c30

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

‎apps/predbat/octopus.py‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,12 @@
5858
CATALOGUE_FRESH_MINUTES = 24 * 60
5959
CATALOGUE_STALE_MINUTES = 25 * 60
6060
# Logged by log_catalogue_ambiguity() when the catalogue gives a make and model more than one value (issue #5438).
61-
# A charge point's power only ever raises input_number.predbat_car_charging_rate (fetch.py), so that is what decides
61+
# A charge point's power only ever raises input_number.{prefix}_car_charging_rate (fetch.py), so that is what decides
6262
# the rate; a vehicle's battery size from Octopus replaces car_charging_battery_size, so there is no setting to change.
63+
# {prefix} is the entity prefix in use (apps.yaml prefix, "predbat" by default).
6364
CATALOGUE_AMBIGUOUS_CHARGER = (
6465
"Octopus's catalogue lists charge point {device} at more than one power ({values} {unit}) and Predbat can't tell which yours is,"
65-
" so it uses the lowest, {value} {unit}, unless input_number.predbat_car_charging_rate (_1, _2 for further cars) is higher. Set that to your charger's rate"
66+
" so it uses the lowest, {value} {unit}, unless input_number.{prefix}_car_charging_rate (_1, _2 for further cars) is higher. Set that to your charger's rate"
6667
)
6768
CATALOGUE_AMBIGUOUS_VEHICLE = (
6869
"Octopus's catalogue lists vehicle {device} with more than one battery size ({values} {unit}) and Predbat can't tell which yours is,"
@@ -2491,7 +2492,8 @@ def log_catalogue_ambiguity(self, message, make, model, values, value, unit):
24912492
24922493
Args:
24932494
message (str): What was looked up and what the user can do about it, formatted with the
2494-
device ({device}), the values ({values}), the one in use ({value}) and the unit ({unit})
2495+
device ({device}), the values ({values}), the one in use ({value}), the unit ({unit}) and
2496+
the entity prefix in use ({prefix})
24952497
make (str): The device's make
24962498
model (str): The device's model
24972499
values (list): The distinct values the catalogue gave, from catalogue_value()
@@ -2504,7 +2506,7 @@ def log_catalogue_ambiguity(self, message, make, model, values, value, unit):
25042506
if key in self.catalogue_ambiguity_logged:
25052507
return
25062508
self.catalogue_ambiguity_logged.add(key)
2507-
self.log("Warn: OctopusAPI: " + message.format(device="{} '{}'".format(make, model), values=", ".join("{:g}".format(v) for v in values), value="{:g}".format(value), unit=unit))
2509+
self.log("Warn: OctopusAPI: " + message.format(device="{} '{}'".format(make, model), values=", ".join("{:g}".format(v) for v in values), value="{:g}".format(value), unit=unit, prefix=self.prefix))
25082510

25092511
async def async_get_vehicle_catalogue(self):
25102512
"""

‎apps/predbat/tests/test_octopus_intelligent_devices.py‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from datetime import datetime, timezone, timedelta
99
from unittest.mock import AsyncMock, MagicMock, patch
1010

11-
from octopus import OctopusAPI, DATE_TIME_STR_FORMAT, OCTOPUS_CAR_ENTITY_SPEC
11+
from octopus import OctopusAPI, DATE_TIME_STR_FORMAT, OCTOPUS_CAR_ENTITY_SPEC, CATALOGUE_AMBIGUOUS_CHARGER
1212

1313

1414
def test_octopus_intelligent_devices_wrapper(my_predbat):
@@ -1707,6 +1707,14 @@ def check(condition, message):
17071707
zappi_warning.startswith("Warn:") and "(7.4, 22 kW)" in zappi_warning and "the lowest, 7.4 kW" in zappi_warning and "input_number.predbat_car_charging_rate" in zappi_warning,
17081708
"the zappi warning should list both powers, the one used and the setting to change: {!r}".format(zappi_warning),
17091709
)
1710+
# The setting is named with the entity prefix in use, which apps.yaml can change from "predbat"
1711+
custom = _make_catalogue_api(my_predbat, "ambiguous-catalogue-prefix", [])
1712+
custom.prefix = "house2"
1713+
custom.log_catalogue_ambiguity(CATALOGUE_AMBIGUOUS_CHARGER, "Myenergi", "zappi (all models)", [7.4, 22.0], 7.4, "kW")
1714+
check(
1715+
len(custom.logged) == 1 and "input_number.house2_car_charging_rate" in custom.logged[0] and "predbat_car_charging_rate" not in custom.logged[0],
1716+
"with prefix house2 the warning should name input_number.house2_car_charging_rate: {}".format(custom.logged),
1717+
)
17101718
ev6_warning = next((message for message in warnings if "EV6" in message), "")
17111719
check(
17121720
ev6_warning.startswith("Warn:") and "(74, 77.4, 80 kWh)" in ev6_warning and "the largest, 80 kWh" in ev6_warning and "car_charging_battery_size" in ev6_warning,

0 commit comments

Comments
 (0)