66 lines
1.5 KiB
Python
66 lines
1.5 KiB
Python
"""Seed the IoT PreTester 4.6 Demo reference data."""
|
|
|
|
import os
|
|
|
|
import django
|
|
from django.db import transaction
|
|
|
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "IoTPreTester.settings")
|
|
django.setup()
|
|
|
|
from IoTAnalyzer.models import Device, DeviceType, Manufacturer, Product # noqa: E402
|
|
|
|
|
|
DEVICE_TYPES = (
|
|
"Camera",
|
|
"Smart Plug",
|
|
"Smart Bulb",
|
|
"Smart Switch",
|
|
"Robot Vacuum Cleaner",
|
|
"Smart Lock",
|
|
"Smart Controller",
|
|
"Sensor",
|
|
)
|
|
|
|
MANUFACTURERS = (
|
|
"Aqara",
|
|
"Dreame",
|
|
"DJI",
|
|
"IKEA",
|
|
"Nuki",
|
|
"Philips Hue",
|
|
"Roborock",
|
|
"Shelly",
|
|
"Sonoff",
|
|
"TP-Link",
|
|
"X-Sense",
|
|
)
|
|
|
|
|
|
@transaction.atomic
|
|
def populate_database() -> None:
|
|
"""Create stable reference rows and one sample device without duplicates."""
|
|
for name in DEVICE_TYPES:
|
|
DeviceType.objects.get_or_create(device_type=name)
|
|
|
|
for name in MANUFACTURERS:
|
|
Manufacturer.objects.get_or_create(name=name)
|
|
|
|
manufacturer = Manufacturer.objects.get(name="Shelly")
|
|
device_type = DeviceType.objects.get(device_type="Smart Controller")
|
|
product, _ = Product.objects.get_or_create(
|
|
manufacturer=manufacturer,
|
|
device_type=device_type,
|
|
product_name="1PM Gen3",
|
|
)
|
|
Device.objects.get_or_create(
|
|
product=product,
|
|
serial="DEMO-001",
|
|
defaults={"comment": "IoT PreTester 4.6 Demo sample device"},
|
|
)
|
|
print("Demo reference data synchronized")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
populate_database()
|