Compare commits

...

24 Commits

Author SHA1 Message Date
Darius
405ebe1e8e 1.9.4 2026-02-08 14:36:16 +01:00
Darius
1fb937973c add HA Update 2026-02-08 14:36:11 +01:00
Darius
9688c9581a 1.9.3 2026-02-08 12:52:36 +01:00
Darius
6b4bd73b14 build... 2026-02-08 12:52:31 +01:00
Darius
e834725b1a make stuff more refined 2026-02-08 12:52:19 +01:00
Darius
e6a7262cf7 1.9.2 2026-02-08 10:16:43 +01:00
Darius
850eb74210 forgot build 2026-02-08 10:16:38 +01:00
Darius
c1c5a41aa5 add format function and var => const 2026-02-08 10:16:10 +01:00
Darius
2b85020d52 1.9.1 2026-02-06 21:38:03 +01:00
Darius
493739238e changing types 2026-02-06 21:37:57 +01:00
Darius
7d96b3a82e 1.9.0 2026-02-06 21:35:30 +01:00
Darius
f49c868007 updatey 2026-02-06 21:35:25 +01:00
Darius
ff4248961b 1.8.4 2026-02-06 20:00:04 +01:00
Darius
fbc6916e2c update => data 2026-02-06 19:59:52 +01:00
Darius
934b287673 1.8.3 2026-02-06 19:55:12 +01:00
Darius
9f28e5eeb6 add component update 2026-02-06 19:55:07 +01:00
Darius
b2d4953fb6 1.8.2 2026-02-06 19:49:56 +01:00
Darius
ec4c9ec492 add grist record to fullinfo 2026-02-06 19:49:46 +01:00
Darius
27dc6f2b12 1.8.1 2026-02-06 17:18:10 +01:00
Darius
845dd30b43 forgot export 2026-02-06 17:18:04 +01:00
Darius
4509de76a2 1.8.0 2026-02-06 17:16:22 +01:00
Darius
4337372b38 add grist 2026-02-06 17:16:17 +01:00
Darius
cd95b63174 1.7.1 2026-02-06 11:14:00 +01:00
Darius
17e6b75ec5 WebSocket improt 2026-02-06 11:13:55 +01:00
28 changed files with 212 additions and 138 deletions

2
dist/fastify.d.ts vendored
View File

@@ -17,6 +17,6 @@ export declare abstract class BaseService<T> {
constructor(client: T);
getClient(): T;
getSuccessfulResult<R = unknown>(result: R): ServiceResult<R>;
getErrorResult(error: string): ServiceResult<string>;
getErrorResult(errorMessage: string, error?: unknown): ServiceResult<string>;
}
//# sourceMappingURL=fastify.d.ts.map

View File

@@ -1 +1 @@
{"version":3,"file":"fastify.d.ts","sourceRoot":"","sources":["../src/fastify.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAE3C,MAAM,MAAM,aAAa,CAAC,CAAC,GAAG,OAAO,IAAI;IACvC,MAAM,EAAE,CAAC,CAAC;IACV,UAAU,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF,qBAAa,SAAS;IACD,KAAK,EAAE,MAAM;gBAAb,KAAK,EAAE,MAAM;CACjC;AAED,8BAAsB,UAAU;IAC9B,OAAO,CAAC,aAAa,CAAgB;gBAEzB,aAAa,EAAE,aAAa;IAIxC,QAAQ,IAAI,aAAa;CAG1B;AAED,8BAAsB,WAAW,CAAC,CAAC;IACjC,OAAO,CAAC,MAAM,CAAI;gBAEN,MAAM,EAAE,CAAC;IAIrB,SAAS,IAAI,CAAC;IAId,mBAAmB,CAAC,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC;IAO7D,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC;CAMrD"}
{"version":3,"file":"fastify.d.ts","sourceRoot":"","sources":["../src/fastify.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAG3C,MAAM,MAAM,aAAa,CAAC,CAAC,GAAG,OAAO,IAAI;IACxC,MAAM,EAAE,CAAC,CAAC;IACV,UAAU,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,qBAAa,SAAS;IACF,KAAK,EAAE,MAAM;gBAAb,KAAK,EAAE,MAAM;CAChC;AAED,8BAAsB,UAAU;IAC/B,OAAO,CAAC,aAAa,CAAgB;gBAEzB,aAAa,EAAE,aAAa;IAIxC,QAAQ,IAAI,aAAa;CAGzB;AAED,8BAAsB,WAAW,CAAC,CAAC;IAClC,OAAO,CAAC,MAAM,CAAI;gBAEN,MAAM,EAAE,CAAC;IAIrB,SAAS,IAAI,CAAC;IAId,mBAAmB,CAAC,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC;IAO7D,cAAc,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC;CAO5E"}

6
dist/fastify.js vendored
View File

@@ -1,3 +1,4 @@
import { logWarning } from "./logger.js";
export class API_Error {
error;
constructor(error) {
@@ -27,9 +28,10 @@ export class BaseService {
successful: true,
};
}
getErrorResult(error) {
getErrorResult(errorMessage, error) {
logWarning(errorMessage);
return {
result: error,
result: errorMessage,
successful: false,
};
}

15
dist/grist.d.ts vendored Normal file
View File

@@ -0,0 +1,15 @@
export type GristRecord_PersonalGoals = {
went_outside: boolean;
standing: boolean;
standing_goal: number;
steps: boolean;
steps_goal: number;
pushups: boolean;
squats: boolean;
leg_raises: boolean;
reps_goal: number;
stairs: boolean;
stairs_goal: number;
is_workday: boolean;
};
//# sourceMappingURL=grist.d.ts.map

1
dist/grist.d.ts.map vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"grist.d.ts","sourceRoot":"","sources":["../src/grist.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,yBAAyB,GAAG;IACvC,YAAY,EAAE,OAAO,CAAC;IACtB,QAAQ,EAAE,OAAO,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,OAAO,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,OAAO,CAAC;IAChB,UAAU,EAAE,OAAO,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,OAAO,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,OAAO,CAAC;CACpB,CAAC"}

1
dist/grist.js vendored Normal file
View File

@@ -0,0 +1 @@
export {};

View File

@@ -21,13 +21,17 @@ export type HomeAssistantEntity = {
export interface HomeAssistantDeskPositionResult {
raw: HomeAssistantEntity;
as_boolean: boolean;
as_text: () => string;
last_changed: TimeBetween;
}
export type API_HA_DeskPosition = {
position: string;
is_standing: boolean;
last_changed: string;
last_changed_seconds: number;
};
export type HA_Update = {
entity_id: string;
state: string;
attributes: unknown;
timestamp: string;
};
//# sourceMappingURL=homeassistant.d.ts.map

View File

@@ -1 +1 @@
{"version":3,"file":"homeassistant.d.ts","sourceRoot":"","sources":["../src/homeassistant.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD,MAAM,MAAM,mBAAmB,GAAG;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE;QACX,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,mBAAmB,CAAC,EAAE,MAAM,CAAC;QAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACvB,CAAC;IACF,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE;QACR,EAAE,EAAE,MAAM,CAAC;QACX,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;QACzB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;KACvB,CAAC;CACF,CAAC;AAEF,MAAM,WAAW,+BAA+B;IAC/C,GAAG,EAAE,mBAAmB,CAAC;IACzB,UAAU,EAAE,OAAO,CAAC;IACpB,OAAO,EAAE,MAAM,MAAM,CAAC;IACtB,YAAY,EAAE,WAAW,CAAC;CAC1B;AAED,MAAM,MAAM,mBAAmB,GAAG;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,OAAO,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,oBAAoB,EAAE,MAAM,CAAC;CAC7B,CAAC"}
{"version":3,"file":"homeassistant.d.ts","sourceRoot":"","sources":["../src/homeassistant.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD,MAAM,MAAM,mBAAmB,GAAG;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE;QACX,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,mBAAmB,CAAC,EAAE,MAAM,CAAC;QAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACvB,CAAC;IACF,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE;QACR,EAAE,EAAE,MAAM,CAAC;QACX,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;QACzB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;KACvB,CAAC;CACF,CAAC;AAEF,MAAM,WAAW,+BAA+B;IAC/C,GAAG,EAAE,mBAAmB,CAAC;IACzB,UAAU,EAAE,OAAO,CAAC;IACpB,YAAY,EAAE,WAAW,CAAC;CAC1B;AAED,MAAM,MAAM,mBAAmB,GAAG;IACjC,WAAW,EAAE,OAAO,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,oBAAoB,EAAE,MAAM,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,OAAO,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;CAClB,CAAA"}

10
dist/homepage.d.ts vendored
View File

@@ -1,8 +1,14 @@
import { type API_HA_DeskPosition } from "./homeassistant";
import { type TidalGetCurrent } from "./tidal";
import type { GristRecord_PersonalGoals } from "./grist";
import type { API_HA_DeskPosition } from "./homeassistant";
import type { TidalGetCurrent } from "./tidal";
export type FullInformation = {
ha_desk_position: API_HA_DeskPosition | null;
ha_temp: string | null;
tidal_current: TidalGetCurrent | null;
grist_personal_goals: GristRecord_PersonalGoals | null;
};
export type ComponentUpdate = {
component: string;
data: unknown;
};
//# sourceMappingURL=homepage.d.ts.map

View File

@@ -1 +1 @@
{"version":3,"file":"homepage.d.ts","sourceRoot":"","sources":["../src/homepage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C,MAAM,MAAM,eAAe,GAAG;IAC7B,gBAAgB,EAAE,mBAAmB,GAAG,IAAI,CAAC;IAC7C,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,aAAa,EAAE,eAAe,GAAG,IAAI,CAAC;CACtC,CAAC"}
{"version":3,"file":"homepage.d.ts","sourceRoot":"","sources":["../src/homepage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAC;AACzD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C,MAAM,MAAM,eAAe,GAAG;IAC7B,gBAAgB,EAAE,mBAAmB,GAAG,IAAI,CAAC;IAC7C,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,aAAa,EAAE,eAAe,GAAG,IAAI,CAAC;IACtC,oBAAoB,EAAE,yBAAyB,GAAG,IAAI,CAAC;CACvD,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,OAAO,CAAC;CACd,CAAC"}

3
dist/index.d.ts vendored
View File

@@ -1,8 +1,9 @@
export * from "./fastify.js";
export * from "./grist.js";
export * from "./homeassistant.js";
export * from "./homepage.js";
export * from "./logger.js";
export * from "./ws.js";
export * from "./tidal.js";
export * from "./timehelper.js";
export * from "./ws.js";
//# sourceMappingURL=index.d.ts.map

2
dist/index.d.ts.map vendored
View File

@@ -1 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC"}
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,SAAS,CAAC"}

3
dist/index.js vendored
View File

@@ -1,7 +1,8 @@
export * from "./fastify.js";
export * from "./grist.js";
export * from "./homeassistant.js";
export * from "./homepage.js";
export * from "./logger.js";
export * from "./ws.js";
export * from "./tidal.js";
export * from "./timehelper.js";
export * from "./ws.js";

View File

@@ -11,5 +11,6 @@ export interface TimeBetween {
toReadable: (roundToMinutes?: boolean) => string;
}
export declare function calculateSecondsBetween(start: number, end: number): TimeBetween;
export declare function secondsToReadable(secs: number, roundToMinutes?: boolean): string;
export declare function formatSecondsToDHMS(secs: number, roundToMinutes?: boolean): string;
export declare function formatSecondsToMS(s: number): string;
//# sourceMappingURL=timehelper.d.ts.map

View File

@@ -1 +1 @@
{"version":3,"file":"timehelper.d.ts","sourceRoot":"","sources":["../src/timehelper.ts"],"names":[],"mappings":"AAAA,qBAAa,QAAQ;IACnB,OAAO,CAAC,KAAK,CAAqC;IAClD,OAAO,CAAC,GAAG,CAAqC;IAChD,OAAO,CAAC,QAAQ,CAAC;gBAEL,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;IAOjD,OAAO,CAAC,SAAS;IAKjB,QAAQ,CAAC,SAAS,GAAE,MAAmB,GAAG,OAAO;CAqBlD;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,CAAC,cAAc,CAAC,EAAE,OAAO,KAAK,MAAM,CAAC;CAClD;AAED,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,GACV,WAAW,CAOb;AAED,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,cAAc,GAAE,OAAe,GAC9B,MAAM,CAmBR"}
{"version":3,"file":"timehelper.d.ts","sourceRoot":"","sources":["../src/timehelper.ts"],"names":[],"mappings":"AAAA,qBAAa,QAAQ;IACpB,OAAO,CAAC,KAAK,CAAqC;IAClD,OAAO,CAAC,GAAG,CAAqC;IAChD,OAAO,CAAC,QAAQ,CAAC;gBAEL,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;IAOjD,OAAO,CAAC,SAAS;IAKjB,QAAQ,CAAC,SAAS,GAAE,MAAmB,GAAG,OAAO;CAqBjD;AAED,MAAM,WAAW,WAAW;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,CAAC,cAAc,CAAC,EAAE,OAAO,KAAK,MAAM,CAAC;CACjD;AAED,wBAAgB,uBAAuB,CACtC,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,GACT,WAAW,CAOb;AAED,wBAAgB,mBAAmB,CAClC,IAAI,EAAE,MAAM,EACZ,cAAc,GAAE,OAAe,GAC7B,MAAM,CAmBR;AAED,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAInD"}

25
dist/timehelper.js vendored
View File

@@ -36,18 +36,23 @@ export function calculateSecondsBetween(start, end) {
const seconds = Math.max(60, (end - start) / 1000);
return {
seconds,
toReadable: (roundToMinutes) => secondsToReadable(seconds, roundToMinutes),
toReadable: (roundToMinutes) => formatSecondsToDHMS(seconds, roundToMinutes),
};
}
export function secondsToReadable(secs, roundToMinutes = false) {
export function formatSecondsToDHMS(secs, roundToMinutes = false) {
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") : "";
const days = Math.floor(totalSeconds / (3600 * 24));
const hours = Math.floor((totalSeconds % (3600 * 24)) / 3600);
const minutes = Math.floor((totalSeconds % 3600) / 60);
const seconds = Math.floor(totalSeconds % 60);
const dayDisplay = days > 0 ? days + (days === 1 ? " day, " : " days, ") : "";
const hourDisplay = hours > 0 ? hours + (hours === 1 ? " hour, " : " hours, ") : "";
const minuteDisplay = minutes > 0 ? minutes + (minutes === 1 ? " minute, " : " minutes, ") : "";
const secondDisplay = seconds > 0 ? seconds + (seconds === 1 ? " second" : " seconds") : "";
return (dayDisplay + hourDisplay + minuteDisplay + secondDisplay).replace(/,\s*$/, "");
}
export function formatSecondsToMS(s) {
const mins = Math.floor(s / 60);
const secs = s % 60;
return `${mins}:${secs < 10 ? "0" : ""}${secs}`;
}

1
dist/ws.d.ts vendored
View File

@@ -1,3 +1,4 @@
import type { WebSocket } from "ws";
export type WsEvent = {
type: string;
data?: unknown;

2
dist/ws.d.ts.map vendored
View File

@@ -1 +1 @@
{"version":3,"file":"ws.d.ts","sourceRoot":"","sources":["../src/ws.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,OAAO,GAAG;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,OAAO,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;AAE/D,qBAAa,SAAS;IACrB,OAAO,CAAC,OAAO,CAA6B;IAC5C,OAAO,CAAC,SAAS,CAAgC;IAEjD,cAAc,CAAC,QAAQ,EAAE,sBAAsB,GAAG,MAAM,IAAI;IAO5D,OAAO,CAAC,gBAAgB;IAMxB,SAAS,CAAC,EAAE,EAAE,SAAS,GAAG,IAAI;IAM9B,YAAY,CAAC,EAAE,EAAE,SAAS,GAAG,IAAI;IAMjC,SAAS,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAMjC,cAAc,IAAI,MAAM;CAGxB"}
{"version":3,"file":"ws.d.ts","sourceRoot":"","sources":["../src/ws.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAGpC,MAAM,MAAM,OAAO,GAAG;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,OAAO,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;AAE/D,qBAAa,SAAS;IACrB,OAAO,CAAC,OAAO,CAA6B;IAC5C,OAAO,CAAC,SAAS,CAAgC;IAEjD,cAAc,CAAC,QAAQ,EAAE,sBAAsB,GAAG,MAAM,IAAI;IAO5D,OAAO,CAAC,gBAAgB;IAMxB,SAAS,CAAC,EAAE,EAAE,SAAS,GAAG,IAAI;IAM9B,YAAY,CAAC,EAAE,EAAE,SAAS,GAAG,IAAI;IAMjC,SAAS,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAMjC,cAAc,IAAI,MAAM;CAGxB"}

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "@dpu/shared",
"version": "1.7.0",
"version": "1.9.4",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@dpu/shared",
"version": "1.7.0",
"version": "1.9.4",
"dependencies": {
"@types/ws": "^8.18.1",
"axios": "^1.7.9",

View File

@@ -1,6 +1,6 @@
{
"name": "@dpu/shared",
"version": "1.7.0",
"version": "1.9.4",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",

View File

@@ -1,48 +1,50 @@
import type { AxiosInstance } from "axios";
import { logWarning } from "./logger.js";
export type ServiceResult<T = unknown> = {
result: T;
successful: boolean;
result: T;
successful: boolean;
};
export class API_Error {
constructor(public error: string) {}
constructor(public error: string) {}
}
export abstract class BaseClient {
private axiosInstance: AxiosInstance;
private axiosInstance: AxiosInstance;
constructor(axiosInstance: AxiosInstance) {
this.axiosInstance = axiosInstance;
}
constructor(axiosInstance: AxiosInstance) {
this.axiosInstance = axiosInstance;
}
getAxios(): AxiosInstance {
return this.axiosInstance;
}
getAxios(): AxiosInstance {
return this.axiosInstance;
}
}
export abstract class BaseService<T> {
private client: T;
private client: T;
constructor(client: T) {
this.client = client;
}
constructor(client: T) {
this.client = client;
}
getClient(): T {
return this.client;
}
getClient(): T {
return this.client;
}
getSuccessfulResult<R = unknown>(result: R): ServiceResult<R> {
return {
result,
successful: true,
};
}
getSuccessfulResult<R = unknown>(result: R): ServiceResult<R> {
return {
result,
successful: true,
};
}
getErrorResult(error: string): ServiceResult<string> {
return {
result: error,
successful: false,
};
}
getErrorResult(errorMessage: string, error?: unknown): ServiceResult<string> {
logWarning(errorMessage);
return {
result: errorMessage,
successful: false,
};
}
}

14
src/grist.ts Normal file
View File

@@ -0,0 +1,14 @@
export type GristRecord_PersonalGoals = {
went_outside: boolean;
standing: boolean;
standing_goal: number;
steps: boolean;
steps_goal: number;
pushups: boolean;
squats: boolean;
leg_raises: boolean;
reps_goal: number;
stairs: boolean;
stairs_goal: number;
is_workday: boolean;
};

View File

@@ -23,13 +23,18 @@ export type HomeAssistantEntity = {
export interface HomeAssistantDeskPositionResult {
raw: HomeAssistantEntity;
as_boolean: boolean;
as_text: () => string;
last_changed: TimeBetween;
}
export type API_HA_DeskPosition = {
position: string;
is_standing: boolean;
last_changed: string;
last_changed_seconds: number;
};
export type HA_Update = {
entity_id: string;
state: string;
attributes: unknown;
timestamp: string; // datetime string
}

View File

@@ -1,8 +1,15 @@
import { type API_HA_DeskPosition } from "./homeassistant";
import { type TidalGetCurrent } from "./tidal";
import type { GristRecord_PersonalGoals } from "./grist";
import type { API_HA_DeskPosition } from "./homeassistant";
import type { TidalGetCurrent } from "./tidal";
export type FullInformation = {
ha_desk_position: API_HA_DeskPosition | null;
ha_temp: string | null;
tidal_current: TidalGetCurrent | null;
grist_personal_goals: GristRecord_PersonalGoals | null;
};
export type ComponentUpdate = {
component: string;
data: unknown;
};

View File

@@ -1,7 +1,8 @@
export * from "./fastify.js";
export * from "./grist.js";
export * from "./homeassistant.js";
export * from "./homepage.js";
export * from "./logger.js";
export * from "./ws.js";
export * from "./tidal.js";
export * from "./timehelper.js";
export * from "./ws.js";

View File

@@ -2,31 +2,31 @@ import axios from "axios";
import chalk from "chalk";
export function logError(...args: unknown[]) {
console.error(chalk.red("ERROR:"), ...args);
console.error(chalk.red("ERROR:"), ...args);
}
export function logWarning(...args: unknown[]) {
console.warn(chalk.yellow("WARNING:"), ...args);
console.warn(chalk.yellow("WARNING:"), ...args);
}
export function logSuccess(...args: unknown[]) {
console.info(chalk.green("SUCCESS:"), ...args);
console.info(chalk.green("SUCCESS:"), ...args);
}
export function logInfo(...args: unknown[]) {
console.info(chalk.cyan("INFO:"), ...args);
console.info(chalk.cyan("INFO:"), ...args);
}
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);
}
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);
}
}

View File

@@ -1,80 +1,86 @@
export class TimeSpan {
private start: { hours: number; minutes: number };
private end: { hours: number; minutes: number };
private timeZone;
private start: { hours: number; minutes: number };
private end: { hours: number; minutes: number };
private timeZone;
constructor(timeSpanStr: string, timeZone: string) {
const [startStr, endStr] = timeSpanStr.split("-");
this.start = this.parseTime(startStr);
this.end = this.parseTime(endStr);
this.timeZone = timeZone;
}
constructor(timeSpanStr: string, timeZone: string) {
const [startStr, endStr] = timeSpanStr.split("-");
this.start = this.parseTime(startStr);
this.end = this.parseTime(endStr);
this.timeZone = timeZone;
}
private parseTime(timeStr: string) {
const [hours, minutes] = timeStr.split(":").map(Number);
return { hours, minutes };
}
private parseTime(timeStr: string) {
const [hours, minutes] = timeStr.split(":").map(Number);
return { hours, minutes };
}
contains(timestamp: number = Date.now()): boolean {
const date = new Date(timestamp);
contains(timestamp: number = Date.now()): boolean {
const date = new Date(timestamp);
const berlinTimeStr = date.toLocaleString("de-DE", {
timeZone: this.timeZone, // "Europe/Berlin"
hour12: false,
hour: "2-digit",
minute: "2-digit",
});
const berlinTimeStr = date.toLocaleString("de-DE", {
timeZone: this.timeZone, // "Europe/Berlin"
hour12: false,
hour: "2-digit",
minute: "2-digit",
});
const [hours, minutes] = berlinTimeStr.split(":").map(Number);
const currentMinutes = hours * 60 + minutes;
const startMinutes = this.start.hours * 60 + this.start.minutes;
const endMinutes = this.end.hours * 60 + this.end.minutes;
const [hours, minutes] = berlinTimeStr.split(":").map(Number);
const currentMinutes = hours * 60 + minutes;
const startMinutes = this.start.hours * 60 + this.start.minutes;
const endMinutes = this.end.hours * 60 + this.end.minutes;
if (startMinutes > endMinutes) {
return currentMinutes >= startMinutes || currentMinutes < endMinutes;
} else {
return currentMinutes >= startMinutes && currentMinutes < endMinutes;
}
}
if (startMinutes > endMinutes) {
return currentMinutes >= startMinutes || currentMinutes < endMinutes;
} else {
return currentMinutes >= startMinutes && currentMinutes < endMinutes;
}
}
}
export interface TimeBetween {
seconds: number;
toReadable: (roundToMinutes?: boolean) => string;
seconds: number;
toReadable: (roundToMinutes?: boolean) => string;
}
export function calculateSecondsBetween(
start: number,
end: number,
start: number,
end: number,
): TimeBetween {
const seconds = Math.max(60, (end - start) / 1000);
return {
seconds,
toReadable: (roundToMinutes?: boolean) =>
secondsToReadable(seconds, roundToMinutes),
};
const seconds = Math.max(60, (end - start) / 1000);
return {
seconds,
toReadable: (roundToMinutes?: boolean) =>
formatSecondsToDHMS(seconds, roundToMinutes),
};
}
export function secondsToReadable(
secs: number,
roundToMinutes: boolean = false,
export function formatSecondsToDHMS(
secs: number,
roundToMinutes: boolean = false,
): string {
const totalSeconds = roundToMinutes ? Math.round(secs / 60) * 60 : secs;
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);
const days = Math.floor(totalSeconds / (3600 * 24));
const hours = Math.floor((totalSeconds % (3600 * 24)) / 3600);
const minutes = Math.floor((totalSeconds % 3600) / 60);
const 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*$/,
"",
);
const dayDisplay = days > 0 ? days + (days === 1 ? " day, " : " days, ") : "";
const hourDisplay =
hours > 0 ? hours + (hours === 1 ? " hour, " : " hours, ") : "";
const minuteDisplay =
minutes > 0 ? minutes + (minutes === 1 ? " minute, " : " minutes, ") : "";
const secondDisplay =
seconds > 0 ? seconds + (seconds === 1 ? " second" : " seconds") : "";
return (dayDisplay + hourDisplay + minuteDisplay + secondDisplay).replace(
/,\s*$/,
"",
);
}
export function formatSecondsToMS(s: number): string {
const mins = Math.floor(s / 60);
const secs = s % 60;
return `${mins}:${secs < 10 ? "0" : ""}${secs}`;
}

View File

@@ -1,3 +1,4 @@
import type { WebSocket } from "ws";
import { logInfo } from "./logger.js";
export type WsEvent = {