Skip to content

Commit

Permalink
fix door api :)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewDTR committed Sep 28, 2024
1 parent e53d8a1 commit 98683b3
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/components/DoorStatus.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,25 @@ const DoorStatus = () => {
try {
const response = await fetch("https://doors.amoses.dev/door-status");
const data = await response.json();
const { door1, door2 } = data.status;

// Determine if the UPL is open
if (door1 === "open" && door2 === "open") {
// determine if the UPL is open
const backDoor = data.find((door) => door.door === "back");
const frontDoor = data.find((door) => door.door === "front");

if (backDoor?.status === "on" && frontDoor?.status === "on") {
setIsOpen(true);
} else {
setIsOpen(false);
}
} catch (error) {
console.error("Error fetching door status:", error);
setIsOpen(false); // Default to closed
setIsOpen(false);
}
};

useEffect(() => {
fetchDoorStatus();
const interval = setInterval(fetchDoorStatus, 10000); // Fetch every 10 seconds
const interval = setInterval(fetchDoorStatus, 10000);
return () => clearInterval(interval);
}, []);

Expand Down

0 comments on commit 98683b3

Please sign in to comment.