chore: import enterprise addons 19.0 bulk snapshot

This commit is contained in:
1b-agent committed 2026-09-16 10:13:08 +00:00
commit ca4af030d3
39951 files changed
+15570005

No files matched your search

@@ -0,0 +1,44 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import base64
import logging
import subprocess
from odoo.addons.iot_drivers.driver import Driver
_logger = logging.getLogger(__name__)
class CameraDriver(Driver):
connection_type = 'video'
def __init__(self, identifier, device):
super().__init__(identifier, device)
self.device_type = 'camera'
self.device_connection = 'direct'
self.device_name = device['name']
self.interface = device['interface']
self._actions.update({
'': self._action_default,
})
@classmethod
def supported(cls, device):
return bool(device['interface'])
def _action_default(self, _data):
"""Capture an image from the camera.
The resolution is set to 1920x1080, but will be lowered if not supported.
"""
# "-" to output to stdout (avoid writing to disk)
image = subprocess.run(
["fswebcam", "-d", self.interface, "-r", "1920x1080", "-"], capture_output=True, check=False
)
if image.returncode == 0:
return {
'image': base64.b64encode(image.stdout).decode(),
}
else:
_logger.error('Failed to capture image: %s', image.stderr.decode())
raise Exception('Failed to capture image from camera.')
@@ -0,0 +1,101 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import logging
import serial
import time
from odoo.addons.iot_drivers.event_manager import event_manager
from odoo.addons.iot_drivers.iot_handlers.drivers.serial_base_driver import SerialDriver, SerialProtocol, serial_connection
_logger = logging.getLogger(__name__)
SylvacSCalProProtocol = SerialProtocol(
name='Sylvac S_Cal pro',
baudrate=4800,
bytesize=serial.SEVENBITS,
stopbits=serial.STOPBITS_TWO,
parity=serial.PARITY_EVEN,
timeout=0.2,
writeTimeout=0.2,
measureRegexp=b'\\+|-\\d+\\.\\d+\r',
statusRegexp=None,
commandTerminator=b'\r',
commandDelay=0.2,
measureDelay=0.2,
newMeasureDelay=0.2,
measureCommand=b'?',
emptyAnswerValid=False,
)
class SylvacSCalProDriver(SerialDriver):
"""Driver For Sylvac's USB calipers."""
_protocol = SylvacSCalProProtocol
def __init__(self, identifier, device):
super().__init__(identifier, device)
self.device_type = 'device'
self._actions['read_once'] = self._action_read_once
def _action_read_once(self, _data):
"""Make value available to the longpolling event route"""
event_manager.device_changed(self)
def _take_measure(self):
"""Asks the device for a new value, and pushes that value to the frontend."""
with self._device_lock:
self._connection.write(self._protocol.measureCommand + self._protocol.commandTerminator)
measure = self._get_raw_response(self._connection)
if measure and measure != self.data['value']:
self.data['value'] = measure
event_manager.device_changed(self)
@staticmethod
def _get_raw_response(connection):
"""Gets a raw, unparsed string containing the updated value of the device.
:param connection: connection to the device's serial port
:type connection: pyserial.Serial
"""
TIMEOUT = 1
answer = []
t0 = time.time()
while True:
char = connection.read()
if char:
if ord(char) == 13:
return b''.join(answer[:-1]).decode('utf-8')
answer.append(char)
t0 = time.time()
elif time.time() - t0 > TIMEOUT:
return ""
@classmethod
def supported(cls, device):
"""Checks whether the device at path `device` is supported by the driver.
:param device: path to the device
:type device: str
:return: whether the device is supported by the driver
:rtype: bool
"""
protocol = cls._protocol
try:
with serial_connection(device['identifier'], protocol, is_probing=True) as connection:
connection.write(protocol.measureCommand + protocol.commandTerminator)
time.sleep(protocol.commandDelay)
measure = cls._get_raw_response(connection)
float(measure)
return True
except (ValueError, TypeError, serial.serialutil.SerialTimeoutException):
pass
except Exception:
_logger.exception('Error while probing %s with protocol %s', device, protocol.name)
return False
@@ -0,0 +1,75 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import dbus
from gatt import Device
import logging
from odoo.addons.iot_drivers.driver import Driver
from odoo.addons.iot_drivers.event_manager import event_manager
from odoo.addons.iot_drivers.iot_handlers.interfaces.BTInterface_L import bt_devices
_logger = logging.getLogger(__name__)
class SylvacBtDriver(Driver):
connection_type = 'bluetooth'
def __init__(self, identifier, device):
super().__init__(identifier, device)
self.gatt_device = GattSylvacBtDriver(mac_address=device.mac_address, manager=device.manager)
self.gatt_device.btdriver = self
self.gatt_device.connect()
self.device_type = 'device'
self.device_connection = 'bluetooth'
self.device_name = device.alias()
self._actions['read_once'] = self._action_read_once
def _action_read_once(self, _data):
"""Make value available to the longpolling event route"""
event_manager.device_changed(self)
@classmethod
def supported(cls, device):
try:
if device.alias() in ["SY295", "SY304", "SY276"]:
return True
except dbus.exceptions.DBusException as e:
_logger.warning(e.get_dbus_name())
_logger.warning(e.get_dbus_message())
return False
def disconnect(self):
super().disconnect()
del bt_devices[self.device_identifier]
class GattSylvacBtDriver(Device):
btdriver = False
def services_resolved(self):
super().services_resolved()
device_information_service = next(
s for s in self.services
if s.uuid == '00005000-0000-1000-8000-00805f9b34fb')
measurement_characteristic = next(
c for c in device_information_service.characteristics if c.uuid == '00005020-0000-1000-8000-00805f9b34fb')
measurement_characteristic.enable_notifications()
def characteristic_value_updated(self, characteristic, value):
total = value[0] + value[1] * 256 + value[2] * 256 * 256 + value[3] * 256 * 256 * 256
if total > 256 ** 4 / 2:
total = total - 256 ** 4
self.btdriver.data['value'] = total / 1000000.0
event_manager.device_changed(self.btdriver)
def characteristic_enable_notification_succeeded(self):
_logger.info("Successfully connected to %s", self.device_name)
def characteristic_enable_notification_failed(self):
_logger.info("Problem connecting to %s", self.device_name)
def disconnect_succeeded(self):
super().disconnect_succeeded()
self.btdriver.disconnect()