rhombus-node-mcp
Version:
MCP server for Rhombus API
182 lines (181 loc) • 6.47 kB
JavaScript
import { logger } from "../logger.js";
import { postApi } from "../network/network.js";
import { formatTimestamp } from "../util.js";
import { tempFunc } from "../utils/temp.js";
export async function getCameraList(requestModifiers, sessionId) {
const body = await postApi({
route: "/camera/getMinimalCameraStateList",
body: {},
modifiers: requestModifiers,
sessionId,
});
return {
cameras: (body.cameraStates ?? []).filter((camera) => !!camera.locationUuid),
};
}
export async function getDoorbellCameras(requestModifiers, sessionId) {
const body = await postApi({
route: "/doorbellcamera/getMinimalStateList",
body: {},
modifiers: requestModifiers,
sessionId,
});
return {
doorbellCameras: (body.minimalStates ?? []).filter((doorbellCamera) => !!doorbellCamera.locationUuid),
};
}
export async function getBadgeReaders(requestModifiers, sessionId) {
return await postApi({
route: "/badgereader/getMinimalStateList",
body: {},
modifiers: requestModifiers,
sessionId,
}).then((response) => {
return {
badgeReaders: (response.minimalStates ?? []).filter((badgeReader) => !!badgeReader.locationUuid),
};
});
}
export async function getAccessControlledDoors(requestModifiers, sessionId) {
return await postApi({
route: "/component/findAccessControlledDoors",
body: {},
modifiers: requestModifiers,
sessionId,
}).then((response) => {
return {
accessControlledDoors: (response.accessControlledDoors || []).map((door) => {
return {
geofenceEnabled: door.geofenceEnabled,
locationUuid: door.locationUuid,
policyUuid: door.policyUuid,
remoteUnlockEnabled: door.remoteUnlockEnabled,
associatedCameras: door.associatedCameras?.filter((c) => c !== null) ??
[],
name: door.name,
uuid: door.uuid,
};
}),
};
});
}
export async function getAudioGateways(timeZone, requestModifiers, sessionId) {
return await postApi({
route: "/audiogateway/getMinimalAudioGatewayStateList",
body: {},
modifiers: requestModifiers,
sessionId,
}).then((response) => {
return {
audioGateways: (response.audioGatewayStates ?? [])
.filter((camera) => !!camera.locationUuid)
.map((gateway) => ({
...gateway,
createdAtString: gateway.createdAtMillis
? formatTimestamp(gateway.createdAtMillis, timeZone)
: undefined,
})),
};
});
}
export async function getDoorSensors(requestModifiers, sessionId) {
return await postApi({
route: "/door/getMinimalDoorStateList",
body: {},
modifiers: requestModifiers,
sessionId,
}).then((response) => {
return {
doorStates: (response.doorStates ?? []).filter((door) => !!door.locationUuid),
};
});
}
export async function getEnvironmentalSensors(timeZone, tempUnit, requestModifiers, sessionId) {
return await postApi({
route: "/climate/getMinimalClimateStateList",
body: {},
modifiers: requestModifiers,
sessionId,
}).then((response) => {
logger.info("Using tempUnit: ", tempUnit);
return {
climateStates: (response.climateStates ?? [])
.filter((sensor) => !!sensor.locationUuid)
.map((_sensor) => {
const { temperatureCelcius, ...sensor } = _sensor;
return {
...sensor,
temperature: tempFunc(temperatureCelcius ?? 0, tempUnit),
createdAtString: sensor.createdAtMillis
? formatTimestamp(sensor.createdAtMillis, timeZone)
: undefined,
};
}),
};
});
}
export async function getMotionSensors(requestModifiers, sessionId) {
return await postApi({
route: "/occupancy/getMinimalOccupancySensorStateList",
body: {},
modifiers: requestModifiers,
sessionId,
}).then((response) => {
return {
occupancySensorStates: (response.occupancySensorStates ?? []).filter((occupancySensor) => !!occupancySensor.locationUuid),
};
});
}
export async function getButtons(timeZone, requestModifiers, sessionId) {
return await postApi({
route: "/button/getMinimalButtonStateList",
body: {},
modifiers: requestModifiers,
sessionId,
}).then((response) => {
return {
buttonStates: (response.states ?? [])
.filter((button) => !!button.locationUuid)
.map((button) => ({
...button,
createdAtString: button.createdAtMillis
? formatTimestamp(button.createdAtMillis, timeZone)
: undefined,
})),
};
});
}
export async function getKeypads(requestModifiers, sessionId) {
return await postApi({
route: "/keypad/getKeypadsForOrg",
body: {},
modifiers: requestModifiers,
sessionId,
}).then((response) => {
return {
keypadStates: (response.keypads ?? []).filter((keypad) => !!keypad.locationUuid),
};
});
}
export async function getEnvironmentalGateways(timeZone, requestModifiers, sessionId) {
return await postApi({
route: "/climate/getMinimalEnvironmentalGatewayStates",
body: {},
modifiers: requestModifiers,
sessionId,
}).then((response) => {
return {
minimalEnvironmentalGatewayStates: (response.minimalEnvironmentalGatewayStates ?? [])
.filter((gateway) => !!gateway.locationUuid)
.map((gateway) => ({
...gateway,
createdAtString: gateway.createdAtMillis
? formatTimestamp(gateway.createdAtMillis, timeZone)
: undefined,
timestampString: gateway.timestampMs
? formatTimestamp(gateway.timestampMs, timeZone)
: undefined,
})),
};
});
}