rewrite typeysation

This commit is contained in:
Darius
2025-11-21 16:49:12 +01:00
parent 27582e342f
commit e8459a7a7b
6 changed files with 131 additions and 514 deletions

View File

@@ -1,14 +1,8 @@
import type { HomeAssistantEntity } from "@dpu/shared";
import { BaseClient } from "@dpu/shared/dist/fastify";
import { printNetworkError } from "@dpu/shared/dist/logger.js";
import type { AxiosInstance } from "axios";
export class HomeAssistantClient {
private axiosInstance: AxiosInstance;
constructor(axiosInstance: AxiosInstance) {
this.axiosInstance = axiosInstance;
}
export class HomeAssistantClient extends BaseClient {
async getEntityStates(entityIds: string[]): Promise<HomeAssistantEntity[]> {
try {
const promises = entityIds.map((id) => this.getEntityState(id));
@@ -21,7 +15,7 @@ export class HomeAssistantClient {
async getEntityState(entityId: string): Promise<HomeAssistantEntity> {
try {
const response = await this.axiosInstance.get<HomeAssistantEntity>(
const response = await this.getAxios().get<HomeAssistantEntity>(
`states/${entityId}`,
);
return response.data;
@@ -33,7 +27,7 @@ export class HomeAssistantClient {
async triggerWebhook(webhookId: string): Promise<unknown> {
try {
const response = await this.axiosInstance.post<HomeAssistantEntity>(
const response = await this.getAxios().post<HomeAssistantEntity>(
`webhook/${webhookId}`,
);
return response.data;