wren's model answers "turn off all lights" with one call, and at 0.98 a
living room light switched on. The node now applies such a command to every
wired target of the kind. Number words become digits ("in five minutes"
lost its delay), aliases put the house's words and known mishearings in the
model's, and sensors.temperature is answered from <area>_temperature or
outdoor. tts writes out units and clock times before speaking.
58 lines
1.4 KiB
Python
58 lines
1.4 KiB
Python
from collections.abc import Generator
|
|
from dataclasses import dataclass
|
|
from typing import Any
|
|
|
|
import pytest
|
|
|
|
|
|
@pytest.fixture(scope="session", autouse=True)
|
|
def db() -> Generator[None, None, None]:
|
|
"""The engine holds no database state, so these tests need no database."""
|
|
yield
|
|
|
|
|
|
@dataclass
|
|
class _Device:
|
|
kind: str
|
|
id: str
|
|
state: str
|
|
|
|
|
|
@dataclass
|
|
class _House:
|
|
time: str
|
|
outdoor_c: float
|
|
dark: bool
|
|
user_area: str | None
|
|
areas: dict[str, list[_Device]]
|
|
|
|
|
|
class FakeWren:
|
|
"""The model package's surface, answering whatever a test sets ``answer`` to."""
|
|
|
|
AREAS = [
|
|
*("living room", "kitchen", "bathroom", "bedroom", "office"),
|
|
*("garden", "patio", "garage", "driveway", "balcony"),
|
|
]
|
|
KINDS = ["light", "media", "heat", "shutter", "water"]
|
|
Device = _Device
|
|
House = _House
|
|
|
|
def __init__(self) -> None:
|
|
self.answer: tuple[list[Any], float] = ([], 1.0)
|
|
self.houses: list[_House] = []
|
|
self.commands: list[str] = []
|
|
|
|
def act(self, command: str, house: _House) -> tuple[list[Any], float]:
|
|
self.houses.append(house)
|
|
self.commands.append(command)
|
|
return self.answer
|
|
|
|
|
|
@pytest.fixture
|
|
def fake_wren(monkeypatch: pytest.MonkeyPatch) -> FakeWren:
|
|
"""Stands in for the optional model package the wren node imports."""
|
|
fake = FakeWren()
|
|
monkeypatch.setattr("fluksio.flow.nodes.wren._wren", lambda: fake)
|
|
return fake
|