add seconds to standing/sitting time
This commit is contained in:
4
package-lock.json
generated
4
package-lock.json
generated
@@ -26,8 +26,8 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@dpu/shared": {
|
"node_modules/@dpu/shared": {
|
||||||
"version": "1.6.2",
|
"version": "1.6.4",
|
||||||
"resolved": "git+https://git.dariusbag.dev/DarDarBinks/dpu-shared.git#ceadd4e5a2db3e94234a455d66338fb94fccea40",
|
"resolved": "git+https://git.dariusbag.dev/DarDarBinks/dpu-shared.git#60bcd23f5b77034777a792bbe8f33a62e92ba246",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^1.7.9",
|
"axios": "^1.7.9",
|
||||||
"chalk": "^5.6.2",
|
"chalk": "^5.6.2",
|
||||||
|
|||||||
@@ -4,101 +4,104 @@ import { z } from "zod";
|
|||||||
import type { HomeAssistantService } from "../homeassistant/service.js";
|
import type { HomeAssistantService } from "../homeassistant/service.js";
|
||||||
|
|
||||||
export async function homeAssistantRoutes(
|
export async function homeAssistantRoutes(
|
||||||
fastify: FastifyInstance,
|
fastify: FastifyInstance,
|
||||||
{
|
{
|
||||||
haService,
|
haService,
|
||||||
verifyAPIKey,
|
verifyAPIKey,
|
||||||
}: {
|
}: {
|
||||||
haService: HomeAssistantService;
|
haService: HomeAssistantService;
|
||||||
verifyAPIKey: (
|
verifyAPIKey: (
|
||||||
request: FastifyRequest,
|
request: FastifyRequest,
|
||||||
reply: FastifyReply,
|
reply: FastifyReply,
|
||||||
) => Promise<void>;
|
) => Promise<void>;
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
fastify.get(
|
fastify.get(
|
||||||
"/homeassistant/desk/position",
|
"/homeassistant/desk/position",
|
||||||
{
|
{
|
||||||
schema: {
|
schema: {
|
||||||
description: "Get current desk position",
|
description: "Get current desk position",
|
||||||
tags: ["homeassistant"],
|
tags: ["homeassistant"],
|
||||||
response: {
|
response: {
|
||||||
200: z.object({
|
200: z.object({
|
||||||
position: z.string(),
|
position: z.string(),
|
||||||
is_standing: z.boolean(),
|
is_standing: z.boolean(),
|
||||||
last_changed: z.string(),
|
last_changed: z.string(),
|
||||||
}),
|
last_changed_seconds: z.number(),
|
||||||
418: z.object({
|
}),
|
||||||
error: z.string(),
|
418: z.object({
|
||||||
}),
|
error: z.string(),
|
||||||
},
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
async (_request, reply) => {
|
},
|
||||||
const service_result = await haService.getDeskPosition();
|
async (_request, reply) => {
|
||||||
|
const service_result = await haService.getDeskPosition();
|
||||||
|
|
||||||
if (!service_result.successful) {
|
if (!service_result.successful) {
|
||||||
reply.code(418);
|
reply.code(418);
|
||||||
return { error: service_result.result };
|
return { error: service_result.result };
|
||||||
}
|
}
|
||||||
|
|
||||||
return haService.convertPosResultToApiAnswer(service_result.result as HomeAssistantDeskPositionResult);
|
return haService.convertPosResultToApiAnswer(
|
||||||
},
|
service_result.result as HomeAssistantDeskPositionResult,
|
||||||
);
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
fastify.post(
|
fastify.post(
|
||||||
"/homeassistant/desk/stand",
|
"/homeassistant/desk/stand",
|
||||||
{
|
{
|
||||||
preHandler: verifyAPIKey,
|
preHandler: verifyAPIKey,
|
||||||
schema: {
|
schema: {
|
||||||
description: "Trigger standing desk automation",
|
description: "Trigger standing desk automation",
|
||||||
tags: ["homeassistant"],
|
tags: ["homeassistant"],
|
||||||
response: {
|
response: {
|
||||||
200: z.unknown(),
|
200: z.unknown(),
|
||||||
401: z.object({
|
401: z.object({
|
||||||
error: z.literal("Invalid API key"),
|
error: z.literal("Invalid API key"),
|
||||||
}),
|
}),
|
||||||
418: z.object({
|
418: z.object({
|
||||||
error: z.string(),
|
error: z.string(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
async (_request, reply) => {
|
async (_request, reply) => {
|
||||||
const service_result = await haService.startStandingAutomation();
|
const service_result = await haService.startStandingAutomation();
|
||||||
|
|
||||||
if (!service_result.successful) {
|
if (!service_result.successful) {
|
||||||
reply.code(418);
|
reply.code(418);
|
||||||
return { error: service_result.result };
|
return { error: service_result.result };
|
||||||
}
|
}
|
||||||
|
|
||||||
return service_result.result;
|
return service_result.result;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
fastify.get(
|
fastify.get(
|
||||||
"/homeassistant/temperature",
|
"/homeassistant/temperature",
|
||||||
{
|
{
|
||||||
schema: {
|
schema: {
|
||||||
description: "Get current room temperature",
|
description: "Get current room temperature",
|
||||||
tags: ["homeassistant"],
|
tags: ["homeassistant"],
|
||||||
response: {
|
response: {
|
||||||
200: z.string(),
|
200: z.string(),
|
||||||
418: z.object({
|
418: z.object({
|
||||||
error: z.string(),
|
error: z.string(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
async (_request, reply) => {
|
async (_request, reply) => {
|
||||||
const service_result = await haService.getTemperatureText();
|
const service_result = await haService.getTemperatureText();
|
||||||
|
|
||||||
if (!service_result.successful) {
|
if (!service_result.successful) {
|
||||||
reply.code(418);
|
reply.code(418);
|
||||||
return { error: service_result.result };
|
return { error: service_result.result };
|
||||||
}
|
}
|
||||||
|
|
||||||
return service_result.result;
|
return service_result.result;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ export class HomeAssistantService extends BaseService<HomeAssistantClient> {
|
|||||||
position: position.as_text(),
|
position: position.as_text(),
|
||||||
is_standing: position.as_boolean,
|
is_standing: position.as_boolean,
|
||||||
last_changed: position.last_changed.toReadable(true),
|
last_changed: position.last_changed.toReadable(true),
|
||||||
|
last_changed_seconds: position.last_changed.seconds,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user