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:
BIN
fusion_iot/iot/tests/.___init__.py
Normal file
BIN
fusion_iot/iot/tests/.___init__.py
Normal file
Binary file not shown.
BIN
fusion_iot/iot/tests/._common.py
Normal file
BIN
fusion_iot/iot/tests/._common.py
Normal file
Binary file not shown.
BIN
fusion_iot/iot/tests/._data
Executable file
BIN
fusion_iot/iot/tests/._data
Executable file
Binary file not shown.
BIN
fusion_iot/iot/tests/._test_ingenico_driver.py
Normal file
BIN
fusion_iot/iot/tests/._test_ingenico_driver.py
Normal file
Binary file not shown.
BIN
fusion_iot/iot/tests/._test_printer_tour.py
Normal file
BIN
fusion_iot/iot/tests/._test_printer_tour.py
Normal file
Binary file not shown.
3
fusion_iot/iot/tests/__init__.py
Normal file
3
fusion_iot/iot/tests/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from . import common
|
||||
from . import test_printer_tour
|
||||
from . import test_ingenico_driver
|
||||
64
fusion_iot/iot/tests/common.py
Normal file
64
fusion_iot/iot/tests/common.py
Normal file
@@ -0,0 +1,64 @@
|
||||
import json
|
||||
from odoo.tests import HttpCase
|
||||
from unittest.mock import patch
|
||||
|
||||
from odoo.addons.iot.models.iot_channel import IotChannel
|
||||
|
||||
|
||||
class IotCommonTest(HttpCase):
|
||||
iot_websocket_messages = []
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
cls.shop_iot_box = cls.env['iot.box'].sudo().create({
|
||||
'name': 'Shop',
|
||||
'identifier': 'test_iot_box',
|
||||
'ip': '10.10.10.10',
|
||||
'version': '25.07',
|
||||
})
|
||||
|
||||
cls.iot_receipt_printer = cls.env['iot.device'].sudo().create({
|
||||
'name': 'Receipt Printer',
|
||||
'identifier': 'printer_identifier',
|
||||
'iot_id': cls.shop_iot_box.id,
|
||||
'type': 'printer',
|
||||
'subtype': 'receipt_printer',
|
||||
'connection': 'network',
|
||||
'connected_status': 'connected',
|
||||
})
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
original_send_message = IotChannel.send_message
|
||||
|
||||
def mock_send_message(iot_channel_record, message, message_type='iot_action'):
|
||||
self.iot_websocket_messages.append({message_type: message})
|
||||
if message_type == 'iot_action':
|
||||
# call the websocket response controller to simulate the response from the IoT Box
|
||||
return self.url_open(
|
||||
'/iot/box/send_websocket',
|
||||
headers={'Content-Type': 'application/json'},
|
||||
data=json.dumps({
|
||||
'params': {
|
||||
'session_id': message['session_id'],
|
||||
'iot_box_identifier': message['iot_identifiers'][0],
|
||||
'device_identifier': message['device_identifiers'][0],
|
||||
'status': 'success',
|
||||
},
|
||||
}),
|
||||
)
|
||||
return original_send_message(iot_channel_record, message, message_type)
|
||||
|
||||
def mock_get_iot_channel(_iot_channel_record):
|
||||
return "mock_iot_channel"
|
||||
|
||||
mock_get_iot_channel._api_model = True
|
||||
mock_send_message._api_model = True
|
||||
|
||||
send_message_patcher = patch.object(IotChannel, 'send_message', mock_send_message)
|
||||
channel_patcher = patch.object(IotChannel, 'get_iot_channel', mock_get_iot_channel)
|
||||
self.addCleanup(send_message_patcher.stop)
|
||||
self.addCleanup(channel_patcher.stop)
|
||||
send_message_patcher.start()
|
||||
channel_patcher.start()
|
||||
BIN
fusion_iot/iot/tests/data/._TransactionResponse
Normal file
BIN
fusion_iot/iot/tests/data/._TransactionResponse
Normal file
Binary file not shown.
BIN
fusion_iot/iot/tests/data/TransactionResponse
Normal file
BIN
fusion_iot/iot/tests/data/TransactionResponse
Normal file
Binary file not shown.
101
fusion_iot/iot/tests/test_ingenico_driver.py
Normal file
101
fusion_iot/iot/tests/test_ingenico_driver.py
Normal file
@@ -0,0 +1,101 @@
|
||||
from unittest.mock import MagicMock, patch
|
||||
from zlib import crc32
|
||||
|
||||
from odoo.tests.common import BaseCase
|
||||
from odoo.tools import file_open
|
||||
|
||||
|
||||
class MockSocket:
|
||||
def __init__(self, f):
|
||||
self.f = f
|
||||
|
||||
def recv(self, num_bytes):
|
||||
return self.f.read(num_bytes)
|
||||
|
||||
|
||||
class TestIncomingTransactionResponse(BaseCase):
|
||||
@patch.dict(
|
||||
"sys.modules", {
|
||||
# Mock out all of iot_drivers to avoid side-effects from starting services,
|
||||
# additional dependencies and modifying global imports
|
||||
"odoo.addons.iot_drivers": MagicMock(),
|
||||
# Mock the modules IngenicoDriver imports so the imports don't fail
|
||||
"odoo.addons.iot_drivers.driver": MagicMock(),
|
||||
"odoo.addons.iot_drivers.event_manager": MagicMock(),
|
||||
"odoo.addons.iot_drivers.iot_handlers.interfaces.SocketInterface": MagicMock(),
|
||||
}
|
||||
)
|
||||
def setUp(self):
|
||||
# pylint: disable=import-outside-toplevel
|
||||
from odoo.addons.iot.iot_handlers.drivers.IngenicoDriver import IncomingIngenicoMessage
|
||||
self.IncomingIngenicoMessage = IncomingIngenicoMessage
|
||||
|
||||
def test_parse_ticketdata(self):
|
||||
# The file contains the payload of a TLV message. To view or modify its
|
||||
# contents, use a hex editor and the TLV Cash Register Interface specification
|
||||
# to interpret it. Most of the data has been anonymized.
|
||||
with file_open('iot/tests/data/TransactionResponse', 'rb') as f:
|
||||
dev = MockSocket(f)
|
||||
msg = self.IncomingIngenicoMessage(dev)
|
||||
ticket_data = msg.getTransactionTicket()
|
||||
|
||||
# First expected string in the ticket data
|
||||
assert b'KOPIE' in ticket_data
|
||||
# Last expected string in the ticket data
|
||||
assert b'Chip' in ticket_data
|
||||
|
||||
|
||||
class TestOutgoingIngenicoMessage(BaseCase):
|
||||
@patch.dict(
|
||||
"sys.modules", {
|
||||
# Mock out all of iot_drivers to avoid side-effects from starting services,
|
||||
# additional dependencies and modifying global imports
|
||||
"odoo.addons.iot_drivers": MagicMock(),
|
||||
# Mock the modules IngenicoDriver imports so the imports don't fail
|
||||
"odoo.addons.iot_drivers.driver": MagicMock(),
|
||||
"odoo.addons.iot_drivers.event_manager": MagicMock(),
|
||||
"odoo.addons.iot_drivers.iot_handlers.interfaces.SocketInterface": MagicMock(),
|
||||
}
|
||||
)
|
||||
def setUp(self):
|
||||
# pylint: disable=import-outside-toplevel
|
||||
from odoo.addons.iot.iot_handlers.drivers.IngenicoDriver import OutgoingIngenicoMessage
|
||||
|
||||
self.OutgoingIngenicoMessage = OutgoingIngenicoMessage
|
||||
self.dev = MagicMock()
|
||||
self.msg = self.OutgoingIngenicoMessage(
|
||||
dev=self.dev,
|
||||
terminalId=b"1",
|
||||
ecrId="1",
|
||||
protocolId=b"1",
|
||||
messageType="TransactionRequest",
|
||||
sequence=b"1",
|
||||
transactionId=1,
|
||||
amount=1,
|
||||
)
|
||||
|
||||
def test_mdc_tag_length(self):
|
||||
# 1 byte for the tag + 1 byte for the length + 4 bytes for the CRC
|
||||
self.assertEqual(len(self.msg._generateMDC(b"dummy")), 6)
|
||||
|
||||
def test_unpadded_crc(self):
|
||||
content = bytes(11)
|
||||
|
||||
# An even length CRC (in nibbles), which doesn't require padding
|
||||
crc = format(crc32(content), 'x')
|
||||
self.assertEqual(crc, '6b87b1ec')
|
||||
self.assertEqual(len(crc), 8)
|
||||
|
||||
# Verify the CRC has the expected length and no errors are thrown
|
||||
self.assertEqual(len(self.msg._getCRC32(content)), 4)
|
||||
|
||||
def test_padded_crc(self):
|
||||
content = bytes(13)
|
||||
|
||||
# An odd length CRC (in nibbles), which does require padding
|
||||
crc = format(crc32(content), 'x')
|
||||
self.assertEqual(crc, 'f744682')
|
||||
self.assertEqual(len(crc), 7)
|
||||
|
||||
# Verify the CRC has the expected length and no errors are thrown
|
||||
self.assertEqual(len(self.msg._getCRC32(content)), 4)
|
||||
28
fusion_iot/iot/tests/test_printer_tour.py
Normal file
28
fusion_iot/iot/tests/test_printer_tour.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from odoo import tests
|
||||
|
||||
from odoo.addons.iot.tests.common import IotCommonTest
|
||||
|
||||
|
||||
@tests.tagged('post_install', '-at_install')
|
||||
class TestUi(IotCommonTest):
|
||||
iot_websocket_messages = []
|
||||
|
||||
def test_iot_device_test_button(self):
|
||||
"""Make sure we can use the websocket to test printers using the 'Test'
|
||||
button on the printer (iot.device) record."""
|
||||
self.start_tour("/odoo/iot", "iot_device_test_printer", login="admin")
|
||||
self.assertEqual(
|
||||
len(self.iot_websocket_messages),
|
||||
3,
|
||||
(
|
||||
"`iot.channel.send_message` should be called exactly three times: "
|
||||
"webrtc offer, websocket action, then operation confirmation."
|
||||
"This time, we received %s" % [next(iter(message.keys())) for message in self.iot_websocket_messages]
|
||||
),
|
||||
)
|
||||
self.assertIn(
|
||||
'webrtc_offer', self.iot_websocket_messages[0], "First ws message should be of type 'webrtc_offer'."
|
||||
)
|
||||
self.assertIn(
|
||||
'iot_action', self.iot_websocket_messages[1], "Second ws message should be of type 'iot_action'."
|
||||
)
|
||||
Reference in New Issue
Block a user