Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
lunDreame authored Oct 10, 2024
1 parent fadee0d commit 4c29bd1
Show file tree
Hide file tree
Showing 11 changed files with 184 additions and 253 deletions.
48 changes: 4 additions & 44 deletions custom_components/apti/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,12 @@

from __future__ import annotations

from datetime import datetime
import voluptuous as vol

from homeassistant.core import (
HomeAssistant,
ServiceCall,
ServiceResponse,
SupportsResponse
)
from homeassistant.core import HomeAssistant
from homeassistant.config_entries import ConfigEntry
from homeassistant.components import persistent_notification
from homeassistant.helpers.event import async_track_time_interval
import homeassistant.helpers.config_validation as cv

from .coordinator import APTiDataUpdateCoordinator
from .const import (
DOMAIN,
PLATFORMS,
UPDATE_SESSION_INTERVAL,
UPDATE_MAINT_INTERVAL,
UPDATE_ENERGY_INTERVAL
)

format_date = datetime.now().strftime("%Y%m%d")

VISIT_RESERVATION_SCHEMA = vol.Schema({
vol.Required("car_no"): cv.string,
vol.Required("phone_no"): cv.string,
vol.Required("visit_date", default=format_date): cv.datetime,
})
from .const import PLATFORMS, UPDATE_ME_INTERVAL


async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
Expand All @@ -42,22 +18,12 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
await coordinator.async_config_entry_first_refresh()

async_track_time_interval(
hass, coordinator.api.login, UPDATE_SESSION_INTERVAL,
cancel_on_shutdown=True
)
async_track_time_interval(
hass, coordinator._update_maint, UPDATE_MAINT_INTERVAL,
cancel_on_shutdown=True
)
async_track_time_interval(
hass, coordinator._update_energy, UPDATE_ENERGY_INTERVAL,
hass, coordinator._update_maint_energy, UPDATE_ME_INTERVAL,
cancel_on_shutdown=True
)

entry.runtime_data = coordinator

#await _async_setup_service(hass, entry)

await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
return True

Expand All @@ -68,11 +34,5 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
entry, PLATFORMS
):
coordinator: APTiDataUpdateCoordinator = entry.runtime_data

return unload_ok


async def _async_setup_service(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Set up the service."""

async def _async_visit_reservation(call: ServiceCall) -> ServiceResponse:
"""Perform vehicle visit reservation service."""
Loading

0 comments on commit 4c29bd1

Please sign in to comment.