Repository: OCA/iot (language: python)

Issue:
[MIG] iot_output_oca: Migration to 13.0 
Standard Migration

Change of module name

Depends on #26 


Discussion / hints:

Fix patch:
diff --git a/iot_input_oca/README.rst b/iot_input_oca/README.rst
new file mode 100644
index 00000000..26438480
--- /dev/null
+++ b/iot_input_oca/README.rst
@@ -0,0 +1,154 @@
+=========
+IoT Input
+=========
+
+.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+   !! This file is generated by oca-gen-addon-readme !!
+   !! changes will be overwritten.                   !!
+   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
+    :target: https://odoo-community.org/page/development-status
+    :alt: Beta
+.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
+    :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
+    :alt: License: AGPL-3
+.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fiot-lightgray.png?logo=github
+    :target: https://github.com/OCA/iot/tree/12.0/iot_input
+    :alt: OCA/iot
+.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
+    :target: https://translation.odoo-community.org/projects/iot-12-0/iot-12-0-iot_input
+    :alt: Translate me on Weblate
+.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
+    :target: https://runbot.odoo-community.org/runbot/269/12.0
+    :alt: Try me on Runbot
+
+|badge1| |badge2| |badge3| |badge4| |badge5| 
+
+This addon allows to use a device in order to input data to odoo automatically.
+
+It opens a URL that a device can use to connect (with a password) that can only
+execute an specific action.
+
+Inputs are useful when a device wants to communicate to odoo for a single
+and simple action.
+This way, the device does not need to be configured with a odoo user and
+password, it is handled by odoo devices.
+
+Examples:
+
+* Sending the temperature every three minutes.
+* Sending the RFID that the device has received in order to perform some action
+
+**Table of contents**
+
+.. contents::
+   :local:
+
+Usage
+=====
+
+There are two endpoints you can use:
+Endpoint 1: /iot/<serial>/action
+
+Takes `application/x-www-form-urlencoded` parameters:
+passphase, value (where value is a JSON object)
+
+1. Create a Device on `IoT > Config Devices`
+2. Access the Inputs section of the device
+3. Create an input. You must define a serial, passphrase, function and model
+
+The function that the system will call must be of the following kind::
+
+    @api.model
+        def call_function(self, key):
+        return {}
+
+Where `key` is the input string send by the device and the result must be a dictionary
+that will be responded to the device as a JSON.
+
+Endpoint 2: /iot/<device_identification>/multi_input
+It can be used to send values with multiple data in one POST request such as:
+- Values for inputs of the same device with different address (multi input)
+- Values for inputs of the same device with same address, different values (multi event)
+- Mix of the above (multi input, multi event)
+
+Takes `application/x-www-form-urlencoded` parameters:
+passphase, values (a JSON array of JSON objects)
+
+It is called using device_identification and passing two POST parameters: device passphrase and
+a JSON string containing an array of values for input
+- The value for the `address` key can be a string or a numeric (to conserve bytes in memory
+restricted devices when creating the JSON object) and is converted to string when parsing.
+- The value for the `value` key can either be string, number or boolean according to
+JSON specs.
+You can see an example of a valid JSON input object in the examples folder, using a few
+combinations.
+
+It requires the function that the system will call must be of the following kind::
+
+    @api.model
+        def call_function(self, key):
+        'do something
+        if err:
+            return {'status': 'error', 'message': 'The error message you want to send to the device'}
+        return {'status': 'ok', 'message': 'Optional success message'}
+
+Where `key` is a dict send by the device having at least value for keys: 'address', 'value'
+
+The function must always return a JSON with status and message. If value contains a value
+with 'uuid' as key, it is returned along with the object for the IoT device to identify
+success/failure per record.
+
+It has full error reporting and the return value is a JSON array of dicts containing at
+least status and message. Error message respose is at some points generic, though
+extended logging is done in Odoo server logs.
+
+Bug Tracker
+===========
+
+Bugs are tracked on `GitHub Issues <https://github.com/OCA/iot/issues>`_.
+In case of trouble, please check there if your issue has already been reported.
+If you spotted it first, help us smashing it by providing a detailed and welcomed
+`feedback <https://github.com/OCA/iot/issues/new?body=module:%20iot_input%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
+
+Do not contact contributors directly about support or help with technical issues.
+
+Credits
+=======
+
+Authors
+~~~~~~~
+
+* Creu Blanca
+
+Contributors
+~~~~~~~~~~~~
+
+* Enric Tobella <etobella@creublanca.es>
+* Dimitrios Tanis <dtanis@tanisfood.gr>
+
+Maintainers
+~~~~~~~~~~~
+
+This module is maintained by the OCA.
+
+.. image:: https://odoo-community.org/logo.png
+   :alt: Odoo Community Association
+   :target: https://odoo-community.org
+
+OCA, or the Odoo Community Association, is a nonprofit organization whose
+mission is to support the collaborative development of Odoo features and
+promote its widespread use.
+
+.. |maintainer-etobella| image:: https://github.com/etobella.png?size=40px
+    :target: https://github.com/etobella
+    :alt: etobella
+
+Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
+
+|maintainer-etobella| 
+
+This module is part of the `OCA/iot <https://github.com/OCA/iot/tree/12.0/iot_input>`_ project on GitHub.
+
+You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
diff --git a/iot_input_oca/__init__.py b/iot_input_oca/__init__.py
new file mode 100644
index 00000000..5607426d
--- /dev/null
+++ b/iot_input_oca/__init__.py
@@ -0,0 +1,2 @@
+from . import models
+from . import controller
diff --git a/iot_input_oca/__manifest__.py b/iot_input_oca/__manifest__.py
new file mode 100644
index 00000000..a6b1f209
--- /dev/null
+++ b/iot_input_oca/__manifest__.py
@@ -0,0 +1,18 @@
+# Copyright (C) 2018 Creu Blanca
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
+{
+    "name": "IoT Input",
+    "version": "13.0.1.0.0",
+    "category": "IoT",
+    "author": "Creu Blanca, Odoo Community Association (OCA)",
+    "license": "AGPL-3",
+    "installable": True,
+    "summary": "IoT Input module",
+    "depends": ["iot_output_oca", "mail"],
+    "maintainers": ["etobella"],
+    "data": [
+        "security/ir.model.access.csv",
+        "views/iot_device_views.xml",
+        "views/iot_device_input_views.xml",
+    ],
+}
diff --git a/iot_input_oca/controller/__init__.py b/iot_input_oca/controller/__init__.py
new file mode 100644
index 00000000..c204f049
--- /dev/null
+++ b/iot_input_oca/controller/__init__.py
@@ -0,0 +1,1 @@
+from . import iot_input_controller
diff --git a/iot_input_oca/controller/iot_input_controller.py b/iot_input_oca/controller/iot_input_controller.py
new file mode 100644
index 00000000..a6b01412
--- /dev/null
+++ b/iot_input_oca/controller/iot_input_controller.py
@@ -0,0 +1,98 @@
+# Copyright 2018 Creu Blanca
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
+
+import json
+import logging
+
+from odoo import _, http
+
+_logger = logging.getLogger(__name__)
+
+
+class CallIot(http.Controller):
+    @http.route(
+        ["/iot/<serial>/action"],
+        type="http",
+        auth="none",
+        methods=["POST"],
+        csrf=False,
+    )
+    def call_unauthorized_iot(self, serial, *args, **kwargs):
+        request = http.request
+        if not request.env:
+            return json.dumps(False)
+        return json.dumps(
+            request.env["iot.device.input"]
+            .sudo()
+            .get_device(serial, kwargs["passphrase"])
+            .call_device(kwargs["value"])
+        )
+
+    @http.route(
+        ["/iot/<device_identification>/multi_input"],
+        type="http",
+        auth="none",
+        methods=["POST"],
+        csrf=False,
+    )
+    def call_unauthorized_iot_multi_input(self, device_identification, *args, **kwargs):
+        """Controller to write multiple input data to device inputs
+
+        :param string passphrase:
+            Device passphrase in POST data.
+
+        :param string values:
+            JSON formatted string containing a JSON an array of JSON objects.
+        """
+        request = http.request
+        if not request.env:
+            _logger.warning("env not set")
+            return json.dumps({"status": "error", "message": _("Server Error")})
+        if "passphrase" not in kwargs:
+            _logger.warning("Passphrase is required")
+            return json.dumps(
+                {"status": "error", "message": _("Passphrase is required")}
+            )
+        if "values" not in kwargs:
+            _logger.warning("Values is required")
+            return json.dumps({"status": "error", "message": _("Values is required")})
+        # Decode JSON object here and use pure python objects in further calls
+        try:
+            values = json.loads(kwargs["values"])
+            if not isinstance(values, list):
+                raise SyntaxError
+        except json.decoder.JSONDecodeError:
+            _logger.warning("Values is not a valid JSON")
+            return json.dumps(
+                {"status": "error", "message": _("Values is not a valid JSON")}
+            )
+        except SyntaxError:
+            _logger.warning("Values should be a JSON array of JSON objects")
+            return json.dumps(
+                {
+                    "status": "error",
+                    "message": _("Values should be a JSON array of JSON objects"),
+                }
+            )
+        # Encode response to JSON and return
+        return json.dumps(
+            request.env["iot.device"]
+            .sudo()
+            .parse_multi_input(device_identification, kwargs["passphrase"], values)
+        )
+
+    @http.route(
+        ["/iot/<serial>/check"], type="http", auth="none", methods=["POST"], csrf=False
+    )
+    def check_unauthorized_iot(self, serial, *args, **kwargs):
+        request = http.request
+        if not request.env:
+            return json.dumps(False)
+        device = (
+            request.env["iot.device.input"]
+            .sudo()
+            .get_device(serial, kwargs["passphrase"])
+        )
+        if device:
+            return json.dumps({"state": True})
+        return json.dumps({"state": False})
diff --git a/iot_input_oca/examples/multi_input_values.json b/iot_input_oca/examples/multi_input_values.json
new file mode 100644
index 00000000..36b503a3
--- /dev/null
+++ b/iot_input_oca/examples/multi_input_values.json
@@ -0,0 +1,19 @@
+[
+  {
+    "address": "ZMPT101B_1",
+    "value": 230
+  },
+  {
+    "address": 1,
+    "value": true
+  },
+  {
+    "address": 2,
+    "value": "Door opened",
+    "uuid": "abcde"
+  },
+  {
+    "address": 10,
+    "value": -18.5
+  }
+]
diff --git a/iot_input_oca/i18n/iot_input.pot b/iot_input_oca/i18n/iot_input.pot
new file mode 100644
index 00000000..7635dc30
--- /dev/null
+++ b/iot_input_oca/i18n/iot_input.pot
@@ -0,0 +1,250 @@
+# Translation of Odoo Server.
+# This file contains the translation of the following modules:
+#	* iot_input
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: Odoo Server 12.0\n"
+"Report-Msgid-Bugs-To: \n"
+"Last-Translator: <>\n"
+"Language-Team: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: \n"
+"Plural-Forms: \n"
+
+#. module: iot_input
+#: model:ir.model.fields,field_description:iot_input.field_iot_device_input__action_ids
+msgid "Action"
+msgstr ""
+
+#. module: iot_input
+#: model:ir.model.fields,field_description:iot_input.field_iot_device_input__action_count
+msgid "Action Count"
+msgstr ""
+
+#. module: iot_input
+#: model:ir.model,name:iot_input.model_iot_device_input_action
+msgid "Action of device inputs"
+msgstr ""
+
+#. module: iot_input
+#: model:ir.model.fields,field_description:iot_input.field_iot_device_input__active
+#: model_terms:ir.ui.view,arch_db:iot_input.iot_device_input_search
+msgid "Active"
+msgstr ""
+
+#. module: iot_input
+#: model:ir.model.fields,field_description:iot_input.field_iot_device_input__address
+msgid "Address"
+msgstr ""
+
+#. module: iot_input
+#: code:addons/iot_input/models/iot_device.py:54
+#, python-format
+msgid "Address for Input is required"
+msgstr ""
+
+#. module: iot_input
+#: model:ir.model.fields,field_description:iot_input.field_iot_device_input_action__args
+msgid "Args"
+msgstr ""
+
+#. module: iot_input
+#: model:ir.model.fields,field_description:iot_input.field_iot_device_input__call_function
+msgid "Call Function"
+msgstr ""
+
+#. module: iot_input
+#: model:ir.model.fields,field_description:iot_input.field_iot_device_input__call_model_id
+msgid "Call Model"
+msgstr ""
+
+#. module: iot_input
+#: model:ir.model.fields,field_description:iot_input.field_iot_device_input__create_uid
+#: model:ir.model.fields,field_description:iot_input.field_iot_device_input_action__create_uid
+msgid "Created by"
+msgstr ""
+
+#. module: iot_input
+#: model:ir.model.fields,field_description:iot_input.field_iot_device_input__create_date
+#: model:ir.model.fields,field_description:iot_input.field_iot_device_input_action__create_date
+msgid "Created on"
+msgstr ""
+
+#. module: iot_input
+#: code:addons/iot_input/models/mail_message.py:15
+#, python-format
+msgid "Detected automatically by %s"
+msgstr ""
+
+#. module: iot_input
+#: model:ir.model.fields,field_description:iot_input.field_iot_device_input__device_id
+msgid "Device"
+msgstr ""
+
+#. module: iot_input
+#: code:addons/iot_input/models/iot_device_input.py:61
+#, python-format
+msgid "Device cannot be found"
+msgstr ""
+
+#. module: iot_input
+#: model:ir.model,name:iot_input.model_iot_device_input
+msgid "Device input"
+msgstr ""
+
+#. module: iot_input
+#: model:ir.model.fields,field_description:iot_input.field_iot_device_input__display_name
+#: model:ir.model.fields,field_description:iot_input.field_iot_device_input_action__display_name
+msgid "Display Name"
+msgstr ""
+
+#. module: iot_input
+#: code:addons/iot_input/models/iot_device.py:136
+#, python-format
+msgid "Empty values array"
+msgstr ""
+
+#. module: iot_input
+#: model:ir.model.fields,field_description:iot_input.field_iot_device_input__id
+#: model:ir.model.fields,field_description:iot_input.field_iot_device_input_action__id
+msgid "ID"
+msgstr ""
+
+#. module: iot_input
+#: model_terms:ir.ui.view,arch_db:iot_input.iot_device_input_search
+msgid "Inactive"
+msgstr ""
+
+#. module: iot_input
+#: model:ir.model.fields,field_description:iot_input.field_iot_device__input_ids
+#: model:ir.model.fields,field_description:iot_input.field_iot_device_input_action__input_id
+msgid "Input"
+msgstr ""
+
+#. module: iot_input
+#: model:ir.model.fields,field_description:iot_input.field_iot_device__input_count
+msgid "Input Count"
+msgstr ""
+
+#. module: iot_input
+#: model_terms:ir.ui.view,arch_db:iot_input.iot_device_form
+msgid "Inputs"
+msgstr ""
+
+#. module: iot_input
+#: model:ir.model,name:iot_input.model_iot_device
+msgid "IoT Device"
+msgstr ""
+
+#. module: iot_input
+#: model_terms:ir.ui.view,arch_db:iot_input.iot_device_input_search
+msgid "IoT Device Input Search"
+msgstr ""
+
+#. module: iot_input
+#: model:ir.actions.act_window,name:iot_input.iot_device_input_action
+msgid "IoT Inputs"
+msgstr ""
+
+#. module: iot_input
+#: model:ir.model.fields,field_description:iot_input.field_iot_device_input__lang
+msgid "Language"
+msgstr ""
+
+#. module: iot_input
+#: model:ir.model.fields,field_description:iot_input.field_iot_device_input____last_update
+#: model:ir.model.fields,field_description:iot_input.field_iot_device_input_action____last_update
+msgid "Last Modified on"
+msgstr ""
+
+#. module: iot_input
+#: model:ir.model.fields,field_description:iot_input.field_iot_device_input__write_uid
+#: model:ir.model.fields,field_description:iot_input.field_iot_device_input_action__write_uid
+msgid "Last Updated by"
+msgstr ""
+
+#. module: iot_input
+#: model:ir.model.fields,field_description:iot_input.field_iot_device_input__write_date
+#: model:ir.model.fields,field_description:iot_input.field_iot_device_input_action__write_date
+msgid "Last Updated on"
+msgstr ""
+
+#. module: iot_input
+#: model:ir.model,name:iot_input.model_mail_message
+msgid "Message"
+msgstr ""
+
+#. module: iot_input
+#: model:ir.model.fields,field_description:iot_input.field_iot_device_input__name
+msgid "Name"
+msgstr ""
+
+#. module: iot_input
+#: model:ir.model.fields,field_description:iot_input.field_iot_device_input__passphrase
+msgid "Passphrase"
+msgstr ""
+
+#. module: iot_input
+#: code:addons/iot_input/controller/iot_input_controller.py:43
+#, python-format
+msgid "Passphrase is required"
+msgstr ""
+
+#. module: iot_input
+#: model:ir.model.fields,field_description:iot_input.field_iot_device_input_action__res
+msgid "Res"
+msgstr ""
+
+#. module: iot_input
+#: model:ir.model.fields,field_description:iot_input.field_iot_device_input__serial
+msgid "Serial"
+msgstr ""
+
+#. module: iot_input
+#: code:addons/iot_input/models/iot_device_input.py:47
+#, python-format
+msgid "Serial and passphrase are required"
+msgstr ""
+
+#. module: iot_input
+#: code:addons/iot_input/controller/iot_input_controller.py:39
+#, python-format
+msgid "Server Error"
+msgstr ""
+
+#. module: iot_input
+#: code:addons/iot_input/models/iot_device.py:74
+#: code:addons/iot_input/models/iot_device.py:87
+#: code:addons/iot_input/models/iot_device.py:117
+#: code:addons/iot_input/models/iot_device.py:123
+#: code:addons/iot_input/models/iot_device.py:129
+#, python-format
+msgid "Server Error. Check server logs"
+msgstr ""
+
+#. module: iot_input
+#: code:addons/iot_input/models/iot_device.py:61
+#, python-format
+msgid "Value for Input is required"
+msgstr ""
+
+#. module: iot_input
+#: code:addons/iot_input/controller/iot_input_controller.py:56
+#, python-format
+msgid "Values is not a valid JSON"
+msgstr ""
+
+#. module: iot_input
+#: code:addons/iot_input/controller/iot_input_controller.py:47
+#, python-format
+msgid "Values is required"
+msgstr ""
+
+#. module: iot_input
+#: code:addons/iot_input/controller/iot_input_controller.py:61
+#, python-format
+msgid "Values should be a JSON array of JSON objects"
+msgstr ""
+
diff --git a/iot_input_oca/models/__init__.py b/iot_input_oca/models/__init__.py
new file mode 100644
index 00000000..58626c86
--- /dev/null
+++ b/iot_input_oca/models/__init__.py
@@ -0,0 +1,3 @@
+from . import mail_message
+from . import iot_device
+from . import iot_device_input
diff --git a/iot_input_oca/models/iot_device.py b/iot_input_oca/models/iot_device.py
new file mode 100644
index 00000000..13fe028e
--- /dev/null
+++ b/iot_input_oca/models/iot_device.py
@@ -0,0 +1,136 @@
+import logging
+
+from odoo import _, api, fields, models
+
+_logger = logging.getLogger(__name__)
+
+
+class IotDevice(models.Model):
+    _inherit = "iot.device"
+
+    input_ids = fields.One2many("iot.device.input", inverse_name="device_id")
+    input_count = fields.Integer(compute="_compute_input_count")
+
+    @api.depends("input_ids")
+    def _compute_input_count(self):
+        for r in self:
+            r.input_count = len(r.input_ids)
+
+    def action_show_input(self):
+        self.ensure_one()
+        action = self.env.ref("iot_input_oca.iot_device_input_action")
+        result = action.read()[0]
+
+        result["context"] = {
+            "default_device_id": self.id,
+        }
+        result["domain"] = [("device_id", "=", self.id)]
+        if len(self.input_ids) == 1:
+            result["views"] = [(False, "form")]
+            result["res_id"] = self.input_ids.id
+        return result
+
+    def parse_single_input(self, value):
+        """Handle single input for device
+
+        :param dict value:
+            Dict containing at least keys 'address', 'value'
+        :returns: dict with keys 'status', 'message' where:
+            - status='ok' when value is parsed without errors
+            - status='error' and message='error message' when error occurs
+            If value contains a value with key 'uuid', it is passed in the return dict
+            to identify result for each entry at the iot end
+        :rtype: dict
+        """
+        msg = {}
+        if "uuid" in value:
+            msg["uuid"] = value["uuid"]
+        if "address" not in value.keys():
+            _logger.warning("Address for Input is required")
+            msg.update(
+                {"status": "error", "message": _("Address for Input is required")}
+            )
+            return msg
+        if "value" not in value.keys():
+            _logger.warning("Value for Input is required")
+            msg.update({"status": "error", "message": _("Value for Input is required")})
+            return msg
+
+        device_input = self.input_ids.filtered(
+            lambda i: i.address == str(value["address"])
+        )
+        if len(device_input) == 1:
+            if not device_input.active:
+                _logger.warning(
+                    "Input with address %s is inactive, no data will be logged",
+                    device_input.address,
+                )
+                msg.update(
+                    {
+                        "status": "error",
+                        "message": _("Server Error. Check server logs"),
+                    }
+                )
+                return msg
+            res = device_input._call_device(value)
+            self.env["iot.device.input.action"].create(
+                device_input._add_action_vals(value, res)
+            )
+            if "uuid" in value:
+                res["uuid"] = value["uuid"]
+            return res
+        else:
+            _logger.warning("Input with address %s not found", value["address"])
+            msg.update(
+                {"status": "error", "message": _("Server Error. Check server logs")}
+            )
+            return msg
+
+    @api.model
+    def parse_multi_input(self, device_identification, passphrase, values):
+        """Handle multiple inputs for device
+
+        :param string device_identification:
+            Device identification.
+        :param string passphrase:
+            Device passphrase.
+        :param list values:
+            Values is a list of dicts with at least values for keys 'address', 'value'
+            Each dict in the list can have:
+             - Different address (multi input)
+             - Same address, different values (multi event)
+             - Mix of the above (multi input, multi event)
+        :returns: JSON encodable list of dicts
+        :rtype: list
+        """
+        device = self.with_context(active_test=False).search(
+            [("device_identification", "=", device_identification)]
+        )
+        if not device:
+            _logger.warning(
+                "Device with identification %s not found", device_identification
+            )
+            return {"status": "error", "message": _("Server Error. Check server logs")}
+        if not device.active:
+            _logger.warning(
+                "Device with identification %s is inactive, no data will be logged",
+                device.device_identification,
+            )
+            return {"status": "error", "message": _("Server Error. Check server logs")}
+        if device.passphrase != passphrase:
+            _logger.warning(
+                "Wrong passphrase for device with identification %s",
+                device.device_identification,
+            )
+            return {"status": "error", "message": _("Server Error. Check server logs")}
+
+        if not values:
+            _logger.warning(
+                "Empty values array for device with identification %s",
+                device.device_identification,
+            )
+            return {"status": "error", "message": _("Empty values array")}
+        res = []
+        for d in values:
+            res.append(device.parse_single_input(d))
+        return res
diff --git a/iot_input_oca/models/iot_device_input.py b/iot_input_oca/models/iot_device_input.py
new file mode 100644
index 00000000..33d6d0c8
--- /dev/null
+++ b/iot_input_oca/models/iot_device_input.py
@@ -0,0 +1,82 @@
+from odoo import _, api, fields, models
+from odoo.exceptions import ValidationError
+
+
+class IotDeviceInput(models.Model):
+    _name = "iot.device.input"
+    _description = "Device input"
+    _order = "name"
+
+    name = fields.Char(required=True)
+    device_id = fields.Many2one("iot.device", required=True, readonly=True)
+    call_model_id = fields.Many2one("ir.model")
+    call_function = fields.Char(required=True)
+    active = fields.Boolean(default=True)
+    serial = fields.Char()
+    address = fields.Char()
+    passphrase = fields.Char()
+    action_ids = fields.One2many(
+        "iot.device.input.action", inverse_name="input_id", readonly=True,
+    )
+    action_count = fields.Integer(compute="_compute_action_count")
+    lang = fields.Selection(
+        selection=lambda self: self.env["res.lang"].get_installed(), string="Language",
+    )
+
+    @api.depends("action_ids")
+    def _compute_action_count(self):
+        for r in self:
+            r.action_count = len(r.action_ids)
+
+    def _call_device(self, value):
+        self.ensure_one()
+        obj = self
+        if self.call_model_id:
+            obj = self.env[self.call_model_id.model].with_context(
+                iot_device_input_id=self.id,
+                iot_device_name=self.device_id.name,
+                iot_device_id=self.device_id.id,
+            )
+        if self.lang:
+            obj = obj.with_context(lang=self.lang)
+        return getattr(obj, self.call_function)(value)
+
+    def parse_args(self, serial, passphrase):
+        if not serial or not passphrase:
+            raise ValidationError(_("Serial and passphrase are required"))
+        return [("serial", "=", serial), ("passphrase", "=", passphrase)]
+
+    @api.model
+    def get_device(self, serial, passphrase):
+        return self.search(self.parse_args(serial, passphrase), limit=1)
+
+    def call_device(self, value):
+        if not self:
+            return {"status": "error", "message": _("Device cannot be found")}
+        else:
+            res = self._call_device(value)
+            res["status"] = "ok"
+        self.env["iot.device.input.action"].create(self._add_action_vals(value, res))
+        return res
+
+    def _add_action_vals(self, value, res):
+        return {
+            "input_id": self.id,
+            "args": str(value),
+            "res": str(res),
+        }
+
+    def test_input_device(self, value):
+        return {"value": value}
+
+    def test_model_function(self, value):
+        return {"status": "ok", "message": value}
+
+
+class IoTDeviceAction(models.Model):
+    _name = "iot.device.input.action"
+    _description = "Action of device inputs"
+
+    input_id = fields.Many2one("iot.device.input")
+    args = fields.Char()
+    res = fields.Char()
diff --git a/iot_input_oca/models/mail_message.py b/iot_input_oca/models/mail_message.py
new file mode 100644
index 00000000..bba4a9d4
--- /dev/null
+++ b/iot_input_oca/models/mail_message.py
@@ -0,0 +1,17 @@
+from odoo import _, api, models
+
+
+class MailMessage(models.Model):
+    _inherit = "mail.message"
+
+    @api.model
+    def create(self, vals):
+        device = self.env.context.get("iot_device_name", False)
+        if device:
+            body = vals.get("body", "")
+            if len(body) > 0:
+                body += "<br>"
+            vals["body"] = "{}{}".format(
+                body, _("Detected automatically by %s") % device
+            )
+        return super().create(vals)
diff --git a/iot_input_oca/readme/CONTRIBUTORS.rst b/iot_input_oca/readme/CONTRIBUTORS.rst
new file mode 100644
index 00000000..61fe3232
--- /dev/null
+++ b/iot_input_oca/readme/CONTRIBUTORS.rst
@@ -0,0 +1,2 @@
+* Enric Tobella <etobella@creublanca.es>
+* Dimitrios Tanis <dtanis@tanisfood.gr>
diff --git a/iot_input_oca/readme/DESCRIPTION.rst b/iot_input_oca/readme/DESCRIPTION.rst
new file mode 100644
index 00000000..0ca60637
--- /dev/null
+++ b/iot_input_oca/readme/DESCRIPTION.rst
@@ -0,0 +1,14 @@
+This addon allows to use a device in order to input data to odoo automatically.
+
+It opens a URL that a device can use to connect (with a password) that can only
+execute an specific action.
+
+Inputs are useful when a device wants to communicate to odoo for a single
+and simple action.
+This way, the device does not need to be configured with a odoo user and
+password, it is handled by odoo devices.
+
+Examples:
+
+* Sending the temperature every three minutes.
+* Sending the RFID that the device has received in order to perform some action
diff --git a/iot_input_oca/readme/USAGE.rst b/iot_input_oca/readme/USAGE.rst
new file mode 100644
index 00000000..d7d24727
--- /dev/null
+++ b/iot_input_oca/readme/USAGE.rst
@@ -0,0 +1,55 @@
+There are two endpoints you can use:
+Endpoint 1: /iot/<serial>/action
+
+Takes `application/x-www-form-urlencoded` parameters:
+passphase, value (where value is a JSON object)
+
+1. Create a Device on `IoT > Config Devices`
+2. Access the Inputs section of the device
+3. Create an input. You must define a serial, passphrase, function and model
+
+The function that the system will call must be of the following kind::
+
+    @api.model
+        def call_function(self, key):
+        return {}
+
+Where `key` is the input string send by the device and the result must be a dictionary
+that will be responded to the device as a JSON.
+
+Endpoint 2: /iot/<device_identification>/multi_input
+It can be used to send values with multiple data in one POST request such as:
+- Values for inputs of the same device with different address (multi input)
+- Values for inputs of the same device with same address, different values (multi event)
+- Mix of the above (multi input, multi event)
+
+Takes `application/x-www-form-urlencoded` parameters:
+passphase, values (a JSON array of JSON objects)
+
+It is called using device_identification and passing two POST parameters: device passphrase and
+a JSON string containing an array of values for input
+- The value for the `address` key can be a string or a numeric (to conserve bytes in memory
+restricted devices when creating the JSON object) and is converted to string when parsing.
+- The value for the `value` key can either be string, number or boolean according to
+JSON specs.
+You can see an example of a valid JSON input object in the examples folder, using a few
+combinations.
+
+It requires the function that the system will call must be of the following kind::
+
+    @api.model
+        def call_function(self, key):
+        'do something
+        if err:
+            return {'status': 'error', 'message': 'The error message you want to send to the device'}
+        return {'status': 'ok', 'message': 'Optional success message'}
+
+Where `key` is a dict send by the device having at least value for keys: 'address', 'value'
+
+The function must always return a JSON with status and message. If value contains a value
+with 'uuid' as key, it is returned along with the object for the IoT device to identify
+success/failure per record.
+
+It has full error reporting and the return value is a JSON array of dicts containing at
+least status and message. Error message respose is at some points generic, though
+extended logging is done in Odoo server logs.
diff --git a/iot_input_oca/security/ir.model.access.csv b/iot_input_oca/security/ir.model.access.csv
new file mode 100644
index 00000000..fe82dfc8
--- /dev/null
+++ b/iot_input_oca/security/ir.model.access.csv
@@ -0,0 +1,5 @@
+id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
+access_iot_device_input,access_iot_device_input,model_iot_device_input,iot_oca.group_iot_user,1,1,1,0
+manage_iot_device_input,access_iot_device_input,model_iot_device_input,iot_oca.group_iot_manager,1,1,1,1
+access_iot_device_input_action,access_iot_device_input_action,model_iot_device_input_action,iot_oca.group_iot_user,1,1,1,0
+manage_iot_device_input_action,access_iot_device_input_action,model_iot_device_input_action,iot_oca.group_iot_manager,1,1,1,1
diff --git a/iot_input_oca/static/description/icon.png b/iot_input_oca/static/description/icon.png
new file mode 100644
index 00000000..da43f6f0
Binary files /dev/null and b/iot_input_oca/static/description/icon.png differ
diff --git a/iot_input_oca/static/description/index.html b/iot_input_oca/static/description/index.html
new file mode 100644
index 00000000..8d31247c
--- /dev/null
+++ b/iot_input_oca/static/description/index.html
@@ -0,0 +1,485 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" />
+<title>IoT Input</title>
+<style type="text/css">
+
+/*
+:Author: David Goodger (goodger@python.org)
+:Id: $Id: html4css1.css 7952 2016-07-26 18:15:59Z milde $
+:Copyright: This stylesheet has been placed in the public domain.
+
+Default cascading style sheet for the HTML output of Docutils.
+
+See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
+customize this style sheet.
+*/
+
+/* used to remove borders from tables and images */
+.borderless, table.borderless td, table.borderless th {
+  border: 0 }
+
+table.borderless td, table.borderless th {
+  /* Override padding for "table.docutils td" with "! important".
+     The right padding separates the table cells. */
+  padding: 0 0.5em 0 0 ! important }
+
+.first {
+  /* Override more specific margin styles with "! important". */
+  margin-top: 0 ! important }
+
+.last, .with-subtitle {
+  margin-bottom: 0 ! important }
+
+.hidden {
+  display: none }
+
+.subscript {
+  vertical-align: sub;
+  font-size: smaller }
+
+.superscript {
+  vertical-align: super;
+  font-size: smaller }
+
+a.toc-backref {
+  text-decoration: none ;
+  color: black }
+
+blockquote.epigraph {
+  margin: 2em 5em ; }
+
+dl.docutils dd {
+  margin-bottom: 0.5em }
+
+object[type="image/svg+xml"], object[type="application/x-shockwave-flash"] {
+  overflow: hidden;
+}
+
+/* Uncomment (and remove this text!) to get bold-faced definition list terms
+dl.docutils dt {
+  font-weight: bold }
+*/
+
+div.abstract {
+  margin: 2em 5em }
+
+div.abstract p.topic-title {
+  font-weight: bold ;
+  text-align: center }
+
+div.admonition, div.attention, div.caution, div.danger, div.error,
+div.hint, div.important, div.note, div.tip, div.warning {
+  margin: 2em ;
+  border: medium outset ;
+  padding: 1em }
+
+div.admonition p.admonition-title, div.hint p.admonition-title,
+div.important p.admonition-title, div.note p.admonition-title,
+div.tip p.admonition-title {
+  font-weight: bold ;
+  font-family: sans-serif }
+
+div.attention p.admonition-title, div.caution p.admonition-title,
+div.danger p.admonition-title, div.error p.admonition-title,
+div.warning p.admonition-title, .code .error {
+  color: red ;
+  font-weight: bold ;
+  font-family: sans-serif }
+
+/* Uncomment (and remove this text!) to get reduced vertical space in
+   compound paragraphs.
+div.compound .compound-first, div.compound .compound-middle {
+  margin-bottom: 0.5em }
+
+div.compound .compound-last, div.compound .compound-middle {
+  margin-top: 0.5em }
+*/
+
+div.dedication {
+  margin: 2em 5em ;
+  text-align: center ;
+  font-style: italic }
+
+div.dedication p.topic-title {
+  font-weight: bold ;
+  font-style: normal }
+
+div.figure {
+  margin-left: 2em ;
+  margin-right: 2em }
+
+div.footer, div.header {
+  clear: both;
+  font-size: smaller }
+
+div.line-block {
+  display: block ;
+  margin-top: 1em ;
+  margin-bottom: 1em }
+
+div.line-block div.line-block {
+  margin-top: 0 ;
+  margin-bottom: 0 ;
+  margin-left: 1.5em }
+
+div.sidebar {
+  margin: 0 0 0.5em 1em ;
+  border: medium outset ;
+  padding: 1em ;
+  background-color: #ffffee ;
+  width: 40% ;
+  float: right ;
+  clear: right }
+
+div.sidebar p.rubric {
+  font-family: sans-serif ;
+  font-size: medium }
+
+div.system-messages {
+  margin: 5em }
+
+div.system-messages h1 {
+  color: red }
+
+div.system-message {
+  border: medium outset ;
+  padding: 1em }
+
+div.system-message p.system-message-title {
+  color: red ;
+  font-weight: bold }
+
+div.topic {
+  margin: 2em }
+
+h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
+h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
+  margin-top: 0.4em }
+
+h1.title {
+  text-align: center }
+
+h2.subtitle {
+  text-align: center }
+
+hr.docutils {
+  width: 75% }
+
+img.align-left, .figure.align-left, object.align-left, table.align-left {
+  clear: left ;
+  float: left ;
+  margin-right: 1em }
+
+img.align-right, .figure.align-right, object.align-right, table.align-right {
+  clear: right ;
+  float: right ;
+  margin-left: 1em }
+
+img.align-center, .figure.align-center, object.align-center {
+  display: block;
+  margin-left: auto;
+  margin-right: auto;
+}
+
+table.align-center {
+  margin-left: auto;
+  margin-right: auto;
+}
+
+.align-left {
+  text-align: left }
+
+.align-center {
+  clear: both ;
+  text-align: center }
+
+.align-right {
+  text-align: right }
+
+/* reset inner alignment in figures */
+div.align-right {
+  text-align: inherit }
+
+/* div.align-center * { */
+/*   text-align: left } */
+
+.align-top    {
+  vertical-align: top }
+
+.align-middle {
+  vertical-align: middle }
+
+.align-bottom {
+  vertical-align: bottom }
+
+ol.simple, ul.simple {
+  margin-bottom: 1em }
+
+ol.arabic {
+  list-style: decimal }
+
+ol.loweralpha {
+  list-style: lower-alpha }
+
+ol.upperalpha {
+  list-style: upper-alpha }
+
+ol.lowerroman {
+  list-style: lower-roman }
+
+ol.upperroman {
+  list-style: upper-roman }
+
+p.attribution {
+  text-align: right ;
+  margin-left: 50% }
+
+p.caption {
+  font-style: italic }
+
+p.credits {
+  font-style: italic ;
+  font-size: smaller }
+
+p.label {
+  white-space: nowrap }
+
+p.rubric {
+  font-weight: bold ;
+  font-size: larger ;
+  color: maroon ;
+  text-align: center }
+
+p.sidebar-title {
+  font-family: sans-serif ;
+  font-weight: bold ;
+  font-size: larger }
+
+p.sidebar-subtitle {
+  font-family: sans-serif ;
+  font-weight: bold }
+
+p.topic-title {
+  font-weight: bold }
+
+pre.address {
+  margin-bottom: 0 ;
+  margin-top: 0 ;
+  font: inherit }
+
+pre.literal-block, pre.doctest-block, pre.math, pre.code {
+  margin-left: 2em ;
+  margin-right: 2em }
+
+pre.code .ln { color: grey; } /* line numbers */
+pre.code, code { background-color: #eeeeee }
+pre.code .comment, code .comment { color: #5C6576 }
+pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
+pre.code .literal.string, code .literal.string { color: #0C5404 }
+pre.code .name.builtin, code .name.builtin { color: #352B84 }
+pre.code .deleted, code .deleted { background-color: #DEB0A1}
+pre.code .inserted, code .inserted { background-color: #A3D289}
+
+span.classifier {
+  font-family: sans-serif ;
+  font-style: oblique }
+
+span.classifier-delimiter {
+  font-family: sans-serif ;
+  font-weight: bold }
+
+span.interpreted {
+  font-family: sans-serif }
+
+span.option {
+  white-space: nowrap }
+
+span.pre {
+  white-space: pre }
+
+span.problematic {
+  color: red }
+
+span.section-subtitle {
+  /* font-size relative to parent (h1..h6 element) */
+  font-size: 80% }
+
+table.citation {
+  border-left: solid 1px gray;
+  margin-left: 1px }
+
+table.docinfo {
+  margin: 2em 4em }
+
+table.docutils {
+  margin-top: 0.5em ;
+  margin-bottom: 0.5em }
+
+table.footnote {
+  border-left: solid 1px black;
+  margin-left: 1px }
+
+table.docutils td, table.docutils th,
+table.docinfo td, table.docinfo th {
+  padding-left: 0.5em ;
+  padding-right: 0.5em ;
+  vertical-align: top }
+
+table.docutils th.field-name, table.docinfo th.docinfo-name {
+  font-weight: bold ;
+  text-align: left ;
+  white-space: nowrap ;
+  padding-left: 0 }
+
+/* "booktabs" style (no vertical lines) */
+table.docutils.booktabs {
+  border: 0px;
+  border-top: 2px solid;
+  border-bottom: 2px solid;
+  border-collapse: collapse;
+}
+table.docutils.booktabs * {
+  border: 0px;
+}
+table.docutils.booktabs th {
+  border-bottom: thin solid;
+  text-align: left;
+}
+
+h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
+h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
+  font-size: 100% }
+
+ul.auto-toc {
+  list-style-type: none }
+
+</style>
+</head>
+<body>
+<div class="document" id="iot-input">
+<h1 class="title">IoT Input</h1>
+
+<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!! This file is generated by oca-gen-addon-readme !!
+!! changes will be overwritten.                   !!
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
+<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/iot/tree/12.0/iot_input"><img alt="OCA/iot" src="https://img.shields.io/badge/github-OCA%2Fiot-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/iot-12-0/iot-12-0-iot_input"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/269/12.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
+<p>This addon allows to use a device in order to input data to odoo automatically.</p>
+<p>It opens a URL that a device can use to connect (with a password) that can only
+execute an specific action.</p>
+<p>Inputs are useful when a device wants to communicate to odoo for a single
+and simple action.
+This way, the device does not need to be configured with a odoo user and
+password, it is handled by odoo devices.</p>
+<p>Examples:</p>
+<ul class="simple">
+<li>Sending the temperature every three minutes.</li>
+<li>Sending the RFID that the device has received in order to perform some action</li>
+</ul>
+<p><strong>Table of contents</strong></p>
+<div class="contents local topic" id="contents">
+<ul class="simple">
+<li><a class="reference internal" href="#usage" id="id1">Usage</a></li>
+<li><a class="reference internal" href="#bug-tracker" id="id2">Bug Tracker</a></li>
+<li><a class="reference internal" href="#credits" id="id3">Credits</a><ul>
+<li><a class="reference internal" href="#authors" id="id4">Authors</a></li>
+<li><a class="reference internal" href="#contributors" id="id5">Contributors</a></li>
+<li><a class="reference internal" href="#maintainers" id="id6">Maintainers</a></li>
+</ul>
+</li>
+</ul>
+</div>
+<div class="section" id="usage">
+<h1><a class="toc-backref" href="#id1">Usage</a></h1>
+<p>There are two endpoints you can use:
+Endpoint 1: /iot/&lt;serial&gt;/action</p>
+<p>Takes <cite>application/x-www-form-urlencoded</cite> parameters:
+passphase, value (where value is a JSON object)</p>
+<ol class="arabic simple">
+<li>Create a Device on <cite>IoT &gt; Config Devices</cite></li>
+<li>Access the Inputs section of the device</li>
+<li>Create an input. You must define a serial, passphrase, function and model</li>
+</ol>
+<p>The function that the system will call must be of the following kind:</p>
+<pre class="literal-block">
+&#64;api.model
+    def call_function(self, key):
+    return {}
+</pre>
+<p>Where <cite>key</cite> is the input string send by the device and the result must be a dictionary
+that will be responded to the device as a JSON.</p>
+<p>Endpoint 2: /iot/&lt;device_identification&gt;/multi_input
+It can be used to send values with multiple data in one POST request such as:
+- Values for inputs of the same device with different address (multi input)
+- Values for inputs of the same device with same address, different values (multi event)
+- Mix of the above (multi input, multi event)</p>
+<p>Takes <cite>application/x-www-form-urlencoded</cite> parameters:
+passphase, values (a JSON array of JSON objects)</p>
+<p>It is called using device_identification and passing two POST parameters: device passphrase and
+a JSON string containing an array of values for input
+- The value for the <cite>address</cite> key can be a string or a numeric (to conserve bytes in memory
+restricted devices when creating the JSON object) and is converted to string when parsing.
+- The value for the <cite>value</cite> key can either be string, number or boolean according to
+JSON specs.
+You can see an example of a valid JSON input object in the examples folder, using a few
+combinations.</p>
+<p>It requires the function that the system will call must be of the following kind:</p>
+<pre class="literal-block">
+&#64;api.model
+    def call_function(self, key):
+    'do something
+    if err:
+        return {'status': 'error', 'message': 'The error message you want to send to the device'}
+    return {'status': 'ok', 'message': 'Optional success message'}
+</pre>
+<p>Where <cite>key</cite> is a dict send by the device having at least value for keys: ‘address’, ‘value’</p>
+<p>The function must always return a JSON with status and message. If value contains a value
+with ‘uuid’ as key, it is returned along with the object for the IoT device to identify
+success/failure per record.</p>
+<p>It has full error reporting and the return value is a JSON array of dicts containing at
+least status and message. Error message respose is at some points generic, though
+extended logging is done in Odoo server logs.</p>
+</div>
+<div class="section" id="bug-tracker">
+<h1><a class="toc-backref" href="#id2">Bug Tracker</a></h1>
+<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/iot/issues">GitHub Issues</a>.
+In case of trouble, please check there if your issue has already been reported.
+If you spotted it first, help us smashing it by providing a detailed and welcomed
+<a class="reference external" href="https://github.com/OCA/iot/issues/new?body=module:%20iot_input%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
+<p>Do not contact contributors directly about support or help with technical issues.</p>
+</div>
+<div class="section" id="credits">
+<h1><a class="toc-backref" href="#id3">Credits</a></h1>
+<div class="section" id="authors">
+<h2><a class="toc-backref" href="#id4">Authors</a></h2>
+<ul class="simple">
+<li>Creu Blanca</li>
+</ul>
+</div>
+<div class="section" id="contributors">
+<h2><a class="toc-backref" href="#id5">Contributors</a></h2>
+<ul class="simple">
+<li>Enric Tobella &lt;<a class="reference external" href="mailto:etobella&#64;creublanca.es">etobella&#64;creublanca.es</a>&gt;</li>
+<li>Dimitrios Tanis &lt;<a class="reference external" href="mailto:dtanis&#64;tanisfood.gr">dtanis&#64;tanisfood.gr</a>&gt;</li>
+</ul>
+</div>
+<div class="section" id="maintainers">
+<h2><a class="toc-backref" href="#id6">Maintainers</a></h2>
+<p>This module is maintained by the OCA.</p>
+<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
+<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
+mission is to support the collaborative development of Odoo features and
+promote its widespread use.</p>
+<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
+<p><a class="reference external" href="https://github.com/etobella"><img alt="etobella" src="https://github.com/etobella.png?size=40px" /></a></p>
+<p>This module is part of the <a class="reference external" href="https://github.com/OCA/iot/tree/12.0/iot_input">OCA/iot</a> project on GitHub.</p>
+<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
+</div>
+</div>
+</div>
+</body>
+</html>
diff --git a/iot_input_oca/views/iot_device_input_views.xml b/iot_input_oca/views/iot_device_input_views.xml
new file mode 100644
index 00000000..cfb7b6ff
--- /dev/null
+++ b/iot_input_oca/views/iot_device_input_views.xml
@@ -0,0 +1,78 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<odoo>
+    <record id="iot_device_input_tree" model="ir.ui.view">
+        <field name="name">iot.device.input.tree</field>
+        <field name="model">iot.device.input</field>
+        <field name="arch" type="xml">
+            <tree delete="0">
+                <field name="name" />
+                <field name="address" />
+                <field name="serial" />
+            </tree>
+        </field>
+    </record>
+    <record id="iot_device_input_form" model="ir.ui.view">
+        <field name="name">iot.device.input.form</field>
+        <field name="model">iot.device.input</field>
+        <field name="arch" type="xml">
+            <form>
+                <header />
+                <sheet>
+                    <widget
+                        name="web_ribbon"
+                        text="Archived"
+                        bg_color="bg-danger"
+                        attrs="{'invisible': [('active', '=', True)]}"
+                    />
+                    <field name="active" invisible="1" />
+                    <div class="oe_button_box" name="button_box" />
+                    <div class="oe_title">
+                        <h1>
+                            <field name="name" />
+                        </h1>
+                    </div>
+                    <group>
+                        <group>
+                            <field name="address" />
+                            <field name="serial" />
+                            <field name="passphrase" widget="password" />
+                        </group>
+                        <group>
+                            <field name="call_model_id" options="{'no_create':True}" />
+                            <field name="call_function" />
+                            <field name="lang" />
+                        </group>
+                    </group>
+                    <notebook invisible="1" />
+                </sheet>
+            </form>
+        </field>
+    </record>
+    <record id="iot_device_input_search" model="ir.ui.view">
+        <field name="name">iot.device.input.search</field>
+        <field name="model">iot.device.input</field>
+        <field name="arch" type="xml">
+            <search string="IoT Device Input Search">
+                <filter
+                    name="active"
+                    string="Active"
+                    domain="[('active','=',True)]"
+                    help="Active"
+                />
+                <filter
+                    name="inactive"
+                    string="Inactive"
+                    domain="[('active','=',False)]"
+                    help="Inactive"
+                />
+                <separator />
+            </search>
+        </field>
+    </record>
+    <record model="ir.actions.act_window" id="iot_device_input_action">
+        <field name="name">IoT Inputs</field>
+        <field name="type">ir.actions.act_window</field>
+        <field name="res_model">iot.device.input</field>
+        <field name="view_mode">tree,form</field>
+    </record>
+</odoo>
diff --git a/iot_input_oca/views/iot_device_views.xml b/iot_input_oca/views/iot_device_views.xml
new file mode 100644
index 00000000..6a72daf4
--- /dev/null
+++ b/iot_input_oca/views/iot_device_views.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<odoo>
+    <record id="iot_device_form" model="ir.ui.view">
+        <field name="name">iot.device.form</field>
+        <field name="model">iot.device</field>
+        <field name="inherit_id" ref="iot_oca.iot_device_form" />
+        <field name="arch" type="xml">
+            <xpath expr="//div[@name='button_box']" position="inside">
+                <button
+                    name="action_show_input"
+                    type="object"
+                    class="oe_stat_button"
+                    icon="fa-keyboard-o"
+                >
+                    <field string="Inputs" name="input_count" widget="statinfo" />
+                </button>
+            </xpath>
+        </field>
+    </record>
+</odoo>
diff --git a/setup/iot_input_oca/odoo/addons/iot_input_oca b/setup/iot_input_oca/odoo/addons/iot_input_oca
new file mode 120000
index 00000000..8ad0a5e1
--- /dev/null
+++ b/setup/iot_input_oca/odoo/addons/iot_input_oca
@@ -0,0 +1,1 @@
+../../../../iot_input_oca
\ No newline at end of file
diff --git a/setup/iot_input_oca/setup.py b/setup/iot_input_oca/setup.py
new file mode 100644
index 00000000..28c57bb6
--- /dev/null
+++ b/setup/iot_input_oca/setup.py
@@ -0,0 +1,6 @@
+import setuptools
+
+setuptools.setup(
+    setup_requires=['setuptools-odoo'],
+    odoo_addon=True,
+)


Test patch:
diff --git a/iot_input_oca/tests/__init__.py b/iot_input_oca/tests/__init__.py
new file mode 100644
index 00000000..0740ace6
--- /dev/null
+++ b/iot_input_oca/tests/__init__.py
@@ -0,0 +1,4 @@
+from . import test_iot_in
+from . import test_iot_multi_input
+from . import test_iot_controller
+from . import test_iot_message
diff --git a/iot_input_oca/tests/models.py b/iot_input_oca/tests/models.py
new file mode 100644
index 00000000..e2a2c4c9
--- /dev/null
+++ b/iot_input_oca/tests/models.py
@@ -0,0 +1,10 @@
+from odoo import models
+
+
+class ResPartner(models.Model):
+    _inherit = "res.partner"
+
+    def test_fake_iot_input(self, value):
+        partner = self.browse(value)
+        partner.message_post(body=str(value))
+        return {}
diff --git a/iot_input_oca/tests/test_iot_controller.py b/iot_input_oca/tests/test_iot_controller.py
new file mode 100644
index 00000000..221a962b
--- /dev/null
+++ b/iot_input_oca/tests/test_iot_controller.py
@@ -0,0 +1,113 @@
+import json
+
+from odoo.tests.common import HttpCase, tagged
+
+
+@tagged("post_install", "-at_install")
+class TestIotController(HttpCase):
+    def setUp(self):
+        super().setUp()
+        self.device_identification = "test_device_name"
+        self.passphrase = "password"
+        self.device = self.env["iot.device"].create(
+            {
+                "name": "Device",
+                "device_identification": self.device_identification,
+                "passphrase": self.passphrase,
+            }
+        )
+        self.address_1 = "I0"
+        self.serial = "testingdeviceserial"
+        self.input_passphrase = "password"
+        self.device_input_1 = self.env["iot.device.input"].create(
+            {
+                "name": "Input 1",
+                "device_id": self.device.id,
+                "address": self.address_1,
+                "serial": self.serial,
+                "passphrase": self.input_passphrase,
+                "call_model_id": self.env.ref(
+                    "iot_input_oca.model_iot_device_input"
+                ).id,
+                "call_function": "test_model_function",
+            }
+        )
+        self.address_2 = "I1"
+        self.env["iot.device.input"].create(
+            {
+                "name": "Input 2",
+                "device_id": self.device.id,
+                "address": self.address_2,
+                "call_model_id": self.env.ref(
+                    "iot_input_oca.model_iot_device_input"
+                ).id,
+                "call_function": "test_model_function",
+            }
+        )
+        self.single_input_values = [{"input": self.address_1, "value": "test"}]
+        self.values = json.dumps(
+            [
+                {"address": self.address_1, "value": "test value 1"},
+                {
+                    "address": self.address_1,
+                    "value": 2.3,
+                },  # Checking that nothing wrong happens with a non string
+                {"address": self.address_2, "value": "test value 3"},
+            ]
+        )
+
+    def test_single_controller(self):
+        res = self.url_open(
+            "/iot/%s/action" % self.serial,
+            data={"passphrase": self.input_passphrase, "value": "123"},
+        )
+        self.assertEqual(res.json()["status"], "ok")
+
+    def test_multi_input_controller_error_passphrase(self):
+        res = self.url_open(
+            "/iot/%s/multi_input" % self.device_identification,
+            data={"values": self.values},
+        ).json()
+        self.assertEqual(res["status"], "error")
+
+    def test_multi_input_controller_error_values(self):
+        res = self.url_open(
+            "/iot/%s/multi_input" % self.device_identification,
+            data={"passphrase": self.passphrase},
+        ).json()
+        self.assertEqual(res["status"], "error")
+
+    def test_multi_input_controller_syntax_error(self):
+        res = self.url_open(
+            "/iot/%s/multi_input" % self.device_identification,
+            data={"passphrase": self.passphrase, "values": "{}"},
+        ).json()
+        self.assertEqual(res["status"], "error")
+
+    def test_multi_input_controller_malformed_error(self):
+        res = self.url_open(
+            "/iot/%s/multi_input" % self.device_identification,
+            data={"passphrase": self.passphrase, "values": "{1234}"},
+        ).json()
+        self.assertEqual(res["status"], "error")
+
+    def test_multi_input_controller(self):
+        res = self.url_open(
+            "/iot/%s/multi_input" % self.device_identification,
+            data={"passphrase": self.passphrase, "values": self.values},
+        )
+        for response in res.json():
+            self.assertEqual(response["status"], "ok")
+
+    def test_multi_input_controller_unauthorized_iot_exists(self):
+        res = self.url_open(
+            "/iot/%s/check" % self.serial, data={"passphrase": self.input_passphrase}
+        ).json()
+        self.assertEqual(res["state"], True)
+
+    def test_multi_input_controller_unauthorized_iot_no_exists(self):
+        res = self.url_open(
+            "/iot/%s/check" % self.passphrase,
+            data={"passphrase": self.input_passphrase},
+        ).json()
+        self.assertEqual(res["state"], False)
diff --git a/iot_input_oca/tests/test_iot_in.py b/iot_input_oca/tests/test_iot_in.py
new file mode 100644
index 00000000..4444e6f2
--- /dev/null
+++ b/iot_input_oca/tests/test_iot_in.py
@@ -0,0 +1,95 @@
+from odoo.exceptions import ValidationError
+from odoo.tests.common import SavepointCase
+
+
+class TestIotIn(SavepointCase):
+    @classmethod
+    def setUpClass(cls):
+        super().setUpClass()
+        cls.serial = "testingdeviceserial"
+        cls.passphrase = "password"
+        cls.device = cls.env["iot.device"].create({"name": "Device"})
+        cls.device_input = cls.env["iot.device.input"].create(
+            {
+                "name": "Input",
+                "device_id": cls.device.id,
+                "active": True,
+                "serial": cls.serial,
+                "passphrase": cls.passphrase,
+                "call_model_id": cls.env.ref("iot_input_oca.model_iot_device_input").id,
+                "call_function": "test_input_device",
+            }
+        )
+        cls.iot = cls.env["iot.device.input"]
+
+    def test_device_action_count_ids(self):
+        self.assertEqual(self.device.input_count, 1)
+
+    def _get_devices(self):
+        action = self.device.action_show_input()
+        devices = self.env[action["res_model"]]
+        if action["res_id"]:
+            devices = devices.browse(action["res_id"])
+        else:
+            devices = devices.search(action["domain"])
+        return devices
+
+    def test_device_action(self):
+        devices = self._get_devices()
+        self.assertEqual(devices, self.device_input)
+        device_input_02 = self.env["iot.device.input"].create(
+            {
+                "name": "Input",
+                "device_id": self.device.id,
+                "active": True,
+                "serial": self.serial + self.serial,
+                "passphrase": self.passphrase,
+                "call_model_id": self.env.ref(
+                    "iot_input_oca.model_iot_device_input"
+                ).id,
+                "call_function": "test_input_device",
+            }
+        )
+        devices = self._get_devices()
+        self.assertIn(self.device_input, devices)
+        self.assertIn(device_input_02, devices)
+
+    def test_device_error_wrong_serial(self):
+        self.assertFalse(
+            self.iot.get_device(
+                serial=self.serial + self.serial, passphrase=self.passphrase
+            )
+        )
+
+    def test_device_error_wrong_passphrase(self):
+        self.assertFalse(
+            self.iot.get_device(
+                serial=self.serial, passphrase=self.passphrase + self.passphrase
+            )
+        )
+
+    def test_device_error_archived(self):
+        self.device_input.active = False
+        self.assertFalse(
+            self.iot.get_device(serial=self.serial, passphrase=self.passphrase)
+        )
+
+    def test_device_error_missing_data(self):
+        with self.assertRaises(ValidationError):
+            self.iot.get_device(serial=False, passphrase=self.passphrase)
+
+    def test_error_execution_without_device(self):
+        res = self.iot.call_device("hello")
+        self.assertEqual(res["status"], "error")
+
+    def test_device_input_calling(self):
+        iot = self.iot.get_device(serial=self.serial, passphrase=self.passphrase)
+        self.assertEqual(iot, self.device_input)
+        self.assertEqual(0, self.device_input.action_count)
+        args = "hello"
+        res = iot.call_device(args)
+        self.assertEqual(res, {"status": "ok", "value": args})
+        self.assertTrue(self.device_input.action_ids)
+        self.assertEqual(self.device_input.action_ids.args, str(args))
+        self.assertEqual(self.device_input.action_ids.res, str(res))
+        self.assertEqual(1, self.device_input.action_count)
diff --git a/iot_input_oca/tests/test_iot_message.py b/iot_input_oca/tests/test_iot_message.py
new file mode 100644
index 00000000..2df859b6
--- /dev/null
+++ b/iot_input_oca/tests/test_iot_message.py
@@ -0,0 +1,46 @@
+from odoo_test_helper import FakeModelLoader
+
+from odoo.tests import SavepointCase
+
+
+class TestIotInputMessage(SavepointCase):
+    @classmethod
+    def setUpClass(cls):
+        super().setUpClass()
+        cls.loader = FakeModelLoader(cls.env, cls.__module__)
+        cls.loader.backup_registry()
+
+        from .models import ResPartner
+
+        cls.loader.update_registry((ResPartner,))
+
+        cls.partner = cls.env["res.partner"].create({"name": "IoT demo partner"})
+        cls.serial = "testingdeviceserial"
+        cls.passphrase = "password"
+        cls.device = cls.env["iot.device"].create({"name": "Device"})
+        cls.device_input = cls.env["iot.device.input"].create(
+            {
+                "name": "Input",
+                "device_id": cls.device.id,
+                "active": True,
+                "serial": cls.serial,
+                "passphrase": cls.passphrase,
+                "call_model_id": cls.env.ref("base.model_res_partner").id,
+                "call_function": "test_fake_iot_input",
+            }
+        )
+        cls.iot = cls.env["iot.device.input"]
+
+    @classmethod
+    def tearDownClass(cls):
+        cls.loader.restore_registry()
+        super().tearDownClass()
+
+    def test_message(self):
+        original_messages = self.partner.message_ids
+        res = self.device_input.call_device(self.partner.id)
+        self.assertEqual("ok", res["status"])
+        new_message = self.partner.message_ids - original_messages
+        self.assertTrue(new_message)
+        self.assertEqual(1, len(new_message))
+        self.assertRegex(new_message.body, ".*Detected automatically by.*")
diff --git a/iot_input_oca/tests/test_iot_multi_input.py b/iot_input_oca/tests/test_iot_multi_input.py
new file mode 100644
index 00000000..0953bfc9
--- /dev/null
+++ b/iot_input_oca/tests/test_iot_multi_input.py
@@ -0,0 +1,174 @@
+from odoo.tests.common import SavepointCase
+
+
+class TestIotIn(SavepointCase):
+    @classmethod
+    def setUpClass(cls):
+        super().setUpClass()
+        cls.device_identification = "test_device_name"
+        cls.passphrase = "password"
+        cls.device = cls.env["iot.device"].create(
+            {
+                "name": "Device",
+                "device_identification": cls.device_identification,
+                "passphrase": cls.passphrase,
+            }
+        )
+        cls.address_1 = "I0"
+        cls.device_input_1 = cls.env["iot.device.input"].create(
+            {
+                "name": "Input 1",
+                "device_id": cls.device.id,
+                "address": cls.address_1,
+                "call_model_id": cls.env.ref("iot_input_oca.model_iot_device_input").id,
+                "call_function": "test_model_function",
+            }
+        )
+        cls.address_2 = "I1"
+        cls.env["iot.device.input"].create(
+            {
+                "name": "Input 2",
+                "device_id": cls.device.id,
+                "address": cls.address_2,
+                "call_model_id": cls.env.ref("iot_input_oca.model_iot_device_input").id,
+                "call_function": "test_model_function",
+            }
+        )
+        cls.single_input_values = [{"input": cls.address_1, "value": "test"}]
+
+    def test_multi_input_error_wrong_identification(self):
+        self.assertEqual(
+            self.env["iot.device"].parse_multi_input(
+                self.device_identification + self.device_identification,
+                self.passphrase,
+                self.single_input_values,
+            )["status"],
+            "error",
+        )
+
+    def test_multi_input_error_wrong_passphrase(self):
+        self.assertEqual(
+            self.env["iot.device"].parse_multi_input(
+                self.device_identification,
+                self.passphrase + self.passphrase,
+                self.single_input_values,
+            )["status"],
+            "error",
+        )
+
+    def test_multi_input_error_no_inputs(self):
+        self.assertEqual(
+            self.env["iot.device"].parse_multi_input(
+                self.device_identification, self.passphrase, False
+            )["status"],
+            "error",
+        )
+
+    def test_multi_input_non_existing_address(self):
+        non_existing_address = "I3"
+        for response in self.env["iot.device"].parse_multi_input(
+            self.device_identification,
+            self.passphrase,
+            [{"address": non_existing_address, "value": "test value 1"}],
+        ):
+            self.assertEqual(response["status"], "error")
+
+    def test_error_missing_parameter(self):
+        for response in self.env["iot.device"].parse_multi_input(
+            self.device_identification, self.passphrase, [{"address": self.address_1}]
+        ):
+            self.assertEqual(response["status"], "error")
+
+    def test_error_with_extra_args(self):
+        for response in self.env["iot.device"].parse_multi_input(
+            self.device_identification,
+            self.passphrase,
+            [{"address": self.address_1, "uuid": "abc"}],
+        ):
+            self.assertEqual(response["status"], "error")
+            self.assertTrue("uuid" in response)
+
+    def test_error_no_address_with_extra_args(self):
+        for response in self.env["iot.device"].parse_multi_input(
+            self.device_identification, self.passphrase, [{"uuid": "abc"}]
+        ):
+            self.assertEqual(response["status"], "error")
+            self.assertTrue("uuid" in response)
+
+    def test_error_no_address(self):
+        for response in self.env["iot.device"].parse_multi_input(
+            self.device_identification, self.passphrase, [{"value": "test value"}]
+        ):
+            self.assertEqual(response["status"], "error")
+
+    def test_correct_one_input(self):
+        for response in self.env["iot.device"].parse_multi_input(
+            self.device_identification,
+            self.passphrase,
+            [{"address": self.address_1, "value": "test"}],
+        ):
+            self.assertEqual(response["status"], "ok")
+
+    def test_correct_two_inputs(self):
+        for response in self.env["iot.device"].parse_multi_input(
+            self.device_identification,
+            self.passphrase,
+            [
+                {"address": self.address_1, "value": "test value 1"},
+                {
+                    "address": self.address_1,
+                    "value": 2.3,
+                },  # Checking that nothing wrong happens with a non string
+                {"address": self.address_2, "value": "test value 3"},
+            ],
+        ):
+            self.assertEqual(response["status"], "ok")
+
+    def test_correct_with_extra_args(self):
+        response_with_uuid = [
+            {"address": self.address_1, "value": "test value 1", "uuid": "abc"},
+            {"address": self.address_1, "value": "test value 2", "uuid": "def"},
+            {"address": self.address_2, "value": "test value 3", "uuid": "ghi"},
+        ]
+        for response in self.env["iot.device"].parse_multi_input(
+            self.device_identification, self.passphrase, response_with_uuid
+        ):
+            self.assertTrue(response["uuid"])
+            self.assertEqual(
+                response["message"],
+                [x for x in response_with_uuid if x["uuid"] == response["uuid"]][0],
+            )
+
+    def test_error_archived_device(self):
+        self.device.active = False
+        self.assertEqual(
+            self.env["iot.device"].parse_multi_input(
+                self.device_identification,
+                self.passphrase,
+                [{"address": self.address_1, "value": "test"}],
+            )["status"],
+            "error",
+        )
+
+    def test_error_archived_device_input(self):
+        self.device_input_1.active = False
+        for result in self.env["iot.device"].parse_multi_input(
+            self.device_identification,
+            self.passphrase,
+            [{"address": self.address_1, "value": "test"}],
+        ):
+            self.assertEqual(
+                result["status"], "error",
+            )
+
+    def test_error_archived_device_input_extra_args(self):
+        self.device_input_1.active = False
+        for result in self.env["iot.device"].parse_multi_input(
+            self.device_identification,
+            self.passphrase,
+            [{"address": self.address_1, "value": "test", "uuid": "ghi"}],
+        ):
+            self.assertEqual(
+                result["status"], "error",
+            )
+            self.assertEqual(result["uuid"], "ghi")
diff --git a/test-requirements.txt b/test-requirements.txt
new file mode 100644
index 00000000..66bc2cba
--- /dev/null
+++ b/test-requirements.txt
@@ -0,0 +1,1 @@
+odoo_test_helper