Skip to content

Commit

Permalink
Merge pull request #2 from cdnninja/fix
Browse files Browse the repository at this point in the history
fix:  setup errors
  • Loading branch information
cdnninja authored Apr 15, 2024
2 parents 02b81d4 + 2c6726a commit 342c43b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion custom_components/yoto/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Platform,
)
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady, ConfigEntryAuthFailed
from homeassistant.exceptions import ConfigEntryNotReady

from .const import (
DOMAIN,
Expand Down
2 changes: 1 addition & 1 deletion custom_components/yoto/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def __init__(self, config_entry: ConfigEntry) -> None:
default=self.config_entry.options.get(
CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL
),
): vol.All(vol.Coerce(int), vol.Range(min=15, max=999))
): vol.All(vol.Coerce(int), vol.Range(min=15, max=999)),
}
)

Expand Down
24 changes: 10 additions & 14 deletions custom_components/yoto/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from __future__ import annotations

from datetime import timedelta


import logging

Expand Down Expand Up @@ -33,15 +35,18 @@ class YotoDataUpdateCoordinator(DataUpdateCoordinator):
def __init__(self, hass: HomeAssistant, config_entry: ConfigEntry) -> None:
"""Initialize."""
self.platforms: set[str] = set()
self.yoto_manager = None
self.yoto_manager = YotoManager(
username=config_entry.data.get(CONF_USERNAME),
password=config_entry.data.get(CONF_PASSWORD),
)
self.scan_interval: int = (
config_entry.options.get(CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL) * 60
)
super().__init__(
hass,
_LOGGER,
name=DOMAIN,
update_interval=self.scan_interval,
update_interval=timedelta(seconds=self.scan_interval),
)

async def _async_update_data(self):
Expand All @@ -50,27 +55,18 @@ async def _async_update_data(self):
Allow to update for the first time without further checking
"""
# try:
if self.yoto_manger is None:
self.yoto_manager = await hass.async_add_executor_job(
YotoManager, user_input[CONF_USERNAME], user_input[CONF_PASSWORD]
)
else:
await self.async_check_and_refresh_token()
await self.async_check_and_refresh_token()
# except AuthenticationError as AuthError:
# raise ConfigEntryAuthFailed(AuthError) from AuthError

await self.hass.async_add_executor_job(
self.yoto_manager.update_all_vehicles_with_cached_state
)
await self.hass.async_add_executor_job(self.yoto_manager.update_player_status)

return self.data

async def async_update_all(self) -> None:
"""Update yoto data."""
await self.async_check_and_refresh_token()
await self.hass.async_add_executor_job(
self.yoto_manager.update_all_vehicles_with_cached_state
)
await self.hass.async_add_executor_job(self.yoto_manager.update_player_status)
await self.async_refresh()

async def async_check_and_refresh_token(self):
Expand Down
2 changes: 1 addition & 1 deletion custom_components/yoto/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"integration_type": "hub",
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/cdnninja/yoto_ha/issues",
"requirements": ["yoto-api==1.0.10"],
"requirements": ["yoto-api==1.0.11"],
"version": "1.0.0"
}

0 comments on commit 342c43b

Please sign in to comment.