mirror of
https://github.com/home-assistant/core.git
synced 2025-07-29 08:07:45 +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"
|
OFF = "off"
|
||||||
ECO_MODE = "eco_mode"
|
ECO_MODE = "eco_mode"
|
||||||
FULL_SOLAR = "full_solar"
|
FULL_SOLAR = "full_solar"
|
||||||
|
DISABLED = "disabled"
|
||||||
|
@ -166,13 +166,20 @@ class WallboxCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Set current solar charging mode
|
# Set current solar charging mode
|
||||||
eco_smart_enabled = data[CHARGER_DATA_KEY][CHARGER_ECO_SMART_KEY][
|
eco_smart_enabled = (
|
||||||
CHARGER_ECO_SMART_STATUS_KEY
|
data[CHARGER_DATA_KEY]
|
||||||
]
|
.get(CHARGER_ECO_SMART_KEY, {})
|
||||||
eco_smart_mode = data[CHARGER_DATA_KEY][CHARGER_ECO_SMART_KEY][
|
.get(CHARGER_ECO_SMART_STATUS_KEY)
|
||||||
CHARGER_ECO_SMART_MODE_KEY
|
)
|
||||||
]
|
|
||||||
if eco_smart_enabled is False:
|
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
|
data[CHARGER_ECO_SMART_KEY] = EcoSmartMode.OFF
|
||||||
elif eco_smart_mode == 0:
|
elif eco_smart_mode == 0:
|
||||||
data[CHARGER_ECO_SMART_KEY] = EcoSmartMode.ECO_MODE
|
data[CHARGER_ECO_SMART_KEY] = EcoSmartMode.ECO_MODE
|
||||||
|
@ -63,15 +63,15 @@ async def async_setup_entry(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Create wallbox select entities in HASS."""
|
"""Create wallbox select entities in HASS."""
|
||||||
coordinator: WallboxCoordinator = hass.data[DOMAIN][entry.entry_id]
|
coordinator: WallboxCoordinator = hass.data[DOMAIN][entry.entry_id]
|
||||||
|
if coordinator.data[CHARGER_ECO_SMART_KEY] != EcoSmartMode.DISABLED:
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
WallboxSelect(coordinator, description)
|
WallboxSelect(coordinator, description)
|
||||||
for ent in coordinator.data
|
for ent in coordinator.data
|
||||||
if (
|
if (
|
||||||
(description := SELECT_TYPES.get(ent))
|
(description := SELECT_TYPES.get(ent))
|
||||||
and description.supported_fn(coordinator)
|
and description.supported_fn(coordinator)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class WallboxSelect(WallboxEntity, SelectEntity):
|
class WallboxSelect(WallboxEntity, SelectEntity):
|
||||||
|
@ -216,6 +216,31 @@ async def setup_integration(hass: HomeAssistant, entry: MockConfigEntry) -> None
|
|||||||
await hass.async_block_till_done()
|
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(
|
async def setup_integration_select(
|
||||||
hass: HomeAssistant, entry: MockConfigEntry, response
|
hass: HomeAssistant, entry: MockConfigEntry, response
|
||||||
) -> None:
|
) -> None:
|
||||||
|
@ -13,6 +13,7 @@ from . import (
|
|||||||
authorisation_response,
|
authorisation_response,
|
||||||
setup_integration,
|
setup_integration,
|
||||||
setup_integration_connection_error,
|
setup_integration_connection_error,
|
||||||
|
setup_integration_no_eco_mode,
|
||||||
setup_integration_read_only,
|
setup_integration_read_only,
|
||||||
test_response,
|
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 await hass.config_entries.async_unload(entry.entry_id)
|
||||||
assert entry.state is ConfigEntryState.NOT_LOADED
|
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