Skip to content

Commit

Permalink
Fix Hassfest warnings (#54)
Browse files Browse the repository at this point in the history
* Resolve warnings

* Define teslafi config schema
  • Loading branch information
jhansche authored Jan 5, 2025
1 parent 0080edb commit d70abb6
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions custom_components/teslafi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
"""TeslaFi integration."""

from __future__ import annotations

import voluptuous as vol

from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform, CONF_API_KEY
from homeassistant.const import CONF_API_KEY, Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.device_registry import DeviceEntry
from homeassistant.helpers import (
device_registry as dr,
)
from homeassistant.helpers.httpx_client import create_async_httpx_client
from homeassistant.helpers.typing import ConfigType

Expand All @@ -30,20 +32,29 @@
Platform.UPDATE,
]

CONFIG_SCHEMA = vol.Schema(
{
DOMAIN: vol.Schema(
{
vol.Required(CONF_API_KEY): cv.string,
}
)
}
)


async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Setup the integration"""
"""Set up the integration."""
hass.data.setdefault(DOMAIN, {})
hass.data[DOMAIN][HTTP_CLIENT] = create_async_httpx_client(hass)
# TODO: services?
return True


async def async_setup_entry(
hass: HomeAssistant,
entry: ConfigEntry,
) -> bool:
"""Setup from a config entry"""
"""Set up from a config entry."""
http_client = hass.data[DOMAIN][HTTP_CLIENT]
client = TeslaFiClient(entry.data[CONF_API_KEY], http_client)
coordinator = TeslaFiCoordinator(hass, client)
Expand Down Expand Up @@ -89,7 +100,7 @@ async def async_migrate_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
) -> bool:
"""Migrate old entry"""
"""Migrate old entry."""
current = config_entry.version
LOGGER.debug("Migrating from version %s", current)

Expand All @@ -107,11 +118,11 @@ async def async_migrate_entry(

if len(device.config_entries) == 1 and len(device.identifiers) == 3:
# Only 3 identifiers: likely all we need to do is move them around
new_identifiers = set(
new_identifiers = {
(DOMAIN, identifier)
for (n, identifier) in device.identifiers
if n == "vin" and identifier
)
}
if new_identifiers:
LOGGER.info(
"Migrating device %s identifiers %s to %s",
Expand Down

0 comments on commit d70abb6

Please sign in to comment.