Skip to content

Commit

Permalink
Migrate to myskoda 0.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Prior99 committed Sep 21, 2024
1 parent 6eb4d6e commit 40b2dc3
Show file tree
Hide file tree
Showing 14 changed files with 917 additions and 1,018 deletions.
42 changes: 3 additions & 39 deletions custom_components/myskoda/__init__.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
"""The MySkoda integration."""

from __future__ import annotations

import logging
from datetime import timedelta

from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator

from myskoda import RestApi, Vehicle

from .const import DATA_COODINATOR, DOMAIN
from .const import COORDINATOR, DOMAIN
from .coordinator import MySkodaDataUpdateCoordinator

_LOGGER = logging.getLogger(__name__)

Expand All @@ -38,7 +33,7 @@ async def async_setup_entry(hass: HomeAssistant, config: ConfigEntry) -> bool:
await coordinator.async_config_entry_first_refresh()

hass.data.setdefault(DOMAIN, {})
hass.data[DOMAIN][config.entry_id] = {DATA_COODINATOR: coordinator}
hass.data[DOMAIN][config.entry_id] = {COORDINATOR: coordinator}

await hass.config_entries.async_forward_entry_setups(config, PLATFORMS)

Expand All @@ -52,34 +47,3 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
hass.data[DOMAIN].pop(entry.entry_id)

return unload_ok


class MySkodaDataUpdateCoordinator(DataUpdateCoordinator):
"""See `DataUpdateCoordinator`.
This class manages all data from the MySkoda API.
"""

def __init__(self, hass: HomeAssistant, config: ConfigEntry) -> None:
"""Create a new coordinator."""

super().__init__(
hass, _LOGGER, name=DOMAIN, update_interval=timedelta(minutes=5)
)
self.hub = RestApi(async_get_clientsession(hass))
self.config = config

async def async_login(self) -> bool:
"""Login to the MySkoda API. Will return `True` if successful."""

return await self.hub.authenticate(
self.config.data["email"], self.config.data["password"]
)

async def _async_update_data(self) -> dict[str, list[Vehicle]]:
return {
"vehicles": await self.hub.get_all_vehicles(),
}

def _unsub_refresh(self):
return
Loading

0 comments on commit 40b2dc3

Please sign in to comment.