Generic Commit; Most likely a fix or small feature

This commit is contained in:
Darius
2025-11-17 23:35:09 +01:00
parent 89355bab8b
commit e8161935b1
15 changed files with 477 additions and 5 deletions

View File

@@ -1,2 +1,4 @@
export * from "./homeassistant";
export * as Logger from "./logger";
export * from "./tidal";
export * as Utility from "./utility";

17
src/logger.ts Normal file
View File

@@ -0,0 +1,17 @@
import chalk from "chalk";
export function logError(...args: unknown[]) {
console.error(chalk.red("ERROR:"), ...args);
}
export function logWarning(...args: unknown[]) {
console.warn(chalk.yellow("WARNING:"), ...args);
}
export function logSuccess(...args: unknown[]) {
console.info(chalk.green("SUCCESS:"), ...args);
}
export function logInfo(...args: unknown[]) {
console.info(chalk.cyan("INFO:"), ...args);
}

40
src/utility.ts Normal file
View File

@@ -0,0 +1,40 @@
import axios from "axios";
import { logError } from "./logger";
export function secondsToReadable(
secs: number,
roundToMinutes: boolean = false,
): string {
const totalSeconds = roundToMinutes ? Math.round(secs / 60) * 60 : secs;
var days = Math.floor(totalSeconds / (3600 * 24));
var hours = Math.floor((totalSeconds % (3600 * 24)) / 3600);
var minutes = Math.floor((totalSeconds % 3600) / 60);
var seconds = Math.floor(totalSeconds % 60);
var dayDisplay = days > 0 ? days + (days === 1 ? " day, " : " days, ") : "";
var hourDisplay =
hours > 0 ? hours + (hours === 1 ? " hour, " : " hours, ") : "";
var minuteDisplay =
minutes > 0 ? minutes + (minutes === 1 ? " minute, " : " minutes, ") : "";
var secondDisplay =
seconds > 0 ? seconds + (seconds === 1 ? " second" : " seconds") : "";
return (dayDisplay + hourDisplay + minuteDisplay + secondDisplay).replace(
/,\s*$/,
"",
);
}
export function printNetworkError(error: unknown) {
if (axios.isAxiosError(error)) {
logError("Axios error details:", {
message: error.message,
status: error.response?.status,
statusText: error.response?.statusText,
data: error.response?.data,
url: error.config?.url,
});
} else {
logError("Unexpected error:", error);
}
}