Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions custom_components/zaptec/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
CONF_CHARGERS,
CONF_MANUAL_SELECT,
CONF_PREFIX,
DOMAIN,
REDACT_DUMP_ON_STARTUP,
REDACT_LOGS,
ZAPTEC_POLL_INTERVAL_BUILD,
Expand Down Expand Up @@ -113,6 +114,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
zaptec=zaptec,
configured_chargers=configured_chargers,
)
if not tracked_devices:
msg = "No Zaptec installations or chargers found for this account or selection"
raise ConfigEntryError(
msg,
translation_domain=DOMAIN,
translation_key="no_devices_found",
translation_placeholders={"username": entry.data[CONF_USERNAME]},
)

# Setup the manager which will be where all the instance data is stored
manager = ZaptecManager(
Expand Down
3 changes: 0 additions & 3 deletions custom_components/zaptec/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,6 @@ async def first_time_setup(zaptec: Zaptec, configured_chargers: set[str] | None)
if charger.installation:
keep.add(charger.installation.id)

if not keep:
_LOGGER.error("No zaptec objects will be added")

# These objects will be updated by the coordinator
tracked_devices = keep

Expand Down
5 changes: 5 additions & 0 deletions custom_components/zaptec/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -205,5 +205,10 @@
"name": "Firmware-Update"
}
}
},
"exceptions": {
"no_devices_found": {
"message": "Keine Zaptec-Installationen oder -Ladegeräte für das Konto {username} gefunden. Prüfe über Neu konfigurieren, ob dies das richtige Zaptec-Konto ist und ob die ausgewählten Ladegeräte noch existieren."
}
}
}
5 changes: 5 additions & 0 deletions custom_components/zaptec/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -205,5 +205,10 @@
"name": "Firmware update"
}
}
},
"exceptions": {
"no_devices_found": {
"message": "No Zaptec installations or chargers found for account {username}. Check that this is the right Zaptec account and that the selected chargers still exist, using Reconfigure."
}
}
}
5 changes: 5 additions & 0 deletions custom_components/zaptec/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -205,5 +205,10 @@
"name": "Mise à jour du micrologiciel"
}
}
},
"exceptions": {
"no_devices_found": {
"message": "Aucune installation ni borne Zaptec trouvée pour le compte {username}. Vérifiez via Reconfigurer qu'il s'agit du bon compte Zaptec et que les bornes sélectionnées existent toujours."
}
}
}
5 changes: 5 additions & 0 deletions custom_components/zaptec/translations/nb.json
Original file line number Diff line number Diff line change
Expand Up @@ -205,5 +205,10 @@
"name": "Fastvareoppdatering"
}
}
},
"exceptions": {
"no_devices_found": {
"message": "Fant ingen Zaptec-installasjoner eller -ladere for kontoen {username}. Bruk Rekonfigurer for å sjekke at dette er riktig Zaptec-konto og at de valgte laderne fortsatt finnes."
}
}
}
5 changes: 5 additions & 0 deletions custom_components/zaptec/translations/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -205,5 +205,10 @@
"name": "Firmware"
}
}
},
"exceptions": {
"no_devices_found": {
"message": "Geen Zaptec-installaties of -laders gevonden voor account {username}. Controleer via Opnieuw configureren of dit het juiste Zaptec-account is en of de geselecteerde laders nog bestaan."
}
}
}
5 changes: 5 additions & 0 deletions custom_components/zaptec/translations/nn.json
Original file line number Diff line number Diff line change
Expand Up @@ -205,5 +205,10 @@
"name": "Fastvareoppdatering"
}
}
},
"exceptions": {
"no_devices_found": {
"message": "Fann ingen Zaptec-installasjonar eller -ladarar for kontoen {username}. Bruk Rekonfigurer for å sjekke at dette er rett Zaptec-konto og at dei valde ladarane framleis finst."
}
}
}
5 changes: 5 additions & 0 deletions custom_components/zaptec/translations/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -205,5 +205,10 @@
"name": "Aktualizacja oprogramowania"
}
}
},
"exceptions": {
"no_devices_found": {
"message": "Nie znaleziono instalacji ani ładowarek Zaptec dla konta {username}. Sprawdź za pomocą Zmień konfigurację, czy to właściwe konto Zaptec i czy wybrane ładowarki nadal istnieją."
}
}
}
5 changes: 5 additions & 0 deletions custom_components/zaptec/translations/sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -205,5 +205,10 @@
"name": "Uppdatera mjukvara"
}
}
},
"exceptions": {
"no_devices_found": {
"message": "Inga Zaptec-installationer eller laddare hittades för kontot {username}. Kontrollera via Konfigurera om att detta är rätt Zaptec-konto och att de valda laddarna fortfarande finns."
}
}
}
55 changes: 54 additions & 1 deletion tests/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from __future__ import annotations

import asyncio
from collections.abc import Callable
from collections.abc import Callable, Iterator
import logging
from types import SimpleNamespace
from typing import Any
Expand Down Expand Up @@ -351,3 +351,56 @@ async def stream_main(*, on_connect: Callable[[], None], **kwargs: object) -> No

warnings = [r for r in caplog.records if r.levelno == logging.WARNING]
assert len(warnings) == 1 # the second failure never connected, so it is the same outage


class FakeZaptec:
"""Stands in for the Zaptec account hierarchy built by first_time_setup."""

def __init__(self, charger_ids: list[str], installation_id: str | None = None) -> None:
"""Initialize the hierarchy."""
installation = SimpleNamespace(id=installation_id) if installation_id else None
self.chargers = [
SimpleNamespace(id=cid, installation=installation) for cid in charger_ids
]
self.build = AsyncMock()
self._ids = set(charger_ids) | ({installation_id} if installation_id else set())

def __iter__(self) -> Iterator[str]:
"""Iterate over all object ids."""
return iter(self._ids)


@pytest.mark.asyncio
async def test_first_time_setup_without_chargers_tracks_nothing() -> None:
"""An account that logs in but sees no devices tracks nothing."""
assert await ZaptecManager.first_time_setup(FakeZaptec([]), configured_chargers=None) == set()


@pytest.mark.asyncio
async def test_first_time_setup_without_selected_chargers_tracks_nothing() -> None:
"""Manually selected chargers that are all gone track nothing."""
tracked = await ZaptecManager.first_time_setup(
FakeZaptec(["other"], installation_id="inst"), configured_chargers={CHARGER_ID}
)

assert tracked == set()


@pytest.mark.asyncio
async def test_first_time_setup_tracks_charger_and_installation() -> None:
"""A selected charger is tracked together with its installation."""
tracked = await ZaptecManager.first_time_setup(
FakeZaptec([CHARGER_ID], installation_id="inst"), configured_chargers={CHARGER_ID}
)

assert tracked == {CHARGER_ID, "inst"}


@pytest.mark.asyncio
async def test_first_time_setup_tracks_installation_without_chargers() -> None:
"""An installation without chargers is still set up."""
tracked = await ZaptecManager.first_time_setup(
FakeZaptec([], installation_id="inst"), configured_chargers=None
)

assert tracked == {"inst"}
Loading