Initial commit: Shelly Manager with Textual CLI, Streamlit UI, and comprehensive .gitignore
Shelly device management app with mDNS/subnet discovery, inventory, configuration, and mass operations for Gen1/Gen2+ devices. Includes .gitignore excluding runtime data (device DB, user config), AI conversation history, build artifacts, and common Python/OS patterns.
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
"""Dashboard inventory statistics."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import UTC, datetime
|
||||
|
||||
from shelly_manager.core.models import ShellyDevice
|
||||
from shelly_manager.ui.dashboard_stats import compute_inventory_stats
|
||||
|
||||
|
||||
def _d(
|
||||
i: str,
|
||||
*,
|
||||
gen: int = 2,
|
||||
online: bool = True,
|
||||
auth: bool = False,
|
||||
model: str = "SNSW-001P16EU",
|
||||
caps: list[str] | None = None,
|
||||
tags: list[str] | None = None,
|
||||
) -> ShellyDevice:
|
||||
return ShellyDevice(
|
||||
id=i,
|
||||
name=None,
|
||||
mac=f"AA:BB:CC:DD:EE:{i[:2]}",
|
||||
ip=f"192.168.1.{i}",
|
||||
generation=gen, # type: ignore[arg-type]
|
||||
model=model,
|
||||
firmware="1",
|
||||
online=online,
|
||||
last_seen=datetime.now(UTC),
|
||||
capabilities=caps or [],
|
||||
status={"sys": {"restart_required": False}},
|
||||
settings={},
|
||||
tags=tags or [],
|
||||
auth_required=auth,
|
||||
)
|
||||
|
||||
|
||||
def test_compute_inventory_stats_empty() -> None:
|
||||
s = compute_inventory_stats([])
|
||||
assert s.total == 0
|
||||
assert s.online == 0
|
||||
|
||||
|
||||
def test_compute_inventory_stats_mix() -> None:
|
||||
devices = [
|
||||
_d("01", gen=1, online=True, model="SHSW-1"),
|
||||
_d("02", gen=2, online=False, tags=["floor1"]),
|
||||
_d("03", gen=3, caps=["switch", "meter"]),
|
||||
]
|
||||
s = compute_inventory_stats(devices)
|
||||
assert s.total == 3
|
||||
assert s.online == 2
|
||||
assert s.offline == 1
|
||||
assert s.gen1 == 1 and s.gen2 == 1 and s.gen3 == 1
|
||||
assert s.devices_with_tags == 1
|
||||
assert s.unique_tag_labels == 1
|
||||
assert len(s.top_models) >= 2
|
||||
Reference in New Issue
Block a user