fix: address code review findings from post-onboarding audit

- Add button platform (button.py + PLATFORMS) so oven/washer Start/Pause/Stop
  controls actually appear in HA
- Load DTLS cert chain from memory via _load_pem_chain(); eliminate all temp
  file writes for key material in config_flow and coordinator
- Fix PEM boundary: ensure leaf and CA blocks are separated by a newline in
  the stored fullchain regardless of whether the user pasted a trailing newline
- Dryer mode select: add static options tuple and value_fn to decode Course_XX
  hex strings back to human names; was permanently empty before
- Remove callable branch from LocalThingsSelect (options_field covers dynamic
  case; callable contract was broken — called with no args vs Callable[[dict]])
- Guard native_min/max_value overrides with hasattr + super() fallback to
  prevent AttributeError when native_min=None and range_field returns nothing
- Add async_close() public method to coordinator; __init__ now calls it instead
  of reaching in to _close_session directly
- Update tests: rename CONF_CERT_PEM/KEY_PEM → CA/LEAF variants, add
  leaf_cert_pem/leaf_key_pem to mock_probe return, fix mock PEM constants
  (no trailing newlines, matching what .strip() stores)
This commit is contained in:
Marc Billow committed 2026-06-30 16:34:39 -05:00
1 parent f25e616950
commit 57cf1cdd11
11 files changed
+176 -120

No files matched your search

+13 -13
View File
@@ -9,27 +9,27 @@ from homeassistant.data_entry_flow import FlowResultType
from pytest_homeassistant_custom_component.common import MockConfigEntry
from custom_components.localthings.const import (
CONF_CERT_PEM, CONF_HOST, CONF_KEY_PEM, CONF_PORT, DOMAIN,
CONF_CA_CERT_PEM, CONF_CA_KEY_PEM, CONF_HOST, CONF_PORT, DOMAIN,
)
from .conftest import (
ENTRY_DATA, MOCK_CERT_PEM, MOCK_HOST, MOCK_KEY_PEM, MOCK_PORT, MOCK_SERIAL,
ENTRY_DATA, MOCK_CA_CERT_PEM, MOCK_CA_KEY_PEM, MOCK_HOST, MOCK_PORT, MOCK_SERIAL,
)
async def test_form_first_device(hass: HomeAssistant) -> None:
"""First device: form asks for host, cert, and key."""
"""First device: form asks for host, CA cert, and CA key."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={'source': 'user'}
)
assert result['type'] == FlowResultType.FORM
assert result['step_id'] == 'user'
assert CONF_CERT_PEM in result['data_schema'].schema
assert CONF_KEY_PEM in result['data_schema'].schema
assert CONF_CA_CERT_PEM in result['data_schema'].schema
assert CONF_CA_KEY_PEM in result['data_schema'].schema
async def test_form_second_device_reuses_creds(hass: HomeAssistant) -> None:
"""Second device: form only asks for host; cert/key schema fields absent."""
"""Second device: form only asks for host; CA cert/key schema fields absent."""
existing = MockConfigEntry(domain=DOMAIN, data=ENTRY_DATA)
existing.add_to_hass(hass)
@@ -37,8 +37,8 @@ async def test_form_second_device_reuses_creds(hass: HomeAssistant) -> None:
DOMAIN, context={'source': 'user'}
)
assert result['type'] == FlowResultType.FORM
assert CONF_CERT_PEM not in result['data_schema'].schema
assert CONF_KEY_PEM not in result['data_schema'].schema
assert CONF_CA_CERT_PEM not in result['data_schema'].schema
assert CONF_CA_KEY_PEM not in result['data_schema'].schema
async def test_successful_setup(hass: HomeAssistant, mock_probe) -> None:
@@ -48,12 +48,12 @@ async def test_successful_setup(hass: HomeAssistant, mock_probe) -> None:
)
result = await hass.config_entries.flow.async_configure(
result['flow_id'],
{CONF_HOST: MOCK_HOST, CONF_CERT_PEM: MOCK_CERT_PEM, CONF_KEY_PEM: MOCK_KEY_PEM},
{CONF_HOST: MOCK_HOST, CONF_CA_CERT_PEM: MOCK_CA_CERT_PEM, CONF_CA_KEY_PEM: MOCK_CA_KEY_PEM},
)
assert result['type'] == FlowResultType.CREATE_ENTRY
assert result['data'][CONF_HOST] == MOCK_HOST
assert result['data'][CONF_PORT] == MOCK_PORT
assert result['data'][CONF_CERT_PEM] == MOCK_CERT_PEM
assert result['data'][CONF_CA_CERT_PEM] == MOCK_CA_CERT_PEM
async def test_cannot_connect(hass: HomeAssistant) -> None:
@@ -69,7 +69,7 @@ async def test_cannot_connect(hass: HomeAssistant) -> None:
)
result = await hass.config_entries.flow.async_configure(
result['flow_id'],
{CONF_HOST: MOCK_HOST, CONF_CERT_PEM: MOCK_CERT_PEM, CONF_KEY_PEM: MOCK_KEY_PEM},
{CONF_HOST: MOCK_HOST, CONF_CA_CERT_PEM: MOCK_CA_CERT_PEM, CONF_CA_KEY_PEM: MOCK_CA_KEY_PEM},
)
assert result['type'] == FlowResultType.FORM
assert result['errors']['base'] == 'cannot_connect'
@@ -78,7 +78,7 @@ async def test_cannot_connect(hass: HomeAssistant) -> None:
async def test_duplicate_device_aborted(hass: HomeAssistant, mock_probe) -> None:
"""Second add of same serial: flow aborts.
When a device already exists the form only asks for host (cert/key are
When a device already exists the form only asks for host (CA creds are
reused), so we only submit CONF_HOST in the second configure call.
"""
existing = MockConfigEntry(
@@ -91,7 +91,7 @@ async def test_duplicate_device_aborted(hass: HomeAssistant, mock_probe) -> None
result = await hass.config_entries.flow.async_init(
DOMAIN, context={'source': 'user'}
)
# Second-device form only has CONF_HOST; cert/key are reused from existing.
# Second-device form only has CONF_HOST; CA creds are reused from existing.
result = await hass.config_entries.flow.async_configure(
result['flow_id'],
{CONF_HOST: MOCK_HOST},