Skip to content

Commit

Permalink
Various fixes
Browse files Browse the repository at this point in the history
- Return 500 instead of 503 when state data is missing for a group
- Correctly type Scene where it can be statically typed
- Always show a delete button for groups, even when state data is
missing
- Add missing break in switch statement
  • Loading branch information
amberstarlight committed Oct 14, 2024
1 parent 36d7c12 commit 1c767b8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
10 changes: 6 additions & 4 deletions packages/api/routes/groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import express, { Request, Response, Router } from "express";
import { Zigbee2MqttService } from "../zigbee2mqttService";
import { ApiError } from "./api";
import { nextUnused, range } from "../utils";
import { type Group, Scene } from "@starlight/types";
import { type Group, type Scene } from "@starlight/types";

const router = express.Router();

Expand Down Expand Up @@ -201,7 +201,7 @@ export function groupsRouter(zigbee2mqttService: Zigbee2MqttService): Router {
const state = await group.getValue(req.query.setting?.toString());

if (state === undefined) {
return res.status(503).json({
return res.status(500).json({
error: ApiError.StateDataMissing,
});
}
Expand Down Expand Up @@ -277,7 +277,7 @@ export function groupsRouter(zigbee2mqttService: Zigbee2MqttService): Router {
return res.status(404).json({ error: ApiError.NameInUse });
}

let sceneId = nextUnused(
const sceneId = nextUnused(
group.group.scenes.map((scene) => scene.id),
range(0, 255),
);
Expand Down Expand Up @@ -389,7 +389,9 @@ export function groupsRouter(zigbee2mqttService: Zigbee2MqttService): Router {
return res.status(404).json({ error: ApiError.GroupNotFound });
}

const currentSceneIds = group.group.scenes.map((scene) => scene.id);
const currentSceneIds = group.group.scenes.map(
(scene: Scene) => scene.id,
);

if (!currentSceneIds.includes(sceneId)) {
return res.status(404).json({ error: ApiError.SceneNotFound });
Expand Down
9 changes: 8 additions & 1 deletion packages/ui/src/components/GroupSettings/GroupSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ function GroupSettings(props) {
/>
);

if (!groupSettingsState) return <LoadingSpinner />;
if (!groupSettingsState)
return (
<>
<LoadingSpinner />
{deleteButton}
</>
);

const groupSettingsGenerator = (groupSettingsState, callback) => {
const settingComponents = [];
Expand Down Expand Up @@ -95,6 +101,7 @@ function GroupSettings(props) {
}}
/>,
);
break;
default:
break;
}
Expand Down

0 comments on commit 1c767b8

Please sign in to comment.