formatting
This commit is contained in:
@@ -3,22 +3,22 @@ import dotenv from "dotenv";
|
||||
dotenv.config();
|
||||
|
||||
export const Config = {
|
||||
api_key: process.env.API_KEY,
|
||||
port: process.env.PORT || "8080",
|
||||
env_dev: process.env.ENV_DEV || false,
|
||||
api_key: process.env.API_KEY,
|
||||
port: process.env.PORT || "8080",
|
||||
env_dev: process.env.ENV_DEV || false,
|
||||
|
||||
tidal: {
|
||||
host: process.env.TIDAL_HOST || "",
|
||||
port: process.env.TIDAL_PORT || "",
|
||||
},
|
||||
tidal: {
|
||||
host: process.env.TIDAL_HOST || "",
|
||||
port: process.env.TIDAL_PORT || "",
|
||||
},
|
||||
|
||||
homeassistant: {
|
||||
api_url: process.env.HA_API_URL || "",
|
||||
api_token: process.env.HA_API_TOKEN || "",
|
||||
homeassistant: {
|
||||
api_url: process.env.HA_API_URL || "",
|
||||
api_token: process.env.HA_API_TOKEN || "",
|
||||
|
||||
id_desk_sensor_binary: process.env.HA_DESK_SENSOR_BINARY || "",
|
||||
id_room_sensors: process.env.HA_ROOMTEMP_SENSOR_IDS?.split(",") || [],
|
||||
id_desk_sensor_binary: process.env.HA_DESK_SENSOR_BINARY || "",
|
||||
id_room_sensors: process.env.HA_ROOMTEMP_SENSOR_IDS?.split(",") || [],
|
||||
|
||||
id_webhook_stand: process.env.HA_STANDING_WEBHOOK || "",
|
||||
},
|
||||
id_webhook_stand: process.env.HA_STANDING_WEBHOOK || "",
|
||||
},
|
||||
} as const;
|
||||
|
||||
@@ -2,37 +2,37 @@ import { BaseClient, type HomeAssistantEntity } from "@dpu/shared";
|
||||
import { printNetworkError } from "@dpu/shared/dist/logger.js";
|
||||
|
||||
export class HomeAssistantClient extends BaseClient {
|
||||
async getEntityStates(entityIds: string[]): Promise<HomeAssistantEntity[]> {
|
||||
try {
|
||||
const promises = entityIds.map((id) => this.getEntityState(id));
|
||||
return await Promise.all(promises);
|
||||
} catch (error) {
|
||||
printNetworkError(error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
async getEntityStates(entityIds: string[]): Promise<HomeAssistantEntity[]> {
|
||||
try {
|
||||
const promises = entityIds.map((id) => this.getEntityState(id));
|
||||
return await Promise.all(promises);
|
||||
} catch (error) {
|
||||
printNetworkError(error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async getEntityState(entityId: string): Promise<HomeAssistantEntity> {
|
||||
try {
|
||||
const response = await this.getAxios().get<HomeAssistantEntity>(
|
||||
`states/${entityId}`,
|
||||
);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
printNetworkError(error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
async getEntityState(entityId: string): Promise<HomeAssistantEntity> {
|
||||
try {
|
||||
const response = await this.getAxios().get<HomeAssistantEntity>(
|
||||
`states/${entityId}`,
|
||||
);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
printNetworkError(error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async triggerWebhook(webhookId: string): Promise<unknown> {
|
||||
try {
|
||||
const response = await this.getAxios().post<HomeAssistantEntity>(
|
||||
`webhook/${webhookId}`,
|
||||
);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
printNetworkError(error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
async triggerWebhook(webhookId: string): Promise<unknown> {
|
||||
try {
|
||||
const response = await this.getAxios().post<HomeAssistantEntity>(
|
||||
`webhook/${webhookId}`,
|
||||
);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
printNetworkError(error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { API_HA_DeskPosition, TidalGetCurrent } from "@dpu/shared";
|
||||
import type { FastifyInstance } from "fastify";
|
||||
import { z } from "zod";
|
||||
import { type HomepageService } from "./service.js";
|
||||
import { type API_HA_DeskPosition, type TidalGetCurrent } from "@dpu/shared";
|
||||
import type { HomepageService } from "./service.js";
|
||||
|
||||
export async function homepageRoutes(
|
||||
fastify: FastifyInstance,
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import {
|
||||
BaseService,
|
||||
FullInformation,
|
||||
HomeAssistantDeskPositionResult,
|
||||
TidalGetCurrent,
|
||||
WsService,
|
||||
type FullInformation,
|
||||
type HomeAssistantDeskPositionResult,
|
||||
type ServiceResult,
|
||||
type TidalGetCurrent,
|
||||
type WsService,
|
||||
} from "@dpu/shared";
|
||||
import { logInfo, logWarning } from "@dpu/shared/dist/logger.js";
|
||||
import { HomeAssistantService } from "../homeassistant/service";
|
||||
import { TidalService } from "../tidal/service";
|
||||
import type { HomeAssistantService } from "../homeassistant/service";
|
||||
import type { TidalService } from "../tidal/service";
|
||||
|
||||
export class HomepageService extends BaseService<null> {
|
||||
private haService: HomeAssistantService;
|
||||
|
||||
16
src/index.ts
16
src/index.ts
@@ -1,6 +1,9 @@
|
||||
import { WsService } from "@dpu/shared";
|
||||
import { logInfo } from "@dpu/shared/dist/logger.js";
|
||||
import fastifyCors from "@fastify/cors";
|
||||
import fastifySwagger from "@fastify/swagger";
|
||||
import fastifySwaggerUi from "@fastify/swagger-ui";
|
||||
import fastifyWebsocket from "@fastify/websocket";
|
||||
import type { FastifyReply, FastifyRequest } from "fastify";
|
||||
import Fastify from "fastify";
|
||||
import fastifyAxios from "fastify-axios";
|
||||
@@ -16,15 +19,12 @@ import { Config } from "./config.js";
|
||||
import { HomeAssistantClient } from "./homeassistant/client.js";
|
||||
import { homeAssistantRoutes } from "./homeassistant/routes.js";
|
||||
import { HomeAssistantService } from "./homeassistant/service.js";
|
||||
import { TidalClient } from "./tidal/client.js";
|
||||
import { TidalService } from "./tidal/service.js";
|
||||
import { tidalRoutes } from "./tidal/routes.js";
|
||||
import { wsRoutes } from "./websocket/routes.js";
|
||||
import { HomepageService } from "./homepage/service.js";
|
||||
import { homepageRoutes } from "./homepage/routes.js";
|
||||
import fastifyCors from "@fastify/cors";
|
||||
import fastifyWebsocket from "@fastify/websocket";
|
||||
import { WsService } from "@dpu/shared";
|
||||
import { HomepageService } from "./homepage/service.js";
|
||||
import { TidalClient } from "./tidal/client.js";
|
||||
import { tidalRoutes } from "./tidal/routes.js";
|
||||
import { TidalService } from "./tidal/service.js";
|
||||
import { wsRoutes } from "./websocket/routes.js";
|
||||
|
||||
const fastify = Fastify().withTypeProvider<ZodTypeProvider>();
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { logInfo, type WsService } from "@dpu/shared";
|
||||
import type { FastifyInstance } from "fastify";
|
||||
import { logInfo, WsService } from "@dpu/shared";
|
||||
|
||||
export async function wsRoutes(
|
||||
fastify: FastifyInstance,
|
||||
|
||||
Reference in New Issue
Block a user