Skip to content
This repository has been archived by the owner on Jun 7, 2024. It is now read-only.

Commit

Permalink
Fix everything to make base integration work (#8)
Browse files Browse the repository at this point in the history
* build: ➕ Add Conventional Commits to devcontainer

* revert: ⬇️ Move AIOAladdinConnect back to original 0.1.58

* fix: 🐛 Change import of config_entries

* fix: remove extraneous model fields

* refactor: 🚧 Fix all pathing and incorrect domain

* build: ⬆️ Update lint workflow to use python 3.12
  • Loading branch information
andyrak authored Apr 23, 2024
1 parent 49f17a0 commit f6ee951
Show file tree
Hide file tree
Showing 16 changed files with 37 additions and 39 deletions.
7 changes: 3 additions & 4 deletions .devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "andyrak/hacs-aladdin-legacy",
"image": "mcr.microsoft.com/devcontainers/python:3.11-bullseye",
"image": "mcr.microsoft.com/devcontainers/python:3.12-bookworm",
"postCreateCommand": "scripts/setup",
"forwardPorts": [
8123
Expand All @@ -17,15 +17,14 @@
"ms-python.python",
"github.vscode-pull-request-github",
"ryanluker.vscode-coverage-gutters",
"ms-python.vscode-pylance"
"ms-python.vscode-pylance",
"vivaxy.vscode-conventional-commits"
],
"settings": {
"files.eol": "\n",
"editor.tabSize": 4,
"python.pythonPath": "/usr/bin/python3",
"python.analysis.autoSearchPaths": false,
"python.linting.pylintEnabled": true,
"python.linting.enabled": true,
"python.formatting.provider": "black",
"python.formatting.blackPath": "/usr/local/py-utils/bin/black",
"editor.formatOnPaste": false,
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: "Set up Python"
uses: actions/[email protected]
with:
python-version: "3.11"
python-version: "3.12"
cache: "pip"

- name: "Install requirements"
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ jobs:
shell: "bash"
run: |
yq -i -o json '.version="${{ github.event.release.tag_name }}"' \
"${{ github.workspace }}/custom_components/custom_components/aladdin_connect_legacy_integration/manifest.json"
"${{ github.workspace }}/custom_components/aladdin_connect_legacy/manifest.json"
- name: "ZIP the integration directory"
shell: "bash"
run: |
cd "${{ github.workspace }}/custom_components/custom_components/aladdin_connect_legacy_integration"
zip custom_components/aladdin_connect_legacy_integration.zip -r ./
cd "${{ github.workspace }}/custom_components/aladdin_connect_legacy"
zip custom_components/aladdin_connect_legacy.zip -r ./
- name: "Upload the ZIP file to the release"
uses: softprops/[email protected]
with:
files: ${{ github.workspace }}/custom_components/custom_components/aladdin_connect_legacy_integration/custom_components/aladdin_connect_legacy_integration.zip
files: ${{ github.workspace }}/custom_components/aladdin_connect_legacy.zip
2 changes: 1 addition & 1 deletion config/configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ default_config:
logger:
default: info
logs:
custom_components.custom_components/aladdin_connect_legacy_integration: debug
custom_components.aladdin_connect_legacy: debug
8 changes: 4 additions & 4 deletions custom_components/aladdin_connect_legacy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import AIOAladdinConnect.session_manager as Aladdin
from aiohttp import ClientError

from homeassistant.config_entries import ConfigEntry
from homeassistant import config_entries
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, Platform
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
Expand All @@ -19,8 +19,8 @@
PLATFORMS: list[Platform] = [Platform.COVER, Platform.SENSOR]


async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up platform from a ConfigEntry."""
async def async_setup_entry(hass: HomeAssistant, entry: config_entries.ConfigEntry) -> bool:
"""Set up platform from a config_entries.ConfigEntry."""
username = entry.data[CONF_USERNAME]
password = entry.data[CONF_PASSWORD]
acc = AladdinConnectClient(
Expand All @@ -39,7 +39,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return True


async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
async def async_unload_entry(hass: HomeAssistant, entry: config_entries.ConfigEntry) -> bool:
"""Unload a config entry."""
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
hass.data[DOMAIN].pop(entry.entry_id)
Expand Down
12 changes: 6 additions & 6 deletions custom_components/aladdin_connect_legacy/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from aiohttp.client_exceptions import ClientError
import voluptuous as vol

from homeassistant.config_entries import ConfigEntry, ConfigFlow, ConfigFlowResult
from homeassistant import config_entries
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
Expand Down Expand Up @@ -48,23 +48,23 @@ async def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> None:
raise InvalidAuth from ex


class AladdinConnectConfigFlow(ConfigFlow, domain=DOMAIN):
class AladdinConnectConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
"""Handle a config flow for Aladdin Connect."""

VERSION = 1
entry: ConfigEntry | None
entry: config_entries.ConfigEntry | None

async def async_step_reauth(
self, entry_data: Mapping[str, Any]
) -> ConfigFlowResult:
) -> config_entries.ConfigFlowResult:
"""Handle re-authentication with Aladdin Connect."""

self.entry = self.hass.config_entries.async_get_entry(self.context["entry_id"])
return await self.async_step_reauth_confirm()

async def async_step_reauth_confirm(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
) -> config_entries.ConfigFlowResult:
"""Confirm re-authentication with Aladdin Connect."""
errors: dict[str, str] = {}

Expand Down Expand Up @@ -104,7 +104,7 @@ async def async_step_reauth_confirm(

async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
) -> config_entries.ConfigFlowResult:
"""Handle the initial step."""
if user_input is None:
return self.async_show_form(
Expand Down
2 changes: 1 addition & 1 deletion custom_components/aladdin_connect_legacy/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
"closing": STATE_CLOSING,
}

DOMAIN = "aladdin_connect"
DOMAIN = "aladdin_connect_legacy"
SUPPORTED_FEATURES: Final = CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE
CLIENT_ID = "1000"
6 changes: 3 additions & 3 deletions custom_components/aladdin_connect_legacy/coordinator.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""DataUpdateCoordinator for custom_components/aladdin_connect_legacy_integration."""
"""DataUpdateCoordinator for custom_components/aladdin_connect_legacy."""
from __future__ import annotations

from datetime import timedelta

from homeassistant.config_entries import ConfigEntry
from homeassistant import config_entries
from homeassistant.core import HomeAssistant
from homeassistant.helpers.update_coordinator import (
DataUpdateCoordinator,
Expand All @@ -23,7 +23,7 @@
class BlueprintDataUpdateCoordinator(DataUpdateCoordinator):
"""Class to manage fetching data from the API."""

config_entry: ConfigEntry
config_entry: config_entries.ConfigEntry

def __init__(
self,
Expand Down
8 changes: 4 additions & 4 deletions custom_components/aladdin_connect_legacy/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from AIOAladdinConnect import AladdinConnectClient, session_manager

from homeassistant.components.cover import CoverDeviceClass, CoverEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant import config_entries
from homeassistant.const import STATE_CLOSED, STATE_CLOSING, STATE_OPENING
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError, PlatformNotReady
Expand All @@ -24,7 +24,7 @@

async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
config_entry: config_entries.ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up the Aladdin Connect platform."""
Expand All @@ -39,7 +39,7 @@ async def async_setup_entry(


def remove_stale_devices(
hass: HomeAssistant, config_entry: ConfigEntry, devices: list[dict]
hass: HomeAssistant, config_entry: config_entries.ConfigEntry, devices: list[dict]
) -> None:
"""Remove stale devices from device registry."""
device_registry = dr.async_get(hass)
Expand Down Expand Up @@ -74,7 +74,7 @@ class AladdinDevice(CoverEntity):
_attr_name = None

def __init__(
self, acc: AladdinConnectClient, device: DoorDevice, entry: ConfigEntry
self, acc: AladdinConnectClient, device: DoorDevice, entry: config_entries.ConfigEntry
) -> None:
"""Initialize the Aladdin Connect cover."""
self._acc = acc
Expand Down
4 changes: 2 additions & 2 deletions custom_components/aladdin_connect_legacy/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from AIOAladdinConnect import AladdinConnectClient

from homeassistant.components.diagnostics import async_redact_data
from homeassistant.config_entries import ConfigEntry
from homeassistant import config_entries
from homeassistant.core import HomeAssistant

from .const import DOMAIN
Expand All @@ -17,7 +17,7 @@

async def async_get_config_entry_diagnostics(
hass: HomeAssistant,
config_entry: ConfigEntry,
config_entry: config_entries.ConfigEntry,
) -> dict[str, Any]:
"""Return diagnostics for a config entry."""

Expand Down
2 changes: 1 addition & 1 deletion custom_components/aladdin_connect_legacy/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"aladdin_connect_legacy"
],
"requirements": [
"AIOAladdinConnect==0.2.0"
"AIOAladdinConnect==0.1.58"
],
"version": "0.1.0"
}
3 changes: 1 addition & 2 deletions custom_components/aladdin_connect_legacy/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ class DoorDevice(TypedDict):
status: str
serial: str
model: str
fault: str
battery_level: int

4 changes: 2 additions & 2 deletions custom_components/aladdin_connect_legacy/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
SensorEntityDescription,
SensorStateClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant import config_entries
from homeassistant.const import PERCENTAGE, SIGNAL_STRENGTH_DECIBELS
from homeassistant.core import HomeAssistant
from homeassistant.helpers.device_registry import DeviceInfo
Expand Down Expand Up @@ -62,7 +62,7 @@ class AccSensorEntityDescription(SensorEntityDescription):


async def async_setup_entry(
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
hass: HomeAssistant, entry: config_entries.ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None:
"""Set up Aladdin Connect sensor devices."""

Expand Down
4 changes: 2 additions & 2 deletions hacs.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "Aladdin Connect Legacy",
"filename": "custom_components/aladdin_connect_legacy_integration.zip",
"filename": "custom_components/aladdin_connect_legacy.zip",
"hide_default_branch": true,
"homeassistant": "2023.8.0",
"homeassistant": "2024.4.3",
"render_readme": true,
"zip_release": true
}
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
colorlog==6.8.2
homeassistant==2023.8.0
homeassistant==2024.4.3
pip>=21.0,<24.1
ruff==0.4.1
2 changes: 1 addition & 1 deletion scripts/develop
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if [[ ! -d "${PWD}/config" ]]; then
fi

# Set the path to custom_components
## This let's us have the structure we want <root>/custom_components/custom_components/aladdin_connect_legacy_integration
## This let's us have the structure we want <root>/custom_components/aladdin_connect_legacy
## while at the same time have Home Assistant configuration inside <root>/config
## without resulting to symlinks.
export PYTHONPATH="${PYTHONPATH}:${PWD}/custom_components"
Expand Down

0 comments on commit f6ee951

Please sign in to comment.