diff --git a/src/config.ts b/src/config.ts index 18d65d7..22682c3 100644 --- a/src/config.ts +++ b/src/config.ts @@ -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; diff --git a/src/homeassistant/client.ts b/src/homeassistant/client.ts index 106f246..26cc345 100644 --- a/src/homeassistant/client.ts +++ b/src/homeassistant/client.ts @@ -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 { - 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 { + 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 { - try { - const response = await this.getAxios().get( - `states/${entityId}`, - ); - return response.data; - } catch (error) { - printNetworkError(error); - throw error; - } - } + async getEntityState(entityId: string): Promise { + try { + const response = await this.getAxios().get( + `states/${entityId}`, + ); + return response.data; + } catch (error) { + printNetworkError(error); + throw error; + } + } - async triggerWebhook(webhookId: string): Promise { - try { - const response = await this.getAxios().post( - `webhook/${webhookId}`, - ); - return response.data; - } catch (error) { - printNetworkError(error); - throw error; - } - } + async triggerWebhook(webhookId: string): Promise { + try { + const response = await this.getAxios().post( + `webhook/${webhookId}`, + ); + return response.data; + } catch (error) { + printNetworkError(error); + throw error; + } + } } diff --git a/src/homepage/routes.ts b/src/homepage/routes.ts index 634fb9d..9b726f9 100644 --- a/src/homepage/routes.ts +++ b/src/homepage/routes.ts @@ -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, diff --git a/src/homepage/service.ts b/src/homepage/service.ts index 653fad4..89a3682 100644 --- a/src/homepage/service.ts +++ b/src/homepage/service.ts @@ -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 { private haService: HomeAssistantService; diff --git a/src/index.ts b/src/index.ts index 0fa4518..229bd71 100644 --- a/src/index.ts +++ b/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(); diff --git a/src/websocket/routes.ts b/src/websocket/routes.ts index bf1dfcf..9b791da 100644 --- a/src/websocket/routes.ts +++ b/src/websocket/routes.ts @@ -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,