Files
full_encoach_platform/odoo/addons/iot_drivers/driver.py
Yamen Ahmad 3e83d8d7d5 feat: add complete EnCoach backend — Odoo 19 + all addons
Includes:
- Odoo 19 framework (odoo/)
- 27 custom EnCoach addons (new_project/custom_addons/)
  - encoach_core, encoach_api, encoach_lms_api, encoach_adaptive_api
  - encoach_exam, encoach_taxonomy, encoach_adaptive, encoach_assignment
  - encoach_ai, encoach_ai_grading, encoach_ai_generation, encoach_ai_media
  - encoach_courseware, encoach_communication, encoach_subscription
  - encoach_notification, encoach_approval, encoach_branding
  - encoach_classroom, encoach_registration, encoach_stats
  - encoach_faq, encoach_ticket, encoach_training, encoach_resources
  - encoach_adaptive_ai, encoach_sis
- 21 OpenEduCat Enterprise modules (new_project/enterprise-19/)
- 14 OpenEduCat Community modules (new_project/openeducat_erp-19.0/)
- Configuration: odoo.conf, requirements.txt, scripts
- 200+ REST API endpoints with JWT authentication
- SRS and test documentation

Made-with: Cursor
2026-04-01 17:10:04 +04:00

81 lines
3.0 KiB
Python

# Part of Odoo. See LICENSE file for full copyright and licensing details.
import logging
from threading import Thread, Event
from odoo.addons.iot_drivers.main import drivers, iot_devices
from odoo.addons.iot_drivers.event_manager import event_manager
from odoo.addons.iot_drivers.tools.helpers import toggleable
from odoo.tools.lru import LRU
_logger = logging.getLogger(__name__)
class Driver(Thread):
"""Hook to register the driver into the drivers list"""
connection_type = ''
priority = 0
def __init__(self, identifier, device):
super().__init__(daemon=True)
self.dev = device
self.device_identifier = identifier
self.device_name = ''
self.device_connection = ''
self.device_type = ''
self.device_manufacturer = ''
self.data = {'value': '', 'result': ''} # TODO: deprecate "value"?
self._actions = {}
self._stopped = Event()
self._recent_action_ids = LRU(256)
def __init_subclass__(cls):
super().__init_subclass__()
if cls not in drivers:
drivers.append(cls)
@classmethod
def supported(cls, device):
"""
On specific driver override this method to check if device is supported or not
return True or False
"""
return False
@toggleable
def action(self, data):
"""Helper function that calls a specific action method on the device.
:param dict data: the action method name and the parameters to be passed to it
:return: the result of the action method
"""
action = data.get('action', '')
action_unique_id = data.get('action_unique_id')
if action_unique_id:
if action_unique_id in self._recent_action_ids:
_logger.warning("Duplicate action %s id %s received, ignoring", action, action_unique_id)
return
self._recent_action_ids[action_unique_id] = action_unique_id
session_id = data.get('session_id')
if session_id:
self.data["owner"] = session_id
self.data["session_id"] = session_id
base_response = {'action_args': {**data}, 'session_id': data.get('session_id')}
try:
response = {'status': 'success', 'result': self._actions[action](data), **base_response}
except Exception as e:
if action_unique_id:
self._recent_action_ids.pop(action_unique_id, None)
_logger.exception("Error while executing action %s with params %s", action, data)
response = {'status': 'error', 'result': str(e), **base_response}
# Make response available to /event route or websocket
# printers and payment terminals handle their own events (low on paper, waiting for card, etc.)
if self.device_type not in ["printer", "payment"]:
event_manager.device_changed(self, response)
def disconnect(self):
self._stopped.set()
del iot_devices[self.device_identifier]