mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 07:37:34 +00:00
Fix missing key for ecosmart in older Wallbox models (#146847)
* fix 146839, missing key * added tests for this issue * added tests for this issue * added tests for this issue, formatting * Prevent loading select on missing key * Prevent loading select on missing key - formatting fixed * Update homeassistant/components/wallbox/coordinator.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
parent
f5355c833e
commit
6e92247799
@ -74,3 +74,4 @@ class EcoSmartMode(StrEnum):
|
||||
OFF = "off"
|
||||
ECO_MODE = "eco_mode"
|
||||
FULL_SOLAR = "full_solar"
|
||||
DISABLED = "disabled"
|
||||
|
@ -166,13 +166,20 @@ class WallboxCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
||||
)
|
||||
|
||||
# Set current solar charging mode
|
||||
eco_smart_enabled = data[CHARGER_DATA_KEY][CHARGER_ECO_SMART_KEY][
|
||||
CHARGER_ECO_SMART_STATUS_KEY
|
||||
]
|
||||
eco_smart_mode = data[CHARGER_DATA_KEY][CHARGER_ECO_SMART_KEY][
|
||||
CHARGER_ECO_SMART_MODE_KEY
|
||||
]
|
||||
if eco_smart_enabled is False:
|
||||
eco_smart_enabled = (
|
||||
data[CHARGER_DATA_KEY]
|
||||
.get(CHARGER_ECO_SMART_KEY, {})
|
||||
.get(CHARGER_ECO_SMART_STATUS_KEY)
|
||||
)
|
||||
|
||||
eco_smart_mode = (
|
||||
data[CHARGER_DATA_KEY]
|
||||
.get(CHARGER_ECO_SMART_KEY, {})
|
||||
.get(CHARGER_ECO_SMART_MODE_KEY)
|
||||
)
|
||||
if eco_smart_mode is None:
|
||||
data[CHARGER_ECO_SMART_KEY] = EcoSmartMode.DISABLED
|
||||
elif eco_smart_enabled is False:
|
||||
data[CHARGER_ECO_SMART_KEY] = EcoSmartMode.OFF
|
||||
elif eco_smart_mode == 0:
|
||||
data[CHARGER_ECO_SMART_KEY] = EcoSmartMode.ECO_MODE
|
||||
|
@ -63,15 +63,15 @@ async def async_setup_entry(
|
||||
) -> None:
|
||||
"""Create wallbox select entities in HASS."""
|
||||
coordinator: WallboxCoordinator = hass.data[DOMAIN][entry.entry_id]
|
||||
|
||||
async_add_entities(
|
||||
WallboxSelect(coordinator, description)
|
||||
for ent in coordinator.data
|
||||
if (
|
||||
(description := SELECT_TYPES.get(ent))
|
||||
and description.supported_fn(coordinator)
|
||||
if coordinator.data[CHARGER_ECO_SMART_KEY] != EcoSmartMode.DISABLED:
|
||||
async_add_entities(
|
||||
WallboxSelect(coordinator, description)
|
||||
for ent in coordinator.data
|
||||
if (
|
||||
(description := SELECT_TYPES.get(ent))
|
||||
and description.supported_fn(coordinator)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
class WallboxSelect(WallboxEntity, SelectEntity):
|
||||
|
@ -216,6 +216,31 @@ async def setup_integration(hass: HomeAssistant, entry: MockConfigEntry) -> None
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
async def setup_integration_no_eco_mode(
|
||||
hass: HomeAssistant, entry: MockConfigEntry
|
||||
) -> None:
|
||||
"""Test wallbox sensor class setup."""
|
||||
with requests_mock.Mocker() as mock_request:
|
||||
mock_request.get(
|
||||
"https://user-api.wall-box.com/users/signin",
|
||||
json=authorisation_response,
|
||||
status_code=HTTPStatus.OK,
|
||||
)
|
||||
mock_request.get(
|
||||
"https://api.wall-box.com/chargers/status/12345",
|
||||
json=test_response_no_power_boost,
|
||||
status_code=HTTPStatus.OK,
|
||||
)
|
||||
mock_request.put(
|
||||
"https://api.wall-box.com/v2/charger/12345",
|
||||
json={CHARGER_MAX_CHARGING_CURRENT_KEY: 20},
|
||||
status_code=HTTPStatus.OK,
|
||||
)
|
||||
|
||||
await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
async def setup_integration_select(
|
||||
hass: HomeAssistant, entry: MockConfigEntry, response
|
||||
) -> None:
|
||||
|
@ -13,6 +13,7 @@ from . import (
|
||||
authorisation_response,
|
||||
setup_integration,
|
||||
setup_integration_connection_error,
|
||||
setup_integration_no_eco_mode,
|
||||
setup_integration_read_only,
|
||||
test_response,
|
||||
)
|
||||
@ -138,3 +139,15 @@ async def test_wallbox_refresh_failed_read_only(
|
||||
|
||||
assert await hass.config_entries.async_unload(entry.entry_id)
|
||||
assert entry.state is ConfigEntryState.NOT_LOADED
|
||||
|
||||
|
||||
async def test_wallbox_setup_load_entry_no_eco_mode(
|
||||
hass: HomeAssistant, entry: MockConfigEntry
|
||||
) -> None:
|
||||
"""Test Wallbox Unload."""
|
||||
|
||||
await setup_integration_no_eco_mode(hass, entry)
|
||||
assert entry.state is ConfigEntryState.LOADED
|
||||
|
||||
assert await hass.config_entries.async_unload(entry.entry_id)
|
||||
assert entry.state is ConfigEntryState.NOT_LOADED
|
||||
|
Loading…
x
Reference in New Issue
Block a user