Compare commits
30 Commits
27dc6f2b12
...
v1.9.9
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d73d98068a | ||
|
|
b305c2ab66 | ||
|
|
e3fbe3b178 | ||
|
|
4c46c5ae6d | ||
|
|
d416e8db07 | ||
|
|
aae0e0db9d | ||
|
|
9983ba1215 | ||
|
|
872d3755d0 | ||
|
|
6d5d34e6d2 | ||
|
|
4ed43fc8a0 | ||
|
|
78f5e4a313 | ||
|
|
e32afa0f70 | ||
|
|
405ebe1e8e | ||
|
|
1fb937973c | ||
|
|
9688c9581a | ||
|
|
6b4bd73b14 | ||
|
|
e834725b1a | ||
|
|
e6a7262cf7 | ||
|
|
850eb74210 | ||
|
|
c1c5a41aa5 | ||
|
|
2b85020d52 | ||
|
|
493739238e | ||
|
|
7d96b3a82e | ||
|
|
f49c868007 | ||
|
|
ff4248961b | ||
|
|
fbc6916e2c | ||
|
|
934b287673 | ||
|
|
9f28e5eeb6 | ||
|
|
b2d4953fb6 | ||
|
|
ec4c9ec492 |
2
dist/fastify.d.ts
vendored
2
dist/fastify.d.ts
vendored
@@ -17,6 +17,6 @@ export declare abstract class BaseService<T> {
|
|||||||
constructor(client: T);
|
constructor(client: T);
|
||||||
getClient(): T;
|
getClient(): T;
|
||||||
getSuccessfulResult<R = unknown>(result: R): ServiceResult<R>;
|
getSuccessfulResult<R = unknown>(result: R): ServiceResult<R>;
|
||||||
getErrorResult(error: string): ServiceResult<string>;
|
getErrorResult(errorMessage: string, error?: unknown): ServiceResult<string>;
|
||||||
}
|
}
|
||||||
//# sourceMappingURL=fastify.d.ts.map
|
//# sourceMappingURL=fastify.d.ts.map
|
||||||
2
dist/fastify.d.ts.map
vendored
2
dist/fastify.d.ts.map
vendored
@@ -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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AE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC;CAO5E"}
|
||||||
6
dist/fastify.js
vendored
6
dist/fastify.js
vendored
@@ -1,3 +1,4 @@
|
|||||||
|
import { logWarning } from "./logger.js";
|
||||||
export class API_Error {
|
export class API_Error {
|
||||||
error;
|
error;
|
||||||
constructor(error) {
|
constructor(error) {
|
||||||
@@ -27,9 +28,10 @@ export class BaseService {
|
|||||||
successful: true,
|
successful: true,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
getErrorResult(error) {
|
getErrorResult(errorMessage, error) {
|
||||||
|
logWarning(errorMessage, error);
|
||||||
return {
|
return {
|
||||||
result: error,
|
result: errorMessage,
|
||||||
successful: false,
|
successful: false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
20
dist/homeassistant.d.ts
vendored
20
dist/homeassistant.d.ts
vendored
@@ -10,9 +10,9 @@ export type HomeAssistantEntity = {
|
|||||||
[key: string]: unknown;
|
[key: string]: unknown;
|
||||||
};
|
};
|
||||||
last_changed: string;
|
last_changed: string;
|
||||||
last_reported: string;
|
last_reported?: string;
|
||||||
last_updated: string;
|
last_updated?: string;
|
||||||
context: {
|
context?: {
|
||||||
id: string;
|
id: string;
|
||||||
parent_id: string | null;
|
parent_id: string | null;
|
||||||
user_id: string | null;
|
user_id: string | null;
|
||||||
@@ -21,13 +21,23 @@ export type HomeAssistantEntity = {
|
|||||||
export interface HomeAssistantDeskPositionResult {
|
export interface HomeAssistantDeskPositionResult {
|
||||||
raw: HomeAssistantEntity;
|
raw: HomeAssistantEntity;
|
||||||
as_boolean: boolean;
|
as_boolean: boolean;
|
||||||
as_text: () => string;
|
|
||||||
last_changed: TimeBetween;
|
last_changed: TimeBetween;
|
||||||
}
|
}
|
||||||
export type API_HA_DeskPosition = {
|
export type API_HA_DeskPosition = {
|
||||||
position: string;
|
|
||||||
is_standing: boolean;
|
is_standing: boolean;
|
||||||
last_changed: string;
|
last_changed: string;
|
||||||
last_changed_seconds: number;
|
last_changed_seconds: number;
|
||||||
};
|
};
|
||||||
|
export type HA_Update = {
|
||||||
|
entity_id: string;
|
||||||
|
state: string;
|
||||||
|
attributes: {
|
||||||
|
state_class?: string;
|
||||||
|
unit_of_measurement?: string;
|
||||||
|
icon?: string;
|
||||||
|
friendly_name?: string;
|
||||||
|
[key: string]: unknown;
|
||||||
|
};
|
||||||
|
timestamp: string;
|
||||||
|
};
|
||||||
//# sourceMappingURL=homeassistant.d.ts.map
|
//# sourceMappingURL=homeassistant.d.ts.map
|
||||||
2
dist/homeassistant.d.ts.map
vendored
2
dist/homeassistant.d.ts.map
vendored
@@ -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,M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E,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,SAAS,EAAE,MAAM,CAAC;CAClB,CAAC"}
|
||||||
5
dist/homepage.d.ts
vendored
5
dist/homepage.d.ts
vendored
@@ -1,8 +1,11 @@
|
|||||||
|
import type { GristRecord_PersonalGoals } from "./grist";
|
||||||
import type { API_HA_DeskPosition } from "./homeassistant";
|
import type { API_HA_DeskPosition } from "./homeassistant";
|
||||||
|
import type { StatusComponentName } from "./status";
|
||||||
import type { TidalGetCurrent } from "./tidal";
|
import type { TidalGetCurrent } from "./tidal";
|
||||||
export type FullInformation = {
|
export type FullInformation = Record<StatusComponentName, unknown> & {
|
||||||
ha_desk_position: API_HA_DeskPosition | null;
|
ha_desk_position: API_HA_DeskPosition | null;
|
||||||
ha_temp: string | null;
|
ha_temp: string | null;
|
||||||
tidal_current: TidalGetCurrent | null;
|
tidal_current: TidalGetCurrent | null;
|
||||||
|
grist_personal_goals: GristRecord_PersonalGoals | null;
|
||||||
};
|
};
|
||||||
//# sourceMappingURL=homepage.d.ts.map
|
//# sourceMappingURL=homepage.d.ts.map
|
||||||
2
dist/homepage.d.ts.map
vendored
2
dist/homepage.d.ts.map
vendored
@@ -1 +1 @@
|
|||||||
{"version":3,"file":"homepage.d.ts","sourceRoot":"","sources":["../src/homepage.ts"],"names":[],"mappings":"AAAA,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;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,mBAAmB,EAAE,MAAM,UAAU,CAAC;AACpD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,mBAAmB,EAAE,OAAO,CAAC,GAAG;IACpE,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"}
|
||||||
1
dist/index.d.ts
vendored
1
dist/index.d.ts
vendored
@@ -3,6 +3,7 @@ export * from "./grist.js";
|
|||||||
export * from "./homeassistant.js";
|
export * from "./homeassistant.js";
|
||||||
export * from "./homepage.js";
|
export * from "./homepage.js";
|
||||||
export * from "./logger.js";
|
export * from "./logger.js";
|
||||||
|
export * from "./status.js";
|
||||||
export * from "./tidal.js";
|
export * from "./tidal.js";
|
||||||
export * from "./timehelper.js";
|
export * from "./timehelper.js";
|
||||||
export * from "./ws.js";
|
export * from "./ws.js";
|
||||||
|
|||||||
2
dist/index.d.ts.map
vendored
2
dist/index.d.ts.map
vendored
@@ -1 +1 @@
|
|||||||
{"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"}
|
{"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,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,SAAS,CAAC"}
|
||||||
1
dist/index.js
vendored
1
dist/index.js
vendored
@@ -3,6 +3,7 @@ export * from "./grist.js";
|
|||||||
export * from "./homeassistant.js";
|
export * from "./homeassistant.js";
|
||||||
export * from "./homepage.js";
|
export * from "./homepage.js";
|
||||||
export * from "./logger.js";
|
export * from "./logger.js";
|
||||||
|
export * from "./status.js";
|
||||||
export * from "./tidal.js";
|
export * from "./tidal.js";
|
||||||
export * from "./timehelper.js";
|
export * from "./timehelper.js";
|
||||||
export * from "./ws.js";
|
export * from "./ws.js";
|
||||||
|
|||||||
16
dist/status.d.ts
vendored
Normal file
16
dist/status.d.ts
vendored
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
export declare const StatusComponent: {
|
||||||
|
readonly HA_DESK_POSITION: "ha_desk_position";
|
||||||
|
readonly HA_TEMP: "ha_temp";
|
||||||
|
readonly TIDAL_CURRENT: "tidal_current";
|
||||||
|
readonly GRIST_PERSONAL_GOALS: "grist_personal_goals";
|
||||||
|
};
|
||||||
|
export type StatusComponentName = (typeof StatusComponent)[keyof typeof StatusComponent];
|
||||||
|
export type ComponentUpdate = {
|
||||||
|
component: StatusComponentName;
|
||||||
|
data: unknown;
|
||||||
|
};
|
||||||
|
export declare function createComponentUpdate(component: StatusComponentName, data: unknown): {
|
||||||
|
component: StatusComponentName;
|
||||||
|
data: unknown;
|
||||||
|
};
|
||||||
|
//# sourceMappingURL=status.d.ts.map
|
||||||
1
dist/status.d.ts.map
vendored
Normal file
1
dist/status.d.ts.map
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../src/status.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe;;;;;CAKlB,CAAC;AAEX,MAAM,MAAM,mBAAmB,GAC9B,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,OAAO,eAAe,CAAC,CAAC;AAExD,MAAM,MAAM,eAAe,GAAG;IAC7B,SAAS,EAAE,mBAAmB,CAAC;IAC/B,IAAI,EAAE,OAAO,CAAC;CACd,CAAC;AAEF,wBAAgB,qBAAqB,CACpC,SAAS,EAAE,mBAAmB,EAC9B,IAAI,EAAE,OAAO;;;EAMb"}
|
||||||
12
dist/status.js
vendored
Normal file
12
dist/status.js
vendored
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
export const StatusComponent = {
|
||||||
|
HA_DESK_POSITION: "ha_desk_position",
|
||||||
|
HA_TEMP: "ha_temp",
|
||||||
|
TIDAL_CURRENT: "tidal_current",
|
||||||
|
GRIST_PERSONAL_GOALS: "grist_personal_goals",
|
||||||
|
};
|
||||||
|
export function createComponentUpdate(component, data) {
|
||||||
|
return {
|
||||||
|
component: component,
|
||||||
|
data: data,
|
||||||
|
};
|
||||||
|
}
|
||||||
3
dist/timehelper.d.ts
vendored
3
dist/timehelper.d.ts
vendored
@@ -11,5 +11,6 @@ export interface TimeBetween {
|
|||||||
toReadable: (roundToMinutes?: boolean) => string;
|
toReadable: (roundToMinutes?: boolean) => string;
|
||||||
}
|
}
|
||||||
export declare function calculateSecondsBetween(start: number, end: number): TimeBetween;
|
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
|
//# sourceMappingURL=timehelper.d.ts.map
|
||||||
2
dist/timehelper.d.ts.map
vendored
2
dist/timehelper.d.ts.map
vendored
@@ -1 +1 @@
|
|||||||
{"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,iBAAiB,CAChC,IAAI,EAAE,MAAM,EACZ,cAAc,GAAE,OAAe,GAC7B,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
25
dist/timehelper.js
vendored
@@ -36,18 +36,23 @@ export function calculateSecondsBetween(start, end) {
|
|||||||
const seconds = Math.max(60, (end - start) / 1000);
|
const seconds = Math.max(60, (end - start) / 1000);
|
||||||
return {
|
return {
|
||||||
seconds,
|
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;
|
const totalSeconds = roundToMinutes ? Math.round(secs / 60) * 60 : secs;
|
||||||
var days = Math.floor(totalSeconds / (3600 * 24));
|
const days = Math.floor(totalSeconds / (3600 * 24));
|
||||||
var hours = Math.floor((totalSeconds % (3600 * 24)) / 3600);
|
const hours = Math.floor((totalSeconds % (3600 * 24)) / 3600);
|
||||||
var minutes = Math.floor((totalSeconds % 3600) / 60);
|
const minutes = Math.floor((totalSeconds % 3600) / 60);
|
||||||
var seconds = Math.floor(totalSeconds % 60);
|
const seconds = Math.floor(totalSeconds % 60);
|
||||||
var dayDisplay = days > 0 ? days + (days === 1 ? " day, " : " days, ") : "";
|
const dayDisplay = days > 0 ? days + (days === 1 ? " day, " : " days, ") : "";
|
||||||
var hourDisplay = hours > 0 ? hours + (hours === 1 ? " hour, " : " hours, ") : "";
|
const hourDisplay = hours > 0 ? hours + (hours === 1 ? " hour, " : " hours, ") : "";
|
||||||
var minuteDisplay = minutes > 0 ? minutes + (minutes === 1 ? " minute, " : " minutes, ") : "";
|
const minuteDisplay = minutes > 0 ? minutes + (minutes === 1 ? " minute, " : " minutes, ") : "";
|
||||||
var secondDisplay = seconds > 0 ? seconds + (seconds === 1 ? " second" : " seconds") : "";
|
const secondDisplay = seconds > 0 ? seconds + (seconds === 1 ? " second" : " seconds") : "";
|
||||||
return (dayDisplay + hourDisplay + minuteDisplay + secondDisplay).replace(/,\s*$/, "");
|
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}`;
|
||||||
|
}
|
||||||
|
|||||||
3
dist/ws.d.ts
vendored
3
dist/ws.d.ts
vendored
@@ -6,9 +6,6 @@ export type WsEvent = {
|
|||||||
export type WsClientChangeCallback = (clients: number) => void;
|
export type WsClientChangeCallback = (clients: number) => void;
|
||||||
export declare class WsService {
|
export declare class WsService {
|
||||||
private clients;
|
private clients;
|
||||||
private listeners;
|
|
||||||
onClientChange(callback: WsClientChangeCallback): () => void;
|
|
||||||
private emitClientChange;
|
|
||||||
addClient(ws: WebSocket): void;
|
addClient(ws: WebSocket): void;
|
||||||
removeClient(ws: WebSocket): void;
|
removeClient(ws: WebSocket): void;
|
||||||
broadcast(message: WsEvent): void;
|
broadcast(message: WsEvent): void;
|
||||||
|
|||||||
2
dist/ws.d.ts.map
vendored
2
dist/ws.d.ts.map
vendored
@@ -1 +1 @@
|
|||||||
{"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"}
|
{"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;IAE5C,SAAS,CAAC,EAAE,EAAE,SAAS,GAAG,IAAI;IAK9B,YAAY,CAAC,EAAE,EAAE,SAAS,GAAG,IAAI;IAKjC,SAAS,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAMjC,cAAc,IAAI,MAAM;CAGxB"}
|
||||||
14
dist/ws.js
vendored
14
dist/ws.js
vendored
@@ -1,27 +1,13 @@
|
|||||||
import { logInfo } from "./logger.js";
|
import { logInfo } from "./logger.js";
|
||||||
export class WsService {
|
export class WsService {
|
||||||
clients = new Set();
|
clients = new Set();
|
||||||
listeners = [];
|
|
||||||
onClientChange(callback) {
|
|
||||||
this.listeners.push(callback);
|
|
||||||
return () => {
|
|
||||||
this.listeners = this.listeners.filter((cb) => cb !== callback);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
emitClientChange() {
|
|
||||||
for (const callback of this.listeners) {
|
|
||||||
callback(this.clients.size);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
addClient(ws) {
|
addClient(ws) {
|
||||||
this.clients.add(ws);
|
this.clients.add(ws);
|
||||||
logInfo(`Socket connected. Total clients: ${this.clients.size}`);
|
logInfo(`Socket connected. Total clients: ${this.clients.size}`);
|
||||||
this.emitClientChange();
|
|
||||||
}
|
}
|
||||||
removeClient(ws) {
|
removeClient(ws) {
|
||||||
this.clients.delete(ws);
|
this.clients.delete(ws);
|
||||||
logInfo(`Socket disconnected. Total clients: ${this.clients.size}`);
|
logInfo(`Socket disconnected. Total clients: ${this.clients.size}`);
|
||||||
this.emitClientChange();
|
|
||||||
}
|
}
|
||||||
broadcast(message) {
|
broadcast(message) {
|
||||||
this.clients.forEach((socket) => {
|
this.clients.forEach((socket) => {
|
||||||
|
|||||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@dpu/shared",
|
"name": "@dpu/shared",
|
||||||
"version": "1.8.1",
|
"version": "1.9.9",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@dpu/shared",
|
"name": "@dpu/shared",
|
||||||
"version": "1.8.1",
|
"version": "1.9.9",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/ws": "^8.18.1",
|
"@types/ws": "^8.18.1",
|
||||||
"axios": "^1.7.9",
|
"axios": "^1.7.9",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@dpu/shared",
|
"name": "@dpu/shared",
|
||||||
"version": "1.8.1",
|
"version": "1.9.9",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import type { AxiosInstance } from "axios";
|
import type { AxiosInstance } from "axios";
|
||||||
|
import { logWarning } from "./logger.js";
|
||||||
|
|
||||||
export type ServiceResult<T = unknown> = {
|
export type ServiceResult<T = unknown> = {
|
||||||
result: T;
|
result: T;
|
||||||
@@ -39,9 +40,10 @@ export abstract class BaseService<T> {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
getErrorResult(error: string): ServiceResult<string> {
|
getErrorResult(errorMessage: string, error?: unknown): ServiceResult<string> {
|
||||||
|
logWarning(errorMessage, error);
|
||||||
return {
|
return {
|
||||||
result: error,
|
result: errorMessage,
|
||||||
successful: false,
|
successful: false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,9 +11,9 @@ export type HomeAssistantEntity = {
|
|||||||
[key: string]: unknown;
|
[key: string]: unknown;
|
||||||
};
|
};
|
||||||
last_changed: string; // datetime string
|
last_changed: string; // datetime string
|
||||||
last_reported: string; // datetime string
|
last_reported?: string; // datetime string
|
||||||
last_updated: string; // datetime string
|
last_updated?: string; // datetime string
|
||||||
context: {
|
context?: {
|
||||||
id: string;
|
id: string;
|
||||||
parent_id: string | null;
|
parent_id: string | null;
|
||||||
user_id: string | null;
|
user_id: string | null;
|
||||||
@@ -23,13 +23,24 @@ export type HomeAssistantEntity = {
|
|||||||
export interface HomeAssistantDeskPositionResult {
|
export interface HomeAssistantDeskPositionResult {
|
||||||
raw: HomeAssistantEntity;
|
raw: HomeAssistantEntity;
|
||||||
as_boolean: boolean;
|
as_boolean: boolean;
|
||||||
as_text: () => string;
|
|
||||||
last_changed: TimeBetween;
|
last_changed: TimeBetween;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type API_HA_DeskPosition = {
|
export type API_HA_DeskPosition = {
|
||||||
position: string;
|
|
||||||
is_standing: boolean;
|
is_standing: boolean;
|
||||||
last_changed: string;
|
last_changed: string;
|
||||||
last_changed_seconds: number;
|
last_changed_seconds: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type HA_Update = {
|
||||||
|
entity_id: string;
|
||||||
|
state: string;
|
||||||
|
attributes: {
|
||||||
|
state_class?: string;
|
||||||
|
unit_of_measurement?: string;
|
||||||
|
icon?: string;
|
||||||
|
friendly_name?: string;
|
||||||
|
[key: string]: unknown;
|
||||||
|
};
|
||||||
|
timestamp: string; // datetime string
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
|
import type { GristRecord_PersonalGoals } from "./grist";
|
||||||
import type { API_HA_DeskPosition } from "./homeassistant";
|
import type { API_HA_DeskPosition } from "./homeassistant";
|
||||||
|
import type { StatusComponentName } from "./status";
|
||||||
import type { TidalGetCurrent } from "./tidal";
|
import type { TidalGetCurrent } from "./tidal";
|
||||||
|
|
||||||
export type FullInformation = {
|
export type FullInformation = Record<StatusComponentName, unknown> & {
|
||||||
ha_desk_position: API_HA_DeskPosition | null;
|
ha_desk_position: API_HA_DeskPosition | null;
|
||||||
ha_temp: string | null;
|
ha_temp: string | null;
|
||||||
tidal_current: TidalGetCurrent | null;
|
tidal_current: TidalGetCurrent | null;
|
||||||
|
grist_personal_goals: GristRecord_PersonalGoals | null;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ export * from "./grist.js";
|
|||||||
export * from "./homeassistant.js";
|
export * from "./homeassistant.js";
|
||||||
export * from "./homepage.js";
|
export * from "./homepage.js";
|
||||||
export * from "./logger.js";
|
export * from "./logger.js";
|
||||||
|
export * from "./status.js";
|
||||||
export * from "./tidal.js";
|
export * from "./tidal.js";
|
||||||
export * from "./timehelper.js";
|
export * from "./timehelper.js";
|
||||||
export * from "./ws.js";
|
export * from "./ws.js";
|
||||||
|
|||||||
24
src/status.ts
Normal file
24
src/status.ts
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
export const StatusComponent = {
|
||||||
|
HA_DESK_POSITION: "ha_desk_position",
|
||||||
|
HA_TEMP: "ha_temp",
|
||||||
|
TIDAL_CURRENT: "tidal_current",
|
||||||
|
GRIST_PERSONAL_GOALS: "grist_personal_goals",
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
export type StatusComponentName =
|
||||||
|
(typeof StatusComponent)[keyof typeof StatusComponent];
|
||||||
|
|
||||||
|
export type ComponentUpdate = {
|
||||||
|
component: StatusComponentName;
|
||||||
|
data: unknown;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function createComponentUpdate(
|
||||||
|
component: StatusComponentName,
|
||||||
|
data: unknown,
|
||||||
|
) {
|
||||||
|
return {
|
||||||
|
component: component,
|
||||||
|
data: data,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -51,30 +51,36 @@ export function calculateSecondsBetween(
|
|||||||
return {
|
return {
|
||||||
seconds,
|
seconds,
|
||||||
toReadable: (roundToMinutes?: boolean) =>
|
toReadable: (roundToMinutes?: boolean) =>
|
||||||
secondsToReadable(seconds, roundToMinutes),
|
formatSecondsToDHMS(seconds, roundToMinutes),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function secondsToReadable(
|
export function formatSecondsToDHMS(
|
||||||
secs: number,
|
secs: number,
|
||||||
roundToMinutes: boolean = false,
|
roundToMinutes: boolean = false,
|
||||||
): string {
|
): 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));
|
const days = Math.floor(totalSeconds / (3600 * 24));
|
||||||
var hours = Math.floor((totalSeconds % (3600 * 24)) / 3600);
|
const hours = Math.floor((totalSeconds % (3600 * 24)) / 3600);
|
||||||
var minutes = Math.floor((totalSeconds % 3600) / 60);
|
const minutes = Math.floor((totalSeconds % 3600) / 60);
|
||||||
var seconds = Math.floor(totalSeconds % 60);
|
const seconds = Math.floor(totalSeconds % 60);
|
||||||
|
|
||||||
var dayDisplay = days > 0 ? days + (days === 1 ? " day, " : " days, ") : "";
|
const dayDisplay = days > 0 ? days + (days === 1 ? " day, " : " days, ") : "";
|
||||||
var hourDisplay =
|
const hourDisplay =
|
||||||
hours > 0 ? hours + (hours === 1 ? " hour, " : " hours, ") : "";
|
hours > 0 ? hours + (hours === 1 ? " hour, " : " hours, ") : "";
|
||||||
var minuteDisplay =
|
const minuteDisplay =
|
||||||
minutes > 0 ? minutes + (minutes === 1 ? " minute, " : " minutes, ") : "";
|
minutes > 0 ? minutes + (minutes === 1 ? " minute, " : " minutes, ") : "";
|
||||||
var secondDisplay =
|
const secondDisplay =
|
||||||
seconds > 0 ? seconds + (seconds === 1 ? " second" : " seconds") : "";
|
seconds > 0 ? seconds + (seconds === 1 ? " second" : " seconds") : "";
|
||||||
return (dayDisplay + hourDisplay + minuteDisplay + secondDisplay).replace(
|
return (dayDisplay + hourDisplay + minuteDisplay + secondDisplay).replace(
|
||||||
/,\s*$/,
|
/,\s*$/,
|
||||||
"",
|
"",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function formatSecondsToMS(s: number): string {
|
||||||
|
const mins = Math.floor(s / 60);
|
||||||
|
const secs = s % 60;
|
||||||
|
return `${mins}:${secs < 10 ? "0" : ""}${secs}`;
|
||||||
|
}
|
||||||
|
|||||||
16
src/ws.ts
16
src/ws.ts
@@ -10,31 +10,15 @@ export type WsClientChangeCallback = (clients: number) => void;
|
|||||||
|
|
||||||
export class WsService {
|
export class WsService {
|
||||||
private clients: Set<WebSocket> = new Set();
|
private clients: Set<WebSocket> = new Set();
|
||||||
private listeners: WsClientChangeCallback[] = [];
|
|
||||||
|
|
||||||
onClientChange(callback: WsClientChangeCallback): () => void {
|
|
||||||
this.listeners.push(callback);
|
|
||||||
return () => {
|
|
||||||
this.listeners = this.listeners.filter((cb) => cb !== callback);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private emitClientChange(): void {
|
|
||||||
for (const callback of this.listeners) {
|
|
||||||
callback(this.clients.size);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
addClient(ws: WebSocket): void {
|
addClient(ws: WebSocket): void {
|
||||||
this.clients.add(ws);
|
this.clients.add(ws);
|
||||||
logInfo(`Socket connected. Total clients: ${this.clients.size}`);
|
logInfo(`Socket connected. Total clients: ${this.clients.size}`);
|
||||||
this.emitClientChange();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
removeClient(ws: WebSocket): void {
|
removeClient(ws: WebSocket): void {
|
||||||
this.clients.delete(ws);
|
this.clients.delete(ws);
|
||||||
logInfo(`Socket disconnected. Total clients: ${this.clients.size}`);
|
logInfo(`Socket disconnected. Total clients: ${this.clients.size}`);
|
||||||
this.emitClientChange();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
broadcast(message: WsEvent): void {
|
broadcast(message: WsEvent): void {
|
||||||
|
|||||||
Reference in New Issue
Block a user