feat(zones): rename tabs to zones across api, ui, and storage

Made-with: Cursor
This commit is contained in:
pi
2026-04-06 18:22:03 +12:00
parent d1ffb857c8
commit fd618d7714
35 changed files with 1347 additions and 1303 deletions

View File

@@ -10,7 +10,7 @@ from test_preset import test_preset
from test_profile import test_profile
from test_group import test_group
from test_sequence import test_sequence
from test_tab import test_tab
from test_zone import test_zone
from test_palette import test_palette
from test_device import test_device
@@ -26,7 +26,7 @@ def run_all_tests():
("Profile", test_profile),
("Group", test_group),
("Sequence", test_sequence),
("Tab", test_tab),
("Zone", test_zone),
("Palette", test_palette),
("Device", test_device),
]

View File

@@ -36,7 +36,7 @@ def test_device():
mac = "aabbccddeeff"
print("Testing create device")
device_id = devices.create("Test Device", address="aa:bb:cc:dd:ee:ff", default_pattern="on", tabs=["1", "2"])
device_id = devices.create("Test Device", address="aa:bb:cc:dd:ee:ff", default_pattern="on", zones=["1", "2"])
print(f"Created device with ID: {device_id}")
assert device_id == mac
assert device_id in devices
@@ -51,7 +51,7 @@ def test_device():
assert device["transport"] == "espnow"
assert device["address"] == mac
assert device["default_pattern"] == "on"
assert device["tabs"] == ["1", "2"]
assert device["zones"] == ["1", "2"]
print("\nTesting read by colon MAC")
assert devices.read("aa:bb:cc:dd:ee:ff")["id"] == mac
@@ -65,14 +65,14 @@ def test_device():
update_data = {
"name": "Updated Device",
"default_pattern": "rainbow",
"tabs": ["1", "2", "3"],
"zones": ["1", "2", "3"],
}
result = devices.update(device_id, update_data)
assert result is True
updated = devices.read(device_id)
assert updated["name"] == "Updated Device"
assert updated["default_pattern"] == "rainbow"
assert len(updated["tabs"]) == 3
assert len(updated["zones"]) == 3
print("\nTesting list devices")
device_list = devices.list()

View File

@@ -3,7 +3,7 @@ import os
def test_profile():
"""Test Profile model CRUD operations.
Profile create() sets name, type, tabs (list of tab IDs), scenes, palette_id.
Profile create() sets name, type, zones (list of zone IDs), scenes, palette_id.
"""
# Clean up any existing test file (model uses db/profile.json from project root)
db_dir = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), "db")
@@ -24,20 +24,20 @@ def test_profile():
print(f"Read: {profile}")
assert profile is not None
assert profile["name"] == "test_profile"
assert "tabs" in profile
assert "zones" in profile
assert "palette_id" in profile
assert "type" in profile
print("\nTesting update profile")
update_data = {
"name": "updated_profile",
"tabs": ["tab1"],
"zones": ["tab1"],
}
result = profiles.update(profile_id, update_data)
assert result is True
updated = profiles.read(profile_id)
assert updated["name"] == "updated_profile"
assert "tab1" in updated["tabs"]
assert "tab1" in updated["zones"]
print("\nTesting list profiles")
profile_list = profiles.list()

View File

@@ -1,57 +0,0 @@
from models.tab import Tab
import os
def test_tab():
"""Test Tab model CRUD operations."""
# Clean up any existing test file
if os.path.exists("Tab.json"):
os.remove("Tab.json")
tabs = Tab()
print("Testing create tab")
tab_id = tabs.create("test_tab", ["1", "2", "3"], ["preset1", "preset2"])
print(f"Created tab with ID: {tab_id}")
assert tab_id is not None
assert tab_id in tabs
print("\nTesting read tab")
tab = tabs.read(tab_id)
print(f"Read: {tab}")
assert tab is not None
assert tab["name"] == "test_tab"
assert len(tab["names"]) == 3
assert len(tab["presets"]) == 2
print("\nTesting update tab")
update_data = {
"name": "updated_tab",
"names": ["4", "5"],
"presets": ["preset3"]
}
result = tabs.update(tab_id, update_data)
assert result is True
updated = tabs.read(tab_id)
assert updated["name"] == "updated_tab"
assert len(updated["names"]) == 2
assert len(updated["presets"]) == 1
print("\nTesting list tabs")
tab_list = tabs.list()
print(f"Tab list: {tab_list}")
assert tab_id in tab_list
print("\nTesting delete tab")
deleted = tabs.delete(tab_id)
assert deleted is True
assert tab_id not in tabs
print("\nTesting read after delete")
tab = tabs.read(tab_id)
assert tab is None
print("\nAll tab tests passed!")
if __name__ == '__main__':
test_tab()

57
tests/models/test_zone.py Normal file
View File

@@ -0,0 +1,57 @@
from models.zone import Zone
import os
def test_zone():
"""Test Zone model CRUD operations."""
if os.path.exists("Zone.json"):
os.remove("Zone.json")
zones = Zone()
print("Testing create zone")
zone_id = zones.create("test_zone", ["1", "2", "3"], ["preset1", "preset2"])
print(f"Created zone with ID: {zone_id}")
assert zone_id is not None
assert zone_id in zones
print("\nTesting read zone")
zone = zones.read(zone_id)
print(f"Read: {zone}")
assert zone is not None
assert zone["name"] == "test_zone"
assert len(zone["names"]) == 3
assert len(zone["presets"]) == 2
print("\nTesting update zone")
update_data = {
"name": "updated_zone",
"names": ["4", "5"],
"presets": ["preset3"],
}
result = zones.update(zone_id, update_data)
assert result is True
updated = zones.read(zone_id)
assert updated["name"] == "updated_zone"
assert len(updated["names"]) == 2
assert len(updated["presets"]) == 1
print("\nTesting list zones")
zone_list = zones.list()
print(f"Zone list: {zone_list}")
assert zone_id in zone_list
print("\nTesting delete zone")
deleted = zones.delete(zone_id)
assert deleted is True
assert zone_id not in zones
print("\nTesting read after delete")
zone = zones.read(zone_id)
assert zone is None
print("\nAll zone tests passed!")
if __name__ == "__main__":
test_zone()