-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for DVSPortal (dutch parking) to HA #134289
base: dev
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @ChessSpider
It seems you haven't yet signed a CLA. Please do so here.
Once you do that we will be able to review and accept this pull request.
Thanks!
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
db86a30
to
74d1364
Compare
Documentation PR is here home-assistant/home-assistant.io#36722 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's split out the service call for now to keep the PR better scoped
hi @joostlek , im also on discord if you'd like to discuss there. Here in the PR is fine with me as well. thank you for your time and effort! Note that im aiming for quality scale bronze now, but i do intent to upgrade to higher quality levels once this is merged in. |
hi @joostlek , just to manage my expectations, when do you thnik youll have time for a review? thank you in advance |
I can review when I have the time, there are 480 or so PRs open so there is quite the queue :) |
ha_registered_license_plates: set[str] | ||
|
||
|
||
type DVSPortalConfigEntry = config_entries.ConfigEntry[DVSPortalRuntimeData] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type DVSPortalConfigEntry = config_entries.ConfigEntry[DVSPortalRuntimeData] | |
type DVSPortalConfigEntry = ConfigEntry[DVSPortalRuntimeData] |
await dvs_portal.close() | ||
raise exceptions.ConfigEntryNotReady("Failed to initialize DVSPortal") from ex | ||
|
||
async def async_unload_entry( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weird indent
|
||
|
||
async def async_setup_entry( | ||
hass: core.HomeAssistant, entry: DVSPortalConfigEntry |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hass: core.HomeAssistant, entry: DVSPortalConfigEntry | |
hass: HomeAssistant, entry: DVSPortalConfigEntry |
try: | ||
# Verify login still works | ||
await dvs_portal.token() | ||
|
||
# Setup and init stuff | ||
coordinator = DVSPortalCoordinator(hass, dvs_portal) | ||
|
||
entry.runtime_data = DVSPortalRuntimeData( | ||
dvs_portal=dvs_portal, | ||
coordinator=coordinator, | ||
ha_registered_license_plates=set(), | ||
) | ||
await hass.config_entries.async_forward_entry_setups(entry, ["sensor"]) | ||
|
||
# Check if the first refresh is successful | ||
await coordinator.async_config_entry_first_refresh() | ||
except dvs_exceptions.DVSPortalError as ex: | ||
await dvs_portal.close() | ||
raise exceptions.ConfigEntryNotReady("Failed to initialize DVSPortal") from ex |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only have stuff in the try block that can raise
class DVSPortalRuntimeData(TypedDict): | ||
"""Typed runtime data for dvsportal.""" | ||
|
||
dvs_portal: DVSPortal | ||
coordinator: DVSPortalCoordinator | ||
ha_registered_license_plates: set[str] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need all 3? the client is available via the coordinator and the latter one isnt used
return { | ||
"default_code": self.dvs_portal.default_code, | ||
"default_type_id": self.dvs_portal.default_type_id, | ||
"balance": self.dvs_portal.balance, | ||
"active_reservations": self.dvs_portal.active_reservations, | ||
"historic_reservations": self.dvs_portal.historic_reservations, | ||
"known_license_plates": self.dvs_portal.known_license_plates, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't you use a dataclass? Rather define it here than in types.py
hass, | ||
_LOGGER, | ||
name=f"{DOMAIN}_coordinator", | ||
update_method=self.async_update_data, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update_method=self.async_update_data, |
) | ||
self.dvs_portal = dvs_portal | ||
|
||
async def async_update_data(self) -> DVSPortalData: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
async def async_update_data(self) -> DVSPortalData: | |
async def _async_update_data(self) -> DVSPortalData: |
"""Fetch data from the DVSPortal API.""" | ||
try: | ||
await self.dvs_portal.update() | ||
except Exception as e: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're only allowed to catch exceptions in the config flow
Proposed change
Add support of DVSPortal. DVSPortal is a parking system in use by some dutch muncipalities. Like these: https://www.google.com/search?q=inurl%3Advsportal
Documentation PR home-assistant/home-assistant.io#36722
Type of change
Additional information
Checklist
ruff format homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
.To help with the load of incoming pull requests: