Skip to content

Commit

Permalink
🥅 Update power state error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreMiras committed Dec 8, 2024
1 parent 0b15e22 commit 90a4364
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/pages/fireplace/[mac].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,20 @@ const Fireplace: NextPage = () => {
fetch();
}, [addErrorCallback, mac, token]);

const onPowerChange = (value: number) => {
setPower(token!, mac!, value);
const onPowerChange = async (value: number) => {
// set the state before hand to avoid the lag feeling
setPowerState(Boolean(value));
try {
await setPower(token!, mac!, value);
} catch (error) {
console.error(error);
addErrorCallback({
title: "Power State Update Failed",
body: "Unable to change the power state. Please try again.",
});
// rollback to the actual/previous value
setPowerState(powerState);
}
};

const onTemperatureChange = async (newTemperature: number) => {
Expand Down

0 comments on commit 90a4364

Please sign in to comment.