Skip to content

Commit 6315a2c

Browse files
committed
Fix options float crash after debug toggle
1 parent 14efe6d commit 6315a2c

3 files changed

Lines changed: 23 additions & 3 deletions

File tree

custom_components/ecoflow_powerocean/config_flow.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,13 @@ async def async_step_init(
139139
) -> ConfigFlowResult:
140140
"""Zeigt das Options-Formular und speichert Änderungen."""
141141
if user_input is not None:
142-
return self.async_create_entry(data=user_input)
142+
# NumberSelector liefert je nach UI-Pfad manchmal float (z. B. 2.0).
143+
# Für die weitere Verarbeitung benötigen wir einen sicheren int-Wert.
144+
normalized_input = dict(user_input)
145+
normalized_input[CONF_NUM_BATTERY_PACKS] = int(
146+
normalized_input[CONF_NUM_BATTERY_PACKS]
147+
)
148+
return self.async_create_entry(data=normalized_input)
143149

144150
current_packs = int(
145151
self.config_entry.options.get(

custom_components/ecoflow_powerocean/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"domain": "ecoflow_powerocean",
33
"name": "EcoFlow PowerOcean",
4-
"version": "0.3.4",
4+
"version": "0.3.5",
55
"codeowners": [],
66
"config_flow": true,
77
"documentation": "https://github.com/Feberdin/ecoflow-powerocean-ha",

custom_components/ecoflow_powerocean/sensor.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
DEFAULT_NUM_BATTERY_PACKS,
6262
DOMAIN,
6363
MANUFACTURER,
64+
MAX_BATTERY_PACKS,
6465
MODEL,
6566
)
6667
from .coordinator import EcoFlowCoordinator
@@ -753,10 +754,23 @@ async def async_setup_entry(
753754
coordinator: EcoFlowCoordinator = hass.data[DOMAIN][entry.entry_id]
754755
serial = entry.data[CONF_SERIAL_NUMBER]
755756
# Options haben Vorrang vor initialen Konfigurationsdaten
756-
num_packs: int = entry.options.get(
757+
raw_num_packs = entry.options.get(
757758
CONF_NUM_BATTERY_PACKS,
758759
entry.data.get(CONF_NUM_BATTERY_PACKS, DEFAULT_NUM_BATTERY_PACKS),
759760
)
761+
try:
762+
num_packs = int(raw_num_packs)
763+
except (TypeError, ValueError):
764+
_LOGGER.warning(
765+
"Ungültiger Wert für %s: %r. Fallback auf Standard: %d",
766+
CONF_NUM_BATTERY_PACKS,
767+
raw_num_packs,
768+
DEFAULT_NUM_BATTERY_PACKS,
769+
)
770+
num_packs = DEFAULT_NUM_BATTERY_PACKS
771+
772+
# Defensive Begrenzung, damit keine ungültigen Sensor-Indizes entstehen.
773+
num_packs = max(1, min(MAX_BATTERY_PACKS, num_packs))
760774

761775
device_info = DeviceInfo(
762776
identifiers={(DOMAIN, serial)},

0 commit comments

Comments
 (0)