Skip to content

Commit

Permalink
Merge branch 'main' into pr/hass-24.11
Browse files Browse the repository at this point in the history
  • Loading branch information
jhansche authored Jan 5, 2025
2 parents fce6a13 + 7b60791 commit a7687bd
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/hacs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: HACS Action

on:
push:
branches:
- main
pull_request:
schedule:
- cron: "45 2 * * 2"
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/hassfest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: Validate with hassfest

on:
push:
branches:
- main
pull_request:
schedule:
- cron: "15 1 * * 1"
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/pythonpackages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: Python package

on:
push:
branches:
- main
pull_request:
schedule:
- cron: "30 16 * * WED"

Expand Down
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 a7687bd

Please sign in to comment.