Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: restyle homesec
Browse files Browse the repository at this point in the history
mdvanes committed Apr 15, 2024

Verified

This commit was signed with the committer’s verified signature.
1 parent 2df4cb7 commit 8c0ee98
Showing 4 changed files with 127 additions and 18 deletions.
92 changes: 82 additions & 10 deletions apps/client/src/Components/Molecules/HomeSec/HomeSec.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,93 @@
import { FC } from "react";
import { useGetHomesecStatusQuery } from "../../../Services/homesecApi";
import {
List,
ListItem,
ListItemAvatar,
ListItemButton,
ListItemText,
Paper,
Icon,
} from "@mui/material";
import { HomesecStatusResponse, TypeF } from "@homeremote/types";
import LoadingDot from "../LoadingDot/LoadingDot";
import SimpleHomeSecListItem from "./SimpleHomeSecListItem";

export const HomeSec: FC = () => {
// TODO handle error/loading
const { data } = useGetHomesecStatusQuery(undefined);
const statusClass: Record<HomesecStatusResponse["status"] | "Error", string> = {
Error: "black",
Disarm: "green",
"Home Arm 1": "yellow",
};

console.log(data?.status);
const typeIcon: Record<TypeF, string> = {
"Door Contact": "sensor_door",
"Smoke Detector": "smoking_rooms",
Keypad: "keyboard",
IR: "animation",
"Remote Controller": "settings_remote",
};

export const HomeSec: FC = () => {
const { data, isLoading, isFetching, isError, refetch } =
useGetHomesecStatusQuery(undefined);

return (
<div>
{data?.status}
<List
component={Paper}
style={{
borderWidth: 1,
borderStyle: "solid",
borderColor: statusClass[data?.status ?? "Error"],
}}
>
<LoadingDot isLoading={isLoading || isFetching} />
{isError ? (
<SimpleHomeSecListItem
title="Error retrieving devices"
onClick={() => refetch()}
/>
) : (
""
)}
{!data?.devices || data?.devices.length === 0 ? (
<SimpleHomeSecListItem
title="No devices found"
onClick={() => refetch()}
/>
) : (
""
)}
{data?.devices?.map((sensor) => (
<div key={sensor.id}>
{sensor.name}: {sensor.status} {sensor.type_f} {sensor.rssi}
</div>
<ListItem disableGutters disablePadding dense>
<ListItemButton>
<ListItemAvatar>
<Icon>{typeIcon[sensor.type_f]}</Icon>
</ListItemAvatar>
<ListItemText
primary={
<div
style={{
display: "flex",
justifyContent: "space-between",
}}
>
<div>{sensor.name}</div>
<div
style={{
display: "flex",
gap: "16px",
}}
>
<div>{sensor.status}</div>
<div>{sensor.rssi}</div>
</div>
</div>
}
/>
</ListItemButton>
</ListItem>
))}
</div>
</List>
);
};

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import RestartAltIcon from "@mui/icons-material/RestartAlt";
import {
IconButton,
ListItem,
ListItemAvatar,
ListItemButton,
ListItemText,
} from "@mui/material";
import { FC } from "react";

const SimpleHomeSecListItem: FC<{ title: string; onClick: () => void }> = ({
title,
onClick,
}) => {
return (
<ListItem disableGutters disablePadding>
<ListItemButton>
<ListItemAvatar></ListItemAvatar>
<ListItemText
primary={
<>
{title}
<IconButton onClick={onClick}>
<RestartAltIcon />
</IconButton>
</>
}
/>
</ListItemButton>
</ListItem>
);
};

export default SimpleHomeSecListItem;
5 changes: 3 additions & 2 deletions apps/server/src/homesec/homesec.controller.ts
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@ import {
HomesecPanelResponse,
HomesecStatusResponse,
} from "@homeremote/types";
import { wait } from "../util/wait";

@Controller("api/homesec")
export class HomesecController {
@@ -48,17 +49,17 @@ export class HomesecController {
password: this.password,
}
).json();
this.logger.log(panelResponse);

try {
await wait(5000);
const devicesResponse: HomesecDevicesResponse = await got(
`${this.baseUrl}/action/deviceListGet`,
{
username: this.username,
password: this.password,
}
).json();
this.logger.log(devicesResponse);

return {
status: panelResponse.updates.mode_a1,
devices: devicesResponse.senrows.map(
14 changes: 8 additions & 6 deletions libs/types/src/lib/homesec.types.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
export type TypeF =
| "Door Contact"
| "Smoke Detector"
| "Keypad"
| "IR"
| "Remote Controller";

interface SensorRow {
area: number;
zone: number;
type: number;
type_f:
| "Door Contact"
| "Smoke Detector"
| "Keypad"
| "IR"
| "Remote Controller";
type_f: TypeF;
name: string;
cond: "";
cond_ok: "0" | "1";

0 comments on commit 8c0ee98

Please sign in to comment.