Skip to content

Commit e7eaeeb

Browse files
author
MrD3y5eL
committed
Added Parity Next Check Schedule attribute
1 parent a7ed169 commit e7eaeeb

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

custom_components/unraid/coordinator.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,78 @@ async def _async_update_data(self) -> Dict[str, Any]:
517517
# Don't let Docker errors affect other data
518518
data["docker_containers"] = []
519519
data["docker_stats"] = {"containers": {}, "summary": {}}
520+
521+
# Step 6 Add parity schedule parsing
522+
try:
523+
result = await self.api.execute_command(
524+
"cat /boot/config/plugins/dynamix/parity-check.cron"
525+
)
526+
next_check = "Unknown"
527+
528+
if result and result.exit_status == 0:
529+
_LOGGER.debug("Found parity check cron: %s", result.stdout)
530+
531+
# Parse the cron entries
532+
for line in result.stdout.splitlines():
533+
if "mdcmd check" in line and not line.startswith('#'):
534+
# Split the cron entry
535+
parts = line.strip().split()
536+
if len(parts) >= 5:
537+
minute, hour, dom, month, dow = parts[:5]
538+
539+
now = dt_util.now()
540+
next_run = None
541+
542+
# Parse based on the cron pattern
543+
if dom == "1" and month == "1": # Yearly on Jan 1st
544+
next_run = now.replace(
545+
month=1,
546+
day=1,
547+
hour=int(hour),
548+
minute=int(minute),
549+
second=0,
550+
microsecond=0
551+
)
552+
if next_run <= now:
553+
next_run = next_run.replace(year=next_run.year + 1)
554+
elif dom == "1" and month == "*": # Monthly on 1st
555+
next_run = now.replace(
556+
day=1,
557+
hour=int(hour),
558+
minute=int(minute),
559+
second=0,
560+
microsecond=0
561+
)
562+
if next_run <= now:
563+
if next_run.month == 12:
564+
next_run = next_run.replace(year=next_run.year + 1, month=1)
565+
else:
566+
next_run = next_run.replace(month=next_run.month + 1)
567+
568+
if next_run:
569+
# Format the date nicely
570+
if (next_run - now).days == 0:
571+
next_check = f"Today at {next_run.strftime('%H:%M')}"
572+
elif (next_run - now).days == 1:
573+
next_check = f"Tomorrow at {next_run.strftime('%H:%M')}"
574+
else:
575+
next_check = next_run.strftime("%b %d %Y at %H:%M")
576+
break
577+
578+
# If no cron schedule found, fall back to config file check
579+
if next_check == "Unknown":
580+
parity_config = data.get("disk_config", {})
581+
if not parity_config.get("parity.mode") == "4": # If not manual mode
582+
next_check = "Schedule configuration error"
583+
else:
584+
next_check = "Manual Only"
585+
586+
data["next_parity_check"] = next_check
587+
_LOGGER.debug("Set next parity check to: %s", next_check)
588+
589+
except Exception as err:
590+
_LOGGER.error("Error parsing parity schedule: %s", err)
591+
data["next_parity_check"] = "Unknown"
520592

521593
_LOGGER.debug("Data update complete. Keys collected: %s", list(data.keys()))
522594

custom_components/unraid/diagnostics/parity.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ def extra_state_attributes(self) -> dict[str, StateType]:
496496
"speed": "N/A",
497497
"errors": 0,
498498
"last_check": "N/A",
499+
"next_check": self.coordinator.data.get("next_parity_check", "Unknown"),
499500
"duration": "N/A",
500501
"last_status": "N/A"
501502
}
@@ -591,6 +592,7 @@ def extra_state_attributes(self) -> dict[str, StateType]:
591592
"speed": "N/A",
592593
"errors": 0,
593594
"last_check": "N/A",
595+
"next_check": "Unknown",
594596
"duration": "N/A",
595597
"last_status": "N/A"
596598
}

0 commit comments

Comments
 (0)