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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
__pycache__/
*.pyc
40 changes: 38 additions & 2 deletions custom_components/pid_departures/__init__.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,56 @@
"""Prague Departure Board integration."""
from __future__ import annotations

import logging

from homeassistant.const import CONF_ID
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er

from .const import DOMAIN
from .coordinator import PIDConfigEntry, PIDDepartureUpdateCoordinator

_LOGGER = logging.getLogger(__name__)

PLATFORMS: list[str] = ["sensor", "binary_sensor", "calendar"]


async def async_migrate_entry(hass: HomeAssistant, entry: PIDConfigEntry) -> bool:
"""Migrate old config entries.

1.1: releases before 3.0.0 declared the config flow version as 0.1. The stored
data is unchanged since then, so only the version number is raised.
1.2: entries created before unique IDs were introduced get the stop ID as
unique ID.
"""
_LOGGER.debug(
"Migrating entry %s from version %s.%s",
entry.title,
entry.version,
entry.minor_version,
)
if entry.version > 1:
# Downgraded from a newer version with an incompatible format.
return False

if entry.version < 1:
hass.config_entries.async_update_entry(entry, version=1, minor_version=1)

if entry.minor_version < 2:
_async_set_missing_unique_id(hass, entry)
hass.config_entries.async_update_entry(entry, minor_version=2)

_LOGGER.debug(
"Migrated entry %s to version %s.%s",
entry.title,
entry.version,
entry.minor_version,
)
return True


async def async_setup_entry(hass: HomeAssistant, entry: PIDConfigEntry) -> bool:
"""Set up Departure Board from a config entry."""
_async_set_missing_unique_id(hass, entry)

coordinator = PIDDepartureUpdateCoordinator(hass, entry)
await coordinator.async_config_entry_first_refresh()

Expand Down
1 change: 1 addition & 0 deletions custom_components/pid_departures/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ async def validate_api_key(hass: HomeAssistant, api_key: str, stop_id: str) -> N
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):

VERSION = 1
MINOR_VERSION = 2

async def async_step_user(self, user_input: dict[str, Any] | None = None) -> ConfigFlowResult:
# Check for any previous instance of the integration
Expand Down
2 changes: 1 addition & 1 deletion custom_components/pid_departures/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/dvejsada/PID_integration/issues",
"requirements": [],
"version": "3.0.0"
"version": "3.0.1"
}
Loading