mirror of
https://github.com/bringout/oca-technical.git
synced 2026-04-21 20:32:09 +02:00
Initial commit: OCA Technical packages (595 packages)
This commit is contained in:
commit
2cc02aac6e
24950 changed files with 2318079 additions and 0 deletions
|
|
@ -0,0 +1,4 @@
|
|||
from . import iot_amqp_host
|
||||
from . import iot_device_output
|
||||
from . import iot_communication_system_action
|
||||
from . import iot_device_output_action
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
# Copyright 2020 Creu Blanca
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class IotAmqpHost(models.Model):
|
||||
_name = "iot.amqp.host"
|
||||
_description = "Amqp Host"
|
||||
|
||||
name = fields.Char(required=True)
|
||||
connection = fields.Char()
|
||||
active = fields.Boolean(default=True)
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
from odoo import models
|
||||
|
||||
|
||||
class IoTCommunicationSystemAction(models.Model):
|
||||
_inherit = "iot.communication.system.action"
|
||||
|
||||
def _run(self, device_action):
|
||||
if self != self.env.ref("iot_amqp_oca.amqp_action"):
|
||||
return super()._run(device_action)
|
||||
device_action._run_amqp()
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class IotDeviceOutput(models.Model):
|
||||
_inherit = "iot.device.output"
|
||||
|
||||
amqp_exchange = fields.Char()
|
||||
amqp_routing_key = fields.Char()
|
||||
amqp_payload = fields.Char()
|
||||
amqp_host_id = fields.Many2one(
|
||||
"iot.amqp.host",
|
||||
)
|
||||
|
||||
@api.constrains(
|
||||
"amqp_exchange", "amqp_routing_key", "amqp_host_id", "communication_system_id"
|
||||
)
|
||||
def _check_amqp(self):
|
||||
amqp_system = self.env.ref("iot_amqp_oca.amqp_system")
|
||||
for rec in self:
|
||||
if rec.communication_system_id == amqp_system:
|
||||
if not rec.amqp_exchange:
|
||||
raise ValidationError(_("Exchange is required"))
|
||||
if not rec.amqp_routing_key:
|
||||
raise ValidationError(_("Routing Key is required"))
|
||||
if not rec.amqp_host_id:
|
||||
raise ValidationError(_("Host is required"))
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
# Copyright 2020 Creu Blanca
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
import logging
|
||||
|
||||
from odoo import models
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
try:
|
||||
from pika import BlockingConnection, URLParameters, spec
|
||||
except (ImportError, IOError) as err:
|
||||
_logger.debug(err)
|
||||
|
||||
|
||||
class IotDeviceOutputAction(models.Model):
|
||||
_inherit = "iot.device.output.action"
|
||||
|
||||
def _run_amqp(self):
|
||||
url = self.output_id.amqp_host_id.connection
|
||||
connection = BlockingConnection(URLParameters(url))
|
||||
channel = connection.channel()
|
||||
result = channel.basic_publish(**self._generate_amqp_data())
|
||||
_logger.debug(result)
|
||||
connection.close()
|
||||
|
||||
def _generate_amqp_data(self):
|
||||
return {
|
||||
"exchange": self.output_id.amqp_exchange,
|
||||
"routing_key": self.output_id.amqp_routing_key,
|
||||
"body": self.output_id.amqp_payload,
|
||||
"properties": spec.BasicProperties(),
|
||||
"mandatory": False,
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue