Skip to content

Commit 2b89336

Browse files
committed
Add support for zigbee component
1 parent 2b12147 commit 2b89336

3 files changed

Lines changed: 86 additions & 3 deletions

File tree

packages/web/src/components/device-detail/device-components.tsx

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import { useTranslation } from "react-i18next";
2-
import { Power, Thermometer, Zap, Activity, Settings } from "lucide-react";
2+
import {
3+
Power,
4+
Thermometer,
5+
Zap,
6+
Activity,
7+
Settings,
8+
Wifi,
9+
} from "lucide-react";
310

411
import { Badge } from "@/components/ui/badge";
512
import {
@@ -15,6 +22,7 @@ import {
1522
isCoverComponent,
1623
isSystemComponent,
1724
isCloudComponent,
25+
isZigbeeComponent,
1826
} from "@/types/api";
1927
import type { DeviceStatus, Component } from "@/types/api";
2028

@@ -241,7 +249,7 @@ export function DeviceComponents({
241249
<CardHeader className="pb-3">
242250
<CardTitle className="flex items-center space-x-2 text-base">
243251
<Settings className="h-4 w-4" />
244-
<span>{t("deviceDetail.components.system")}</span>
252+
<span>System</span>
245253
</CardTitle>
246254
<CardDescription>
247255
{t("deviceDetail.components.system.description")}
@@ -333,6 +341,59 @@ export function DeviceComponents({
333341
);
334342
}
335343

344+
if (isZigbeeComponent(component)) {
345+
const getStatusVariant = (networkState: string) => {
346+
switch (networkState.toLowerCase()) {
347+
case "joined":
348+
return "default";
349+
case "joining":
350+
return "secondary";
351+
default:
352+
return "destructive";
353+
}
354+
};
355+
356+
const getStatusLabel = (networkState: string) => {
357+
switch (networkState.toLowerCase()) {
358+
case "joined":
359+
return t("deviceDetail.components.zigbee.joined");
360+
case "joining":
361+
return t("deviceDetail.components.zigbee.joining");
362+
default:
363+
return t("deviceDetail.components.zigbee.disconnected");
364+
}
365+
};
366+
367+
return (
368+
<Card key={component.key} className="border-l-4 border-l-orange-500">
369+
<CardHeader className="pb-3">
370+
<CardTitle className="flex items-center justify-between text-base">
371+
<div className="flex items-center space-x-2">
372+
<Wifi className="h-4 w-4" />
373+
<span>Zigbee</span>
374+
</div>
375+
<Badge variant={getStatusVariant(component.status.network_state)}>
376+
{getStatusLabel(component.status.network_state)}
377+
</Badge>
378+
</CardTitle>
379+
<CardDescription>
380+
{t("deviceDetail.components.zigbee.description")}
381+
</CardDescription>
382+
</CardHeader>
383+
<CardContent className="pt-0">
384+
<div className="space-y-2 text-sm">
385+
<div className="flex items-center justify-between">
386+
<span>{t("deviceDetail.components.zigbee.networkState")}</span>
387+
<span className="font-medium">
388+
{component.status.network_state}
389+
</span>
390+
</div>
391+
</div>
392+
</CardContent>
393+
</Card>
394+
);
395+
}
396+
336397
// Generic component fallback
337398
return (
338399
<Card key={component.key} className="border-l-4 border-l-gray-300">

packages/web/src/i18n/en.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,13 @@
179179
"enabled": "Enabled",
180180
"server": "Server"
181181
},
182+
"zigbee": {
183+
"joined": "JOINED",
184+
"joining": "JOINING",
185+
"disconnected": "DISCONNECTED",
186+
"description": "Zigbee network connectivity status",
187+
"networkState": "Network State"
188+
},
182189
"generic": {
183190
"componentType": "Component type"
184191
}

packages/web/src/types/api.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ export interface CloudComponent extends Component {
108108
};
109109
}
110110

111+
export interface ZigbeeComponent extends Component {
112+
type: "zigbee";
113+
status: {
114+
network_state: string;
115+
};
116+
config: Record<string, unknown>;
117+
}
118+
111119
export interface UpdateInfo {
112120
version: string;
113121
build_id: string;
@@ -197,7 +205,8 @@ export type ComponentType =
197205
| InputComponent
198206
| CoverComponent
199207
| SystemComponent
200-
| CloudComponent;
208+
| CloudComponent
209+
| ZigbeeComponent;
201210

202211
export function isSwitchComponent(
203212
component: Component,
@@ -228,3 +237,9 @@ export function isCloudComponent(
228237
): component is CloudComponent {
229238
return component.type === "cloud";
230239
}
240+
241+
export function isZigbeeComponent(
242+
component: Component,
243+
): component is ZigbeeComponent {
244+
return component.type === "zigbee";
245+
}

0 commit comments

Comments
 (0)