Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1fcc02ef1f | ||
|
|
1085ce870b | ||
|
|
d73d98068a | ||
|
|
b305c2ab66 | ||
|
|
e3fbe3b178 | ||
|
|
4c46c5ae6d | ||
|
|
d416e8db07 | ||
|
|
aae0e0db9d | ||
|
|
9983ba1215 |
2
dist/fastify.js
vendored
2
dist/fastify.js
vendored
@@ -29,7 +29,7 @@ export class BaseService {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
getErrorResult(errorMessage, error) {
|
getErrorResult(errorMessage, error) {
|
||||||
logWarning(errorMessage);
|
logWarning(errorMessage, error);
|
||||||
return {
|
return {
|
||||||
result: errorMessage,
|
result: errorMessage,
|
||||||
successful: false,
|
successful: false,
|
||||||
|
|||||||
7
dist/homepage.d.ts
vendored
7
dist/homepage.d.ts
vendored
@@ -1,14 +1,11 @@
|
|||||||
import type { GristRecord_PersonalGoals } from "./grist";
|
import type { GristRecord_PersonalGoals } from "./grist";
|
||||||
import type { API_HA_DeskPosition } from "./homeassistant";
|
import type { API_HA_DeskPosition } from "./homeassistant";
|
||||||
|
import type { StatsComponentName } from "./stats";
|
||||||
import type { TidalGetCurrent } from "./tidal";
|
import type { TidalGetCurrent } from "./tidal";
|
||||||
export type FullInformation = {
|
export type FullInformation = Record<StatsComponentName, 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;
|
grist_personal_goals: GristRecord_PersonalGoals | null;
|
||||||
};
|
};
|
||||||
export type ComponentUpdate = {
|
|
||||||
component: string;
|
|
||||||
data: unknown;
|
|
||||||
};
|
|
||||||
//# 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,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"}
|
{"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,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,kBAAkB,EAAE,OAAO,CAAC,GAAG;IACnE,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 "./stats.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,YAAY,CAAC;AAC3B,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 "./stats.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";
|
||||||
|
|||||||
20
dist/stats.d.ts
vendored
Normal file
20
dist/stats.d.ts
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
export declare const StatsComponent: {
|
||||||
|
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 StatsComponentName = (typeof StatsComponent)[keyof typeof StatsComponent];
|
||||||
|
export type ComponentUpdate = {
|
||||||
|
component: StatsComponentName;
|
||||||
|
data: unknown;
|
||||||
|
};
|
||||||
|
export type StepRow = {
|
||||||
|
year: string;
|
||||||
|
steps: number;
|
||||||
|
};
|
||||||
|
export declare function createComponentUpdate(component: StatsComponentName, data: unknown): {
|
||||||
|
component: StatsComponentName;
|
||||||
|
data: unknown;
|
||||||
|
};
|
||||||
|
//# sourceMappingURL=stats.d.ts.map
|
||||||
1
dist/stats.d.ts.map
vendored
Normal file
1
dist/stats.d.ts.map
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"version":3,"file":"stats.d.ts","sourceRoot":"","sources":["../src/stats.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc;;;;;CAKjB,CAAC;AAEX,MAAM,MAAM,kBAAkB,GAC7B,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,OAAO,cAAc,CAAC,CAAC;AAEtD,MAAM,MAAM,eAAe,GAAG;IAC7B,SAAS,EAAE,kBAAkB,CAAC;IAC9B,IAAI,EAAE,OAAO,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,wBAAgB,qBAAqB,CACpC,SAAS,EAAE,kBAAkB,EAC7B,IAAI,EAAE,OAAO;;;EAMb"}
|
||||||
12
dist/stats.js
vendored
Normal file
12
dist/stats.js
vendored
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
export const StatsComponent = {
|
||||||
|
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/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.9.6",
|
"version": "1.10.0",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@dpu/shared",
|
"name": "@dpu/shared",
|
||||||
"version": "1.9.6",
|
"version": "1.10.0",
|
||||||
"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.9.6",
|
"version": "1.10.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ export abstract class BaseService<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getErrorResult(errorMessage: string, error?: unknown): ServiceResult<string> {
|
getErrorResult(errorMessage: string, error?: unknown): ServiceResult<string> {
|
||||||
logWarning(errorMessage);
|
logWarning(errorMessage, error);
|
||||||
return {
|
return {
|
||||||
result: errorMessage,
|
result: errorMessage,
|
||||||
successful: false,
|
successful: false,
|
||||||
|
|||||||
@@ -1,15 +1,11 @@
|
|||||||
import type { GristRecord_PersonalGoals } from "./grist";
|
import type { GristRecord_PersonalGoals } from "./grist";
|
||||||
import type { API_HA_DeskPosition } from "./homeassistant";
|
import type { API_HA_DeskPosition } from "./homeassistant";
|
||||||
|
import type { StatsComponentName } from "./stats";
|
||||||
import type { TidalGetCurrent } from "./tidal";
|
import type { TidalGetCurrent } from "./tidal";
|
||||||
|
|
||||||
export type FullInformation = {
|
export type FullInformation = Record<StatsComponentName, 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;
|
grist_personal_goals: GristRecord_PersonalGoals | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ComponentUpdate = {
|
|
||||||
component: string;
|
|
||||||
data: unknown;
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -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 "./stats.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";
|
||||||
|
|||||||
29
src/stats.ts
Normal file
29
src/stats.ts
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
export const StatsComponent = {
|
||||||
|
HA_DESK_POSITION: "ha_desk_position",
|
||||||
|
HA_TEMP: "ha_temp",
|
||||||
|
TIDAL_CURRENT: "tidal_current",
|
||||||
|
GRIST_PERSONAL_GOALS: "grist_personal_goals",
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
export type StatsComponentName =
|
||||||
|
(typeof StatsComponent)[keyof typeof StatsComponent];
|
||||||
|
|
||||||
|
export type ComponentUpdate = {
|
||||||
|
component: StatsComponentName;
|
||||||
|
data: unknown;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type StepRow = {
|
||||||
|
year: string;
|
||||||
|
steps: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function createComponentUpdate(
|
||||||
|
component: StatsComponentName,
|
||||||
|
data: unknown,
|
||||||
|
) {
|
||||||
|
return {
|
||||||
|
component: component,
|
||||||
|
data: data,
|
||||||
|
};
|
||||||
|
}
|
||||||
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