feat: NUT (Network UPS Tools) service provider + provider-agnostic UI
Add full NUT support as a polling-based service provider: - Async TCP client for upsd protocol (port 3493, configurable) - 8 event types: online, on_battery, low_battery, battery_restored, comms_lost, comms_restored, replace_battery, overload - 3 bot commands: /status, /devices, /battery - 38 Jinja2 templates (EN+RU notification + command templates) - Database: tracking config fields, migration, seeds - Frontend: provider form with host/port/credentials, grid items, i18n Provider-agnostic UI improvements: - Remove hardcoded 'immich' defaults from all config forms - Dynamic collection labels per provider type (Albums/Repos/Boards/UPS Devices) - Capability-driven test types instead of provider type checks - Template variable helpers for all providers (was Immich-only) - Guard Immich-only shared link check to Immich providers - Auto-clear stale global provider filter from localStorage - EntitySelect search placeholder shows current selection - Fix noneLabel in linked target config selectors New CLAUDE.md rule #8: no provider-specific hardcoding
This commit is contained in:
@@ -185,6 +185,41 @@ async def migrate_schema(engine: AsyncEngine) -> None:
|
||||
)
|
||||
logger.info("Added %s column to tracking_config table", col_name)
|
||||
|
||||
# Add NUT (UPS) tracking flags to tracking_config if missing
|
||||
if await _has_table(conn, "tracking_config"):
|
||||
nut_flags = [
|
||||
("track_ups_online", "INTEGER DEFAULT 1"),
|
||||
("track_ups_on_battery", "INTEGER DEFAULT 1"),
|
||||
("track_ups_low_battery", "INTEGER DEFAULT 1"),
|
||||
("track_ups_battery_restored", "INTEGER DEFAULT 1"),
|
||||
("track_ups_comms_lost", "INTEGER DEFAULT 1"),
|
||||
("track_ups_comms_restored", "INTEGER DEFAULT 1"),
|
||||
("track_ups_replace_battery", "INTEGER DEFAULT 1"),
|
||||
("track_ups_overload", "INTEGER DEFAULT 1"),
|
||||
]
|
||||
for col_name, col_type in nut_flags:
|
||||
if not await _has_column(conn, "tracking_config", col_name):
|
||||
await conn.execute(
|
||||
text(f"ALTER TABLE tracking_config ADD COLUMN {col_name} {col_type}")
|
||||
)
|
||||
logger.info("Added %s column to tracking_config table", col_name)
|
||||
|
||||
# Drop legacy template content columns from template_config
|
||||
# (template content moved to template_slot child rows)
|
||||
if await _has_table(conn, "template_config"):
|
||||
legacy_cols = [
|
||||
"message_assets_added", "message_assets_removed",
|
||||
"message_collection_renamed", "message_collection_deleted",
|
||||
"message_sharing_changed", "periodic_summary_message",
|
||||
"scheduled_assets_message", "memory_mode_message",
|
||||
]
|
||||
for col_name in legacy_cols:
|
||||
if await _has_column(conn, "template_config", col_name):
|
||||
await conn.execute(
|
||||
text(f"ALTER TABLE template_config DROP COLUMN {col_name}")
|
||||
)
|
||||
logger.info("Dropped legacy column %s from template_config", col_name)
|
||||
|
||||
# Add collection_name and shared to tracker_state if missing
|
||||
state_table = "notification_tracker_state" if await _has_table(conn, "notification_tracker_state") else "tracker_state"
|
||||
if await _has_table(conn, state_table):
|
||||
|
||||
@@ -150,6 +150,16 @@ class TrackingConfig(SQLModel, table=True):
|
||||
# Scheduler event tracking
|
||||
track_scheduled_message: bool = Field(default=True)
|
||||
|
||||
# NUT (UPS) event tracking
|
||||
track_ups_online: bool = Field(default=True)
|
||||
track_ups_on_battery: bool = Field(default=True)
|
||||
track_ups_low_battery: bool = Field(default=True)
|
||||
track_ups_battery_restored: bool = Field(default=True)
|
||||
track_ups_comms_lost: bool = Field(default=True)
|
||||
track_ups_comms_restored: bool = Field(default=True)
|
||||
track_ups_replace_battery: bool = Field(default=True)
|
||||
track_ups_overload: bool = Field(default=True)
|
||||
|
||||
# Immich asset display
|
||||
track_images: bool = Field(default=True)
|
||||
track_videos: bool = Field(default=True)
|
||||
|
||||
@@ -151,6 +151,7 @@ async def _seed_default_templates() -> None:
|
||||
await _seed_provider_template(session, "gitea", "Gitea")
|
||||
await _seed_provider_template(session, "planka", "Planka")
|
||||
await _seed_provider_template(session, "scheduler", "Scheduler")
|
||||
await _seed_provider_template(session, "nut", "NUT")
|
||||
await session.commit()
|
||||
|
||||
|
||||
@@ -171,6 +172,9 @@ async def _seed_default_command_templates() -> None:
|
||||
await _seed_provider_command_template(
|
||||
session, "planka", "Default Planka Commands", "Default Planka command templates",
|
||||
)
|
||||
await _seed_provider_command_template(
|
||||
session, "nut", "Default NUT Commands", "Default NUT command templates",
|
||||
)
|
||||
await session.commit()
|
||||
|
||||
|
||||
@@ -221,6 +225,18 @@ async def _seed_default_tracking_configs() -> None:
|
||||
"name": "Default Scheduler",
|
||||
"track_scheduled_message": True,
|
||||
},
|
||||
{
|
||||
"provider_type": "nut",
|
||||
"name": "Default NUT",
|
||||
"track_ups_online": True,
|
||||
"track_ups_on_battery": True,
|
||||
"track_ups_low_battery": True,
|
||||
"track_ups_battery_restored": True,
|
||||
"track_ups_comms_lost": True,
|
||||
"track_ups_comms_restored": True,
|
||||
"track_ups_replace_battery": True,
|
||||
"track_ups_overload": True,
|
||||
},
|
||||
]
|
||||
|
||||
for cfg in defaults:
|
||||
@@ -279,6 +295,16 @@ async def _seed_default_command_configs() -> None:
|
||||
"default_count": 10,
|
||||
"rate_limits": {"api": 15, "default": 10},
|
||||
},
|
||||
{
|
||||
"provider_type": "nut",
|
||||
"name": "Default NUT",
|
||||
"enabled_commands": [
|
||||
"help", "status", "devices", "battery",
|
||||
],
|
||||
"response_mode": "text",
|
||||
"default_count": 5,
|
||||
"rate_limits": {"api": 15, "default": 10},
|
||||
},
|
||||
]
|
||||
|
||||
for cfg in defaults:
|
||||
|
||||
Reference in New Issue
Block a user