change homeassistant container to use new ddb
This commit is contained in:
parent
ca2cd5286f
commit
aeefd6f5d3
@ -1,8 +1,10 @@
|
|||||||
import { serve } from "bun";
|
import { serve } from "bun";
|
||||||
import { Hono } from "hono";
|
import { Hono } from "hono";
|
||||||
import { prettyJSON } from "hono/pretty-json";
|
import { prettyJSON } from "hono/pretty-json";
|
||||||
import { createDDBClient, getDoorConfigCommand, getLockStatusCommand, isLockOpen } from "../../doorman-api/src/utils/ddb";
|
import { createDynaBridgeClient } from "../../doorman-api/src/utils/ddb";
|
||||||
import { DoorStatus } from "../../doorman-api/src/types/DoorStatus";
|
import { DoorStatus } from "../../doorman-api/src/types/DoorStatus";
|
||||||
|
import { getLockStatusID, isLockOpen } from "../../doorman-api/src/schema/LockStatus";
|
||||||
|
import { getDoorConfigID } from "../../doorman-api/src/schema/DoorConfig";
|
||||||
|
|
||||||
const app = new Hono();
|
const app = new Hono();
|
||||||
|
|
||||||
@ -16,27 +18,22 @@ app.get("/api/door/info", async (c) => {
|
|||||||
}, 400);
|
}, 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
const client = createDDBClient(Bun.env as any);
|
const db = createDynaBridgeClient(Bun.env as any);
|
||||||
const config = await client.send(getDoorConfigCommand(door));
|
|
||||||
|
|
||||||
if (!config.Item) {
|
const config = await db.entities.doorConfig.findById(getDoorConfigID(door));
|
||||||
|
|
||||||
|
if (!config) {
|
||||||
return c.json({
|
return c.json({
|
||||||
err: "This buzzer is not registered properly",
|
err: "This buzzer is not registered properly",
|
||||||
}, 404);
|
}, 404);
|
||||||
}
|
}
|
||||||
return await client.send(getLockStatusCommand(door))
|
|
||||||
.then(async (lock) => {
|
const lock = await db.entities.lockStatus.findById(getLockStatusID(door));
|
||||||
const status = isLockOpen(lock) ? DoorStatus.OPEN: "CLOSED";
|
const status = isLockOpen(lock) ? DoorStatus.OPEN: "CLOSED";
|
||||||
return c.json({
|
return c.json({
|
||||||
id: door,
|
id: door,
|
||||||
status,
|
status,
|
||||||
});
|
});
|
||||||
}).catch((e) => {
|
|
||||||
console.log(e);
|
|
||||||
return c.json({
|
|
||||||
err: e,
|
|
||||||
}, 500);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
serve({
|
serve({
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user