diff --git a/backend/main.py b/backend/main.py index 68f44c3..63a8e46 100644 --- a/backend/main.py +++ b/backend/main.py @@ -206,7 +206,12 @@ async def get_events(limit: int = 10, offset: int = 0): # Get paginated events async with db.execute( - "SELECT timestamp, action, source, success FROM events ORDER BY timestamp DESC LIMIT ? OFFSET ?", + """ + SELECT timestamp, action, source, success + FROM events + ORDER BY timestamp DESC, id DESC + LIMIT ? OFFSET ? + """, (limit, offset) ) as cursor: events = [ @@ -222,7 +227,7 @@ async def get_events(limit: int = 10, offset: int = 0): return { "events": events, "total": total, - "hasMore": total > (offset + limit) + "hasMore": offset + len(events) < total } except Exception as e: logger.error(f"Failed to get events: {e}", exc_info=True) diff --git a/backend/mqtt_integration.py b/backend/mqtt_integration.py index 65bb3a1..3127203 100644 --- a/backend/mqtt_integration.py +++ b/backend/mqtt_integration.py @@ -198,6 +198,10 @@ class HomeAssistantMQTT: """Set callback for handling commands""" self.command_callback = callback + def is_connected(self) -> bool: + """Return current connection status""" + return self._connected + def update_settings(self, settings): """Update MQTT settings""" logger.info(f"Updating MQTT settings - Broker: {settings.broker}:{settings.port}") diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index b78f427..0f42465 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -117,9 +117,11 @@ function App() { const handleLoadMore = async () => { try { const moreEvents = await api.getEvents(10, events.length); - setEvents(prev => [...prev, ...moreEvents.events]); - setHasMoreEvents(moreEvents.hasMore); - setTotalEvents(moreEvents.total); + if (moreEvents.events.length > 0) { + setEvents(prev => [...prev, ...moreEvents.events]); + setHasMoreEvents(moreEvents.hasMore); + setTotalEvents(moreEvents.total); + } } catch (err) { setError('Failed to load more events'); console.error(err);