feat(iot): repackaged Odoo iot modules + Fusion Plating sensor wrapper
Phase A of the IoT initiative — gets the server-side infrastructure
in place before the Raspberry Pi hardware arrives, so the iot admin
UI + /fp/iot/ingest endpoint are ready to accept the first real
temperature reading as soon as the Pi is wired up.
New top-level folder: fusion_iot/
1. **iot_base/** — Odoo S.A. iot_base module, copied from
RePackaged-Odoo verbatim. LGPL-3 upstream, no changes needed.
2. **iot/** — Odoo S.A. iot module, repackaged:
- `models/update.py` neutralised (removed the publisher_warranty
IoT-Box-counting report that phones home to odoo.com for
enterprise licence enforcement)
- `iot_handlers/lib/load_worldline_library.sh` deleted (proprietary
Worldline payment lib fetch from download.odoo.com, not needed)
- `wizard/add_iot_box.py._connect_iot_box_with_pairing_code` —
upstream called odoo.com's iot-proxy to resolve pairing codes;
replaced with a no-op. Pi-side iot_drivers proxy registers
directly with this Odoo server instead.
- Manifest rebranded with an explicit changelog preamble.
3. **fusion_plating_iot/** — new plating-specific wrapper:
- `fp.tank.sensor` — maps an iot.device (or a direct-HTTP-ingest
sensor) to a fusion.plating.tank + fusion.plating.bath.parameter.
Supports DS18B20, PT100/1000, pH, conductivity, level. Per-sensor
alert_min/max overrides.
- `fp.tank.reading` — append-only time-series. On create, evaluates
against sensor's alert range. On in-spec → out-of-spec TRANSITION,
auto-raises a fusion.plating.quality.hold (once per excursion,
no spam during sustained out-of-spec).
- `POST /fp/iot/ingest` — shared-secret HTTP endpoint for sensors
bypassing the Pi proxy. Token via X-FP-IOT-Token header OR body.
Accepts single-reading or batch payloads.
- Menu under Plating → Operations → Sensors & Readings.
- Tank form inherits get a Sensors tab inline.
Deployed to entech. Verified end-to-end:
- Install: iot_base + iot + fusion_plating_iot all 'installed'
- Smoke test: in-spec → out-of-spec → hold raised (HOLD-0010);
continued excursion → NO duplicate hold; back-in-spec → NEW
excursion → NEW hold (HOLD-0011) ✓
- HTTP endpoint: correct token → 200 accepted; wrong token → 401;
unknown device_serial → 404; batch payload → 200 accepted=N ✓
Phase B (when Raspberry Pi hardware arrives): DS18B20 iot_handler
driver for the Pi-side iot_drivers proxy + systemd service on
vanilla Raspberry Pi OS + first live reading from physical probe.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Binary file not shown.
BIN
fusion_iot/iot/static/src/backend/._iot_device_form.js
Normal file
BIN
fusion_iot/iot/static/src/backend/._iot_device_form.js
Normal file
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,84 @@
|
||||
import { formView } from "@web/views/form/form_view";
|
||||
import { FormController } from "@web/views/form/form_controller";
|
||||
import { registry } from "@web/core/registry";
|
||||
import { useService } from "@web/core/utils/hooks";
|
||||
import { onMounted, onWillUnmount } from "@odoo/owl";
|
||||
import { _t } from "@web/core/l10n/translation";
|
||||
|
||||
|
||||
export class AddIoTBoxFormController extends FormController {
|
||||
setup() {
|
||||
super.setup();
|
||||
this.notification = useService("notification");
|
||||
this.orm = useService("orm");
|
||||
this.iotBoxesBeforeConnection = [];
|
||||
this.newIoTBoxes = []; // List of new IoT boxes found
|
||||
this.iotCheckTimer = null; // Timer to manage polling
|
||||
|
||||
onMounted(async () => {
|
||||
await this.initializeIoTConnection();
|
||||
});
|
||||
|
||||
onWillUnmount(() => {
|
||||
this.onWillUnmount();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a loop to check for new IoT Boxes every 10 seconds.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async initializeIoTConnection() {
|
||||
this.iotBoxesBeforeConnection = await this.orm.call("iot.box", "search_read", [[], ["identifier"]]);
|
||||
|
||||
// Set a timer to check for new IoT Boxes every 5 seconds
|
||||
this.iotCheckTimer = setInterval(async () => {
|
||||
if (await this.lookForNewIoTBox()) {
|
||||
this.notifyIoTBoxFound(true);
|
||||
clearInterval(this.iotCheckTimer);
|
||||
}
|
||||
}, 5000);
|
||||
|
||||
// Set a timeout to stop the polling after 2 minutes
|
||||
setTimeout(() => this.notifyIoTBoxFound(false), 60 * 2 * 1000);
|
||||
}
|
||||
|
||||
/**
|
||||
* Look for new IoT Boxes that have been connected since the last check.
|
||||
* @returns {Promise<boolean>} True if a new IoT Box has been found, false otherwise.
|
||||
*/
|
||||
async lookForNewIoTBox() {
|
||||
const iotBoxesAfterConnection = await this.orm.call("iot.box", "search_read", [[], ["identifier"]]);
|
||||
this.newIoTBoxes = iotBoxesAfterConnection.filter(
|
||||
(afterBox) => !this.iotBoxesBeforeConnection.some(
|
||||
beforeBox => beforeBox.identifier === afterBox.identifier
|
||||
)
|
||||
);
|
||||
|
||||
return this.newIoTBoxes.length > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify the user if a new IoT Box has been found. If no new IoT Box has been found, notify the user.
|
||||
* @param {boolean} found Whether a new IoT Box has been found.
|
||||
*/
|
||||
notifyIoTBoxFound(found) {
|
||||
if (found) {
|
||||
this.env.services.action.doAction({ type: "ir.actions.act_window_close" });
|
||||
this.notification.add(_t("New IoT Box connected!"), { type: "success" });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the timer when the component is unmounted.
|
||||
*/
|
||||
onWillUnmount() {
|
||||
if (this.iotCheckTimer) {
|
||||
clearInterval(this.iotCheckTimer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const addIoTBox = { ...formView, Controller: AddIoTBoxFormController };
|
||||
|
||||
registry.category("views").add('add_iot_box_wizard', addIoTBox);
|
||||
139
fusion_iot/iot/static/src/backend/iot_device_form.js
Normal file
139
fusion_iot/iot/static/src/backend/iot_device_form.js
Normal file
@@ -0,0 +1,139 @@
|
||||
import { registry } from "@web/core/registry";
|
||||
import { useService } from "@web/core/utils/hooks";
|
||||
import { formView } from "@web/views/form/form_view";
|
||||
import { _t } from "@web/core/l10n/translation";
|
||||
import { useSubEnv } from "@odoo/owl";
|
||||
import { PRINTER_MESSAGES, FDM_MESSAGES } from "@iot/network_utils/iot_http_service";
|
||||
import { printReport } from "@iot/iot_report_action";
|
||||
|
||||
class IoTDeviceController extends formView.Controller {
|
||||
setup() {
|
||||
super.setup();
|
||||
this.iotHttp = useService("iot_http");
|
||||
this.notification = useService("notification");
|
||||
this.orm = useService("orm");
|
||||
|
||||
useSubEnv({ onClickViewButton: this.onClickButtonTest.bind(this) });
|
||||
}
|
||||
|
||||
async onWillSaveRecord(record) {
|
||||
if (["keyboard", "scanner"].includes(record.data.type)) {
|
||||
await this.updateKeyboardLayout(record.data);
|
||||
} else if (record.data.type === "display") {
|
||||
await this.updateDisplayUrl(record.data);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Send an action to the device to update the keyboard layout
|
||||
*/
|
||||
async updateKeyboardLayout(data) {
|
||||
const { iot_id, identifier, keyboard_layout, is_scanner } = data;
|
||||
// IMPROVEMENT: Perhaps combine the call to update_is_scanner and update_layout in just one remote call to the iotbox.
|
||||
this.iotHttp.action(
|
||||
iot_id.id,
|
||||
identifier,
|
||||
{
|
||||
action: "update_is_scanner",
|
||||
is_scanner
|
||||
},
|
||||
() => {},
|
||||
() => {
|
||||
this.notification.add(_t("Failed to update scanner mode on the device."), {
|
||||
type: "danger"
|
||||
});
|
||||
}
|
||||
);
|
||||
if (keyboard_layout) {
|
||||
const [keyboard] = await this.model.orm.read(
|
||||
"iot.keyboard.layout",
|
||||
[keyboard_layout[0]],
|
||||
["layout", "variant"]
|
||||
);
|
||||
return this.iotHttp.action(
|
||||
iot_id.id,
|
||||
identifier,
|
||||
{
|
||||
action: "update_layout",
|
||||
layout: keyboard.layout,
|
||||
variant: keyboard.variant,
|
||||
},
|
||||
() => {},
|
||||
() => {
|
||||
this.notification.add(_t("Failed to update keyboard layout on the device."), {
|
||||
type: "danger"
|
||||
});
|
||||
}
|
||||
);
|
||||
} else {
|
||||
return this.iotHttp.action(iot_id.id, identifier, { action: "update_layout" });
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Send an action to the device to update the screen url
|
||||
*/
|
||||
async updateDisplayUrl(data) {
|
||||
const { iot_id, identifier, display_url } = data;
|
||||
return this.iotHttp.action(iot_id.id, identifier, { action: "update_url", url: display_url });
|
||||
}
|
||||
|
||||
onDeviceEvent(event, type) {
|
||||
const errorMessages = type === "printer" ? PRINTER_MESSAGES : FDM_MESSAGES;
|
||||
// Parse blackbonse response
|
||||
if (type === "fiscal_data_module") {
|
||||
const errorCode = event.message ? event.message.substring(0, 3) : event.result?.error?.errorCode;
|
||||
if (FDM_MESSAGES[errorCode] && !["000", "102"].includes(errorCode)) {
|
||||
event.message = errorCode
|
||||
event.status = "error";
|
||||
}
|
||||
}
|
||||
const errorMessage = errorMessages[event.message] ?? event.message;
|
||||
const defaultMessage = type === "printer" ? _t("Test page printed") : _t('Fiscal Data Module is connected and operational');
|
||||
switch (event.status) {
|
||||
case "error":
|
||||
this.notification.add(errorMessage, { type: "danger" });
|
||||
return;
|
||||
case "warning":
|
||||
this.notification.add(errorMessage, { type: "warning" });
|
||||
return;
|
||||
case "disconnected":
|
||||
this.notification.add(_t("Device is disconnected"), { type: "danger" });
|
||||
return;
|
||||
default:
|
||||
this.notification.add(defaultMessage, { type: "info" });
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
async onClickButtonTest(params) {
|
||||
if (params.clickParams.name === "test_device") {
|
||||
const { iot_id, identifier, type, subtype } = this.model.root.data;
|
||||
|
||||
if (type === "printer" && subtype === "office_printer") {
|
||||
// We print a "real" pdf report: the external report sample
|
||||
const reportId = (await this.orm.searchRead(
|
||||
"ir.actions.report",
|
||||
[["report_type", "=", "qweb-pdf"], ["report_name", "=", "web.preview_externalreport"]],
|
||||
["id"],
|
||||
{ limit: 1 }
|
||||
))[0].id;
|
||||
const deviceId = this.model.root._config.resId;
|
||||
return printReport(this.env, [reportId, [deviceId], null], [deviceId]);
|
||||
}
|
||||
|
||||
return this.iotHttp.action(
|
||||
iot_id.id,
|
||||
identifier,
|
||||
{ action: "status" },
|
||||
(event) => this.onDeviceEvent(event, type),
|
||||
(event) => this.onDeviceEvent(event, type),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const iotDeviceFormView = {
|
||||
...formView,
|
||||
Controller: IoTDeviceController,
|
||||
};
|
||||
|
||||
registry.category("views").add("iot_device_form", iotDeviceFormView);
|
||||
@@ -0,0 +1,64 @@
|
||||
import { discoverIotBoxes } from "@iot/client_action/discover_iot_boxes";
|
||||
import { formView } from "@web/views/form/form_view";
|
||||
import { FormController } from "@web/views/form/form_controller";
|
||||
import { registry } from "@web/core/registry";
|
||||
import { onMounted, onWillUnmount } from "@odoo/owl";
|
||||
import { _t } from "@web/core/l10n/translation";
|
||||
import { useService } from "@web/core/utils/hooks";
|
||||
|
||||
|
||||
export class NoIoTBoxFoundFormController extends FormController {
|
||||
setup() {
|
||||
super.setup();
|
||||
this.actionService = useService("action");
|
||||
this.retryDiscoverInterval = null;
|
||||
|
||||
onMounted(() => {
|
||||
this.startCountdown(15);
|
||||
});
|
||||
|
||||
onWillUnmount(() => {
|
||||
if (this.retryDiscoverInterval) {
|
||||
clearInterval(this.retryDiscoverInterval);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and show a countdown. When it reaches 0 we look for new IoT Boxes again
|
||||
*/
|
||||
startCountdown(seconds) {
|
||||
const countdownSpinner = document.getElementById("discover_retry_spinner");
|
||||
const countdownEl = document.getElementById("discover_retry_countdown");
|
||||
const textToDisplay = _t("Retrying in ")
|
||||
let timeLeft = seconds;
|
||||
if (countdownEl) {
|
||||
countdownEl.textContent = `${textToDisplay}${timeLeft}s`;
|
||||
this.retryDiscoverInterval = setInterval(async () => {
|
||||
timeLeft--;
|
||||
countdownEl.textContent = `${textToDisplay}${timeLeft}s`;
|
||||
// Look for new IoT Boxes again
|
||||
if (timeLeft <= 0) {
|
||||
countdownEl.textContent = `${textToDisplay}0s`;
|
||||
const nextAction = await discoverIotBoxes(this.env)
|
||||
if (!nextAction.no_iot_found_found) {
|
||||
await this.actionService.doAction(nextAction);
|
||||
}
|
||||
timeLeft = seconds + 1;
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
// Clear the countdown and interval
|
||||
setTimeout(() => {
|
||||
if (countdownEl) {
|
||||
countdownSpinner.classList.add("o_hidden");
|
||||
countdownEl.textContent = null;
|
||||
clearInterval(this.retryDiscoverInterval);
|
||||
}
|
||||
}, 60 * 5 * 1000);
|
||||
}
|
||||
}
|
||||
|
||||
export const noIoTBoxFound = { ...formView, Controller: NoIoTBoxFoundFormController };
|
||||
|
||||
registry.category("views").add('no_iot_box_found_wizard', noIoTBoxFound);
|
||||
Reference in New Issue
Block a user