Fixed MQTT commands and frontend event loading
- Fixed MQTT command handling by properly handling async callbacks - Fixed frontend event loading to preserve loaded events - Added proper state tracking for initial load - Fixed useEffect dependencies
This commit is contained in:
parent
3e2511f019
commit
b372618cf7
|
|
@ -98,7 +98,8 @@ class HomeAssistantMQTT:
|
||||||
if topic == self.command_topic and self.command_callback:
|
if topic == self.command_topic and self.command_callback:
|
||||||
command = decoded_payload.upper()
|
command = decoded_payload.upper()
|
||||||
logger.debug(f"Processing command: {command}")
|
logger.debug(f"Processing command: {command}")
|
||||||
self.command_callback(command)
|
# Create task for async callback
|
||||||
|
asyncio.create_task(self.command_callback(command))
|
||||||
else:
|
else:
|
||||||
logger.debug(f"Message received on non-command topic: {topic}")
|
logger.debug(f"Message received on non-command topic: {topic}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ function App() {
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
const [isSettingsOpen, setIsSettingsOpen] = useState(false);
|
const [isSettingsOpen, setIsSettingsOpen] = useState(false);
|
||||||
|
const [isInitialLoad, setIsInitialLoad] = useState(true);
|
||||||
|
|
||||||
const formatDate = (isoString: string) => {
|
const formatDate = (isoString: string) => {
|
||||||
const date = new Date(isoString);
|
const date = new Date(isoString);
|
||||||
|
|
@ -52,6 +53,7 @@ function App() {
|
||||||
setTotalEvents(eventsData.total);
|
setTotalEvents(eventsData.total);
|
||||||
setSettings(settingsData);
|
setSettings(settingsData);
|
||||||
setGateStatus(statusData);
|
setGateStatus(statusData);
|
||||||
|
setIsInitialLoad(false);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setError('Failed to load data');
|
setError('Failed to load data');
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
|
@ -67,8 +69,8 @@ function App() {
|
||||||
]);
|
]);
|
||||||
setGateStatus(statusData);
|
setGateStatus(statusData);
|
||||||
|
|
||||||
// Update only if we're on the first page and don't have more events loaded
|
// Only update events if this is the initial load or we haven't loaded more
|
||||||
if (events.length <= 10 && !hasMoreEvents) {
|
if (isInitialLoad || (!hasMoreEvents && events.length <= 10)) {
|
||||||
setEvents(eventsData.events);
|
setEvents(eventsData.events);
|
||||||
setHasMoreEvents(eventsData.hasMore);
|
setHasMoreEvents(eventsData.hasMore);
|
||||||
setTotalEvents(eventsData.total);
|
setTotalEvents(eventsData.total);
|
||||||
|
|
@ -91,10 +93,13 @@ function App() {
|
||||||
}
|
}
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
|
||||||
|
// Only do initial load if we haven't loaded yet
|
||||||
|
if (isInitialLoad) {
|
||||||
loadData();
|
loadData();
|
||||||
|
}
|
||||||
|
|
||||||
return () => clearInterval(interval);
|
return () => clearInterval(interval);
|
||||||
}, []);
|
}, [events, hasMoreEvents, isInitialLoad]);
|
||||||
|
|
||||||
const handleGateControl = async () => {
|
const handleGateControl = async () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue