Initial commit: Main Gate Controller HACS integration
Tests / pytest + ruff (3.12) (push) Has been cancelled
Validate / HACS validation (push) Has been cancelled
Validate / Hassfest validation (push) Has been cancelled

This commit is contained in:
bot
2026-09-07 23:19:12 +02:00
commit 988a30cbf7
27 changed files with 2456 additions and 0 deletions
+76
View File
@@ -0,0 +1,76 @@
"""Tests for the countdown phase of the cycle."""
from __future__ import annotations
import asyncio
from homeassistant.core import HomeAssistant
from pytest_homeassistant_custom_component.common import MockConfigEntry
from custom_components.main_gate_controller.const import (
ATTR_DURATION,
ATTR_REMAINING_SECONDS,
ATTR_RUNNING,
DOMAIN,
GATE_STATE_OPEN,
)
from tests.conftest import make_entry_data
async def test_countdown_attributes_decrease(hass: HomeAssistant, service_calls):
"""remaining_seconds decreases over the open phase and finishes at zero."""
switch = "switch.fast_gate_relay"
hass.states.async_set(switch, "off")
entry = MockConfigEntry(
domain=DOMAIN,
title="Main Gate",
data=make_entry_data(
switch_entity_id=switch,
name="Main Gate",
open_duration=2,
pulse_duration=0.1,
notify_enabled=False,
notify_entities=[],
),
unique_id=switch,
)
entry.add_to_hass(hass)
assert await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
controller = entry.runtime_data
# Manually step into the open phase and capture attribute changes.
assert controller.async_trigger() is True
# Wait until the cycle is in the ``open`` state.
while controller.status != GATE_STATE_OPEN:
await asyncio.sleep(0.05)
snapshot1 = controller.extra_state_attributes.copy()
assert snapshot1[ATTR_DURATION] == 2
assert snapshot1[ATTR_RUNNING] is True
first_remaining = snapshot1[ATTR_REMAINING_SECONDS]
assert first_remaining is not None and first_remaining >= 1
# Let the countdown progress for ~1 second before re-checking.
await asyncio.sleep(1.0)
snapshot2 = controller.extra_state_attributes.copy()
assert snapshot2[ATTR_REMAINING_SECONDS] < first_remaining
assert snapshot2[ATTR_RUNNING] is True
# Wait for completion.
await controller.async_wait_until_idle()
after = controller.extra_state_attributes
assert after[ATTR_RUNNING] is False
assert after[ATTR_REMAINING_SECONDS] is None
async def test_duration_reflects_configured_value(
hass: HomeAssistant, loaded_entry
):
"""The ``duration`` attribute follows the configuration value."""
controller = loaded_entry.runtime_data
attrs = controller.extra_state_attributes
assert attrs[ATTR_DURATION] == 20