feat: standardize device type for Sound Level Meters (SLM)

- Updated all instances of device_type from "sound_level_meter" to "slm" across the codebase.
- Enhanced documentation to reflect the new device type standardization.
- Added migration script to convert legacy device types in the database.
- Updated relevant API endpoints, models, and frontend templates to use the new device type.
- Ensured backward compatibility by deprecating the old device type without data loss.
This commit is contained in:
serversdwn
2026-01-16 18:31:27 +00:00
parent 6c7ce5aad0
commit 1ef0557ccb
22 changed files with 488 additions and 72 deletions

View File

@@ -31,7 +31,7 @@ class DeviceController:
Usage:
controller = DeviceController()
await controller.start_recording("nl43-001", "sound_level_meter", config={})
await controller.start_recording("nl43-001", "slm", config={})
await controller.stop_recording("seismo-042", "seismograph")
"""
@@ -53,7 +53,7 @@ class DeviceController:
Args:
unit_id: Unit identifier
device_type: "sound_level_meter" | "seismograph"
device_type: "slm" | "seismograph"
config: Device-specific recording configuration
Returns:
@@ -63,7 +63,7 @@ class DeviceController:
UnsupportedDeviceTypeError: Device type not supported
DeviceControllerError: Operation failed
"""
if device_type == "sound_level_meter":
if device_type == "slm":
try:
return await self.slmm_client.start_recording(unit_id, config)
except SLMMClientError as e:
@@ -81,7 +81,7 @@ class DeviceController:
else:
raise UnsupportedDeviceTypeError(
f"Device type '{device_type}' is not supported. "
f"Supported types: sound_level_meter, seismograph"
f"Supported types: slm, seismograph"
)
async def stop_recording(
@@ -94,12 +94,12 @@ class DeviceController:
Args:
unit_id: Unit identifier
device_type: "sound_level_meter" | "seismograph"
device_type: "slm" | "seismograph"
Returns:
Response dict from device module
"""
if device_type == "sound_level_meter":
if device_type == "slm":
try:
return await self.slmm_client.stop_recording(unit_id)
except SLMMClientError as e:
@@ -126,12 +126,12 @@ class DeviceController:
Args:
unit_id: Unit identifier
device_type: "sound_level_meter" | "seismograph"
device_type: "slm" | "seismograph"
Returns:
Response dict from device module
"""
if device_type == "sound_level_meter":
if device_type == "slm":
try:
return await self.slmm_client.pause_recording(unit_id)
except SLMMClientError as e:
@@ -157,12 +157,12 @@ class DeviceController:
Args:
unit_id: Unit identifier
device_type: "sound_level_meter" | "seismograph"
device_type: "slm" | "seismograph"
Returns:
Response dict from device module
"""
if device_type == "sound_level_meter":
if device_type == "slm":
try:
return await self.slmm_client.resume_recording(unit_id)
except SLMMClientError as e:
@@ -192,12 +192,12 @@ class DeviceController:
Args:
unit_id: Unit identifier
device_type: "sound_level_meter" | "seismograph"
device_type: "slm" | "seismograph"
Returns:
Status dict from device module
"""
if device_type == "sound_level_meter":
if device_type == "slm":
try:
return await self.slmm_client.get_unit_status(unit_id)
except SLMMClientError as e:
@@ -224,12 +224,12 @@ class DeviceController:
Args:
unit_id: Unit identifier
device_type: "sound_level_meter" | "seismograph"
device_type: "slm" | "seismograph"
Returns:
Live data dict from device module
"""
if device_type == "sound_level_meter":
if device_type == "slm":
try:
return await self.slmm_client.get_live_data(unit_id)
except SLMMClientError as e:
@@ -261,14 +261,14 @@ class DeviceController:
Args:
unit_id: Unit identifier
device_type: "sound_level_meter" | "seismograph"
device_type: "slm" | "seismograph"
destination_path: Local path to save files
files: List of filenames, or None for all
Returns:
Download result with file list
"""
if device_type == "sound_level_meter":
if device_type == "slm":
try:
return await self.slmm_client.download_files(
unit_id,
@@ -304,13 +304,13 @@ class DeviceController:
Args:
unit_id: Unit identifier
device_type: "sound_level_meter" | "seismograph"
device_type: "slm" | "seismograph"
config: Configuration parameters
Returns:
Updated config from device module
"""
if device_type == "sound_level_meter":
if device_type == "slm":
try:
return await self.slmm_client.update_unit_config(
unit_id,
@@ -347,12 +347,12 @@ class DeviceController:
Args:
unit_id: Unit identifier
device_type: "sound_level_meter" | "seismograph"
device_type: "slm" | "seismograph"
Returns:
True if device is reachable, False otherwise
"""
if device_type == "sound_level_meter":
if device_type == "slm":
try:
status = await self.slmm_client.get_unit_status(unit_id)
return status.get("last_seen") is not None

View File

@@ -207,7 +207,7 @@ class SchedulerService:
project_id=action.project_id,
location_id=action.location_id,
unit_id=unit_id,
session_type="sound" if action.device_type == "sound_level_meter" else "vibration",
session_type="sound" if action.device_type == "slm" else "vibration",
started_at=datetime.utcnow(),
status="recording",
session_metadata=json.dumps({"scheduled_action_id": action.id}),
@@ -272,7 +272,7 @@ class SchedulerService:
# Build destination path
# Example: data/Projects/{project-id}/sound/{location-name}/session-{timestamp}/
session_timestamp = datetime.utcnow().strftime("%Y-%m-%d-%H%M")
location_type_dir = "sound" if action.device_type == "sound_level_meter" else "vibration"
location_type_dir = "sound" if action.device_type == "slm" else "vibration"
destination_path = (
f"data/Projects/{project.id}/{location_type_dir}/"