Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,22 @@ on:
pull_request:
paths:
- '**.py'
- 'custom_components/**/*.json'
- 'requirements.test.txt'
- '.github/workflows/tests.yaml'
push:
paths:
- '**.py'
- 'custom_components/**/*.json'
- 'requirements.test.txt'
- '.github/workflows/tests.yaml'

jobs:
tests:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.12']
python-version: ['3.12', '3.14']

steps:
- uses: actions/checkout@v4
Expand Down
4 changes: 4 additions & 0 deletions custom_components/poollab/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

_LOGGER = logging.getLogger(__name__)

API_KEY_URL = "https://labcom.cloud/pages/user-setting"


class PoolLabConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
"""PoolLab config flow."""
Expand Down Expand Up @@ -84,6 +86,7 @@ async def async_step_user(
step_id="user",
data_schema=user_schema,
errors=errors,
description_placeholders={"api_key_url": API_KEY_URL},
)

async def async_step_reconfigure(
Expand Down Expand Up @@ -129,6 +132,7 @@ async def async_step_reconfigure(
step_id="reconfigure",
data_schema=user_schema,
errors=errors,
description_placeholders={"api_key_url": API_KEY_URL},
)

async def async_step_import(self, import_data) -> FlowResult:
Expand Down
4 changes: 2 additions & 2 deletions custom_components/poollab/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"step": {
"user": {
"title": "PoolLab",
"description": "Setup a PoolLab integration, get key from https://labcom.cloud/pages/user-setting",
"description": "Setup a PoolLab integration, get key from {api_key_url}",
"data": {
"api_key": "API key",
"url": "API endpoint URL",
Expand All @@ -12,7 +12,7 @@
},
"reconfigure": {
"title": "PoolLab",
"description": "Reconfigure a PoolLab integration, get key from https://labcom.cloud/pages/user-setting",
"description": "Reconfigure a PoolLab integration, get key from {api_key_url}",
"data": {
"api_key": "API key",
"url": "API endpoint URL",
Expand Down
76 changes: 47 additions & 29 deletions tests/test_config_flow.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,51 @@
"""config_flow tests."""
"""Tests for PoolLab configuration forms."""

from unittest import mock
import json
from pathlib import Path

from custom_components.poollab import config_flow
import pytest
from pytest_homeassistant_custom_component.common import MockConfigEntry

from homeassistant.config_entries import SOURCE_RECONFIGURE, SOURCE_USER
from homeassistant.const import CONF_API_KEY, CONF_SSL, CONF_URL
from homeassistant.data_entry_flow import FlowResultType

from custom_components.poollab import config_flow
from custom_components.poollab.const import DOMAIN
from custom_components.poollab.poollab import API_ENDPOINT


@pytest.mark.parametrize("source", [SOURCE_USER, SOURCE_RECONFIGURE])
async def test_config_form_api_key_link(hass, source):
"""Both forms must supply a working URL for their translated description."""
context = {"source": source}
if source == SOURCE_RECONFIGURE:
entry = MockConfigEntry(
domain=DOMAIN,
title="PoolLab",
unique_id="test-api-key",
version=config_flow.PoolLabConfigFlow.VERSION,
minor_version=config_flow.PoolLabConfigFlow.MINOR_VERSION,
data={
CONF_API_KEY: "test-api-key",
CONF_URL: API_ENDPOINT,
CONF_SSL: True,
},
)
entry.add_to_hass(hass)
context["entry_id"] = entry.entry_id

result = await hass.config_entries.flow.async_init(DOMAIN, context=context)

assert result["type"] == FlowResultType.FORM
assert result["step_id"] == source
assert result["errors"] == {}

# from pytest_homeassistant_custom_component.async_mock import patch
import voluptuous as vol

from homeassistant import config_entries
from homeassistant.const import ATTR_NAME, ATTR_UNIT_OF_MEASUREMENT
from homeassistant.helpers import selector


# @pytest.mark.asyncio
# async def test_flow_init(hass):
# """Test the initial flow."""
# result = await hass.config_entries.flow.async_init(
# config_flow.DOMAIN, context={"source": "user"}
# )

# expected = {
# "data_schema": SCHEMA_COPY,
# # "data_schema": config_flow.DATA_SCHEMA,
# "description_placeholders": None,
# "errors": {},
# "flow_id": mock.ANY,
# "handler": "poollab",
# "step_id": "user",
# "type": "form",
# }
# assert expected == result
translations = json.loads(
(Path(config_flow.__file__).parent / "translations" / "en.json").read_text()
)
description = translations["config"]["step"][source]["description"]
assert "https://" not in description
rendered_description = description.format(**result["description_placeholders"])
assert "https://labcom.cloud/pages/user-setting" in rendered_description
hass.config_entries.flow.async_abort(result["flow_id"])
49 changes: 7 additions & 42 deletions tests/test_coordinator.py
Original file line number Diff line number Diff line change
@@ -1,48 +1,13 @@
"""planner tests."""
"""Tests for the PoolLab coordinator."""

from unittest import mock

# from custom_components.poollab.poollab import PoolLabApi
# from pytest_homeassistant_custom_component.async_mock import patch
# from pytest_homeassistant_custom_component.common import (
# MockModule,
# MockPlatform,
# mock_integration,
# mock_platform,
# )
from custom_components.poollab import DOMAIN, PoolLabCoordinator
from custom_components.poollab import PoolLabCoordinator
from custom_components.poollab.poollab import PoolLabApi
import pytest

from homeassistant import config_entries
from homeassistant.const import ATTR_NAME

# from homeassistant.components import sensor
# from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback

NAME = "My balancer"

CONF_ENTRY = config_entries.ConfigEntry(
data={
ATTR_NAME: NAME,
"api_key": 5,
},
options={},
domain=DOMAIN,
version=1,
minor_version=0,
source="user",
title=NAME,
unique_id="123456",
discovery_keys=None,
)


@pytest.mark.asyncio
async def test_coordinator_init(hass):
"""Test the coordinator initialization."""

coordinator = PoolLabCoordinator(hass, PoolLabApi("API_TOKEN"))
"""Initialize the coordinator with its API and name."""
api = PoolLabApi("API_TOKEN")
coordinator = PoolLabCoordinator(hass, api)

# assert coordinator.name == NAME
assert coordinator.api is api
assert coordinator.name == "PoolLab API"
Loading