mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-15 17:12:59 -04:00
update all rovers buttone
This commit is contained in:
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -78,7 +78,7 @@
|
||||
<script defer src="https://analytics.otter.land/script.js" data-website-id="82dd56a5-db44-4279-bd1e-a4d9fee39af7" data-domains="rover.otter.land"></script>
|
||||
<script defer src="https://analytics.otter.land/recorder.js" data-website-id="82dd56a5-db44-4279-bd1e-a4d9fee39af7" data-domains="rover.otter.land" data-sample-rate="0.15" data-mask-level="moderate" data-max-duration="300000"></script>
|
||||
<title>Roomba Rover</title>
|
||||
<script type="module" crossorigin src="/assets/index-D5vPzVhj.js"></script>
|
||||
<script type="module" crossorigin src="/assets/index-DrMv7S5j.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/assets/index-BN3kEVFL.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@@ -106,6 +106,28 @@ function handleAck(msg) {
|
||||
});
|
||||
}
|
||||
|
||||
function issueUpdateToAllRovers() {
|
||||
const updated = [];
|
||||
const failed = [];
|
||||
|
||||
roverManager.rovers.forEach((record) => {
|
||||
if (!record?.ws) return;
|
||||
|
||||
const roverId = String(record.id);
|
||||
try {
|
||||
// Use the same narrow update payload as the per-rover admin action. The
|
||||
// browser only asks for "update all"; the Pi still owns the privileged
|
||||
// pull/install/reboot sequence through its fixed self-update helper.
|
||||
issueCommand(roverId, { type: 'update', update: {} });
|
||||
updated.push(roverId);
|
||||
} catch (err) {
|
||||
failed.push({ roverId, error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
return { updated, failed };
|
||||
}
|
||||
|
||||
function getRecentDriveActivity(windowMs, options = {}) {
|
||||
const now = Date.now();
|
||||
const results = [];
|
||||
@@ -288,6 +310,26 @@ io.on('connection', (socket) => {
|
||||
|
||||
socket.on('command', handleCommand);
|
||||
socket.on('command:issue', handleCommand);
|
||||
|
||||
socket.on('command:updateAllRovers', (_payload = {}, cb) => {
|
||||
const reply = typeof cb === 'function' ? cb : () => {};
|
||||
try {
|
||||
if (!isAdmin(socket)) {
|
||||
throw new Error('Not authorized');
|
||||
}
|
||||
|
||||
const result = issueUpdateToAllRovers();
|
||||
logger.warn('Admin requested update for all online rovers', {
|
||||
socketId: socket.id,
|
||||
updated: result.updated,
|
||||
failed: result.failed,
|
||||
});
|
||||
reply(result);
|
||||
} catch (err) {
|
||||
logger.warn('Update-all rovers rejected', socket.id, err.message);
|
||||
reply({ error: err.message });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
homeAssistantService.homeAssistantEvents.on('update', () => {
|
||||
|
||||
Reference in New Issue
Block a user