wren node: targets from the wiring, on wren 2
Every output is a target and every input besides prompt a reading. A targets setting gives descriptions, values, ranges and per-target guards, model takes a trained pack's artifact digest, min_confidence defaults to the model's threshold. A command is applied whole or not at all, and targets the model was not trained on read degraded. The home path (area/kind ports, groups, brightness, temperature answers) is gone.
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
from collections.abc import Generator
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
@@ -12,40 +14,51 @@ def db() -> Generator[None, None, None]:
|
||||
|
||||
|
||||
@dataclass
|
||||
class _Device:
|
||||
kind: str
|
||||
id: str
|
||||
state: str
|
||||
class FakeTarget:
|
||||
name: str
|
||||
type: str
|
||||
value: Any
|
||||
values: list[str] | None = None
|
||||
range: list[float] | None = None
|
||||
description: str = ""
|
||||
unit: str | None = None
|
||||
readonly: bool = False
|
||||
|
||||
|
||||
@dataclass
|
||||
class _House:
|
||||
time: str
|
||||
outdoor_c: float
|
||||
dark: bool
|
||||
user_area: str | None
|
||||
areas: dict[str, list[_Device]]
|
||||
class FakeCall:
|
||||
target: str
|
||||
value: Any = None
|
||||
delay_s: float | None = None
|
||||
confidence: float = 1.0
|
||||
|
||||
|
||||
class FakeWren:
|
||||
"""The model package's surface, answering whatever a test sets ``answer`` to."""
|
||||
"""The model package's surface: ``act`` answers whatever a test sets
|
||||
``answer`` to, and ``load_pack`` returns ``pack``."""
|
||||
|
||||
AREAS = [
|
||||
*("living room", "kitchen", "bathroom", "bedroom", "office"),
|
||||
*("garden", "patio", "garage", "driveway", "balcony"),
|
||||
]
|
||||
KINDS = ["light", "media", "heat", "shutter", "water", "switch"]
|
||||
Device = _Device
|
||||
House = _House
|
||||
Target = FakeTarget
|
||||
Call = FakeCall
|
||||
runtime = SimpleNamespace(MODEL=Path("demo.bin"))
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.answer: tuple[list[Any], float] = ([], 1.0)
|
||||
self.houses: list[_House] = []
|
||||
self.answer: list[FakeCall] = []
|
||||
self.pack: dict[str, Any] = {"meta": {"threshold": 0.9, "targets": []}}
|
||||
self.loaded: list[Path] = []
|
||||
self.commands: list[str] = []
|
||||
self.targets: list[list[FakeTarget]] = []
|
||||
self.models: list[Any] = []
|
||||
|
||||
def act(self, command: str, house: _House) -> tuple[list[Any], float]:
|
||||
self.houses.append(house)
|
||||
def load_pack(self, path: Path) -> dict[str, Any]:
|
||||
self.loaded.append(path)
|
||||
return self.pack
|
||||
|
||||
def act(
|
||||
self, command: str, targets: list[FakeTarget], *, model: Any = None
|
||||
) -> list[FakeCall]:
|
||||
self.commands.append(command)
|
||||
self.targets.append(targets)
|
||||
self.models.append(model)
|
||||
return self.answer
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user