If you unplug the iot box and wait 15 seconds or so, and then plug it
back in, it's possible to get an exception from helpers.get_ip, because
neither the wired nor the wireless interface has an IP. In that case,
the exception would kill the Manager thread, since it was uncaught.
This fix adds a catch-all to the Manager thread that logs any uncaught
exceptions and continues its main loop.
closesodoo/odoo#77111
X-original-commit: a9808a4efe46c4ba7948f5d6a8757546c6b4147b
Signed-off-by: Quentin Lejeune (qle) <qle@odoo.com>
Signed-off-by: Raf Geens <raf-odoo@users.noreply.github.com>
get_ip and get_mac_address respectively try to get the IP and MAC from
the IoT box's active network interface. If the interface isn't fully up
yet (due to waiting on a slow DHCP server response for example), both
functions can end up raising a KeyError exception since neither
interface has a value.
This can be bad if it's uncaught and happens in something like the
Manager thread, potentially killing it as a result. This can then
disrupt the rest of the application. The network being gone for a bit or
slow is something that can happen during everyday use, so we should be
robust against it.
Since the box can't do any useful work without an active network
connection, this fix keeps retrying until one of the interfaces comes
back up.
opw-2357144
closesodoo/odoo#77052
X-original-commit: d0359858b17fb84c04c267bdf5cc1626569f5cce
Signed-off-by: Quentin Lejeune (qle) <qle@odoo.com>
The license is missing in most enterprise manifest so
the decision was taken to make it explicit in all cases.
When not defined, a warning will be triggered starting from
14.0 when falling back on the default LGPL-3.
closesodoo/odoo#74245
Related: odoo/design-themes#48
Related: odoo/enterprise#19862
Signed-off-by: Xavier Dollé (xdo) <xdo@odoo.com>
We call the status of the hostapd in each request of 'get_odoo_server_url()' and 'get_ssid()'
And this call display in the log the status '0' or 'inactive' in the log
With this commit we hide this useless information
closesodoo/odoo#72133
X-original-commit: e5e9f9f91cf9bf35f1e0b307008840a0de134e2f
Signed-off-by: Quentin Lejeune (qle) <qle@odoo.com>
Currently, none of the classes derived from Interface use `super`. If
it's added, for example by adding this to `SocketInterface`:
```
def __init__(self):
super().__init__()
```
, a deprecation warning will appear in Python 3.6 and 3.7:
```
2021-04-30 13:14:25,000 24736 WARNING ? py.warnings: /home/pi/odoo/addons/hw_drivers/iot_handlers/interfaces/SocketInterface.py:11: DeprecationWarning: class not set defining 'SocketInterface' as <class 'SocketInterface.py.SocketInterface'>. Was classcell propagated to type.new?
class SocketInterface(Interface):
```
In Python 3.8 this is no longer a warning and becomes a `RuntimeError`.
The reason this happens is that `InterfaceMetaClass` caches the results
of the `__new__` calls it does in `interfaces`. CPython's data model
specifies that when calling `__new__`, the cell for `__class__` needs to
be passed along to the parent class: https://docs.python.org/3/reference/datamodel.html#creating-the-class-object .
See https://docs.python.org/3/c-api/cell.html for a definition of what
a cell is.
Because of the caching, this doesn't happen when `__new__` is called
multiple times for the same class. In the case of the `SocketInterface`
example, `__new__` is called twice: first when it's imported directly by
`load_iot_handlers` (https://github.com/odoo/odoo/blob/841c016913a87133bf7257c62ae5f6bf7d99e06d/addons/hw_drivers/main.py#L81)
and second when `IngenicoDriver` imports it. The `__class__` cell is
different each time in that case. With the caching present, this means
the second cell isn't propagated correctly, resulting in the warning /
error.
After `load_iot_handlers` has finished, the `Manager`'s `run` method
iterates over `interfaces`, instantiating and starting the loaded
classes. Because of this, simply removing the caching appears to be
sufficient to avoid the issue while keeping the end result the same.
This issue was encountered while forward-porting a V13 PR, which adds a
`super` use to `SocketInterface`. The issue didn't occur in V13, because
the metaclass doesn't have a cache there.
I found a second problem resulting from the caching. I had noticed that
the `socket_devices` dict the `IngenicoDriver` had access to did not
have the same contents as the one the `SocketInterface` was operating
on. This means that whenever you called the `disconnect` function on the
`IngenicoDriver`, which deletes its entry from `socket_devices`, it will
always fail. The bluetooth driver seems to be impacted by the same.
It turns out the reason for that is how downloaded modules get loaded in
`load_iot_handlers`. That logic (using `exec_module`) doesn't actually
import the module, it just executes the code (registering the interfaces
and drivers as a side-effect). This means the module doesn't get cached
in sys.modules. That means that when another module (`IngenicoDriver`)
imports that same module (`SocketInterface`), Python will execute the
entire contents again, in this case effectively replacing socket_devices
with a new dict, which `IngenicoDriver` gets a reference to, while the
`SocketInterface` thread that runs is still using the old reference to
the original dict. Meaning the two are out of sync. See
https://docs.python.org/3/reference/import.html#the-module-cache for
details on how the import caching works.
The reason the classes get out of sync is because the metaclass doesn't
update interfaces when the second actual import happens, so the
`SocketInterface` class that gets instantiated holds a reference to the
old `socket_devices` dict. Removing the caching removes that problem as
well. If there's no caching, both the `SocketInterface` class and
`IngenicoDriver` will hold a reference to the same instance of
`socket_devices`.
X-original-commit: edffdd10f3ceb3826bf8897f93fa8290d7fce1ec
This commit was originally part of a larger commit related to an
Ingenico double connection deadlock bugfix in V13, but in V14 most of
the related code has moved to enterprise. When a driver thread is
running, calling `disconnect` on it will delete it from iot_devices. If
the driver thread gets added to iot_devices in the Interface thread
after starting it, this means there is a tiny window of time where
`disconnect` could be called and the thread wouldn't be in iot_devices
yet, resulting in an exception. This change puts the driver thread in
iot_devices before starting it, avoiding that scenario and the need to
check in `disconnect` for that happening.
X-original-commit: 6c24d30c3910e67ed751327d1554e2e8cf5e958b
This commit will add the needed ESLint configurations on the JS files.
These configurations are added if the JS file uses a different
environment (serviceworker, node, etc) or if it uses a specific global
(google, ace, etc).
Co-authored-by: Samuel Degueldre <sad@odoo.com>
* The result of `plaintext2html` is fully controlled and
markup-safe (the first thing we do is escape the input).
* For `append_content_to_html`, we assume the inputs are HTML and the
output is thus always properly HTML.
Alternatively, we may want to `Markup("%s%s") % ...` and require the
inputs to be properly marked? That seems like a good idea.
* In `_replace_local_links`, applying re.sub will strip out the markup
mark, so store it and reapply it on output if necessary.
That one is a big gnarly, because if the input to ustr is
markup-safe bytes (e.g. qweb rendering output) then the output is a
Markup object, but if the input is str then the output is str, so we
need to check before and after unless... we update ustr to check for
subclasses instead of exact type?
* In `_prepend_preview` the issue is similar to that of
`append_content_to_html`, though in this case we should *not* trust
the input, so we can flag the "parent document" as Markup and format
the preview bit in.
* And since we're marking mail's jinja output as safe, do the same for
web and iot.
Sadly there doesn't seem to be any hook for doing that at the
environment level of jinja, so every `Template.render` site has to
be marked.
Some requests are sended without specific action.
So we need set these call to fit to a default action
who is a empty string.
Pull requeste related: 63375
closesodoo/odoo#67089
Signed-off-by: pimodoo <pimodoo@users.noreply.github.com>
Only the 'action' requests have the 'data' parameter set, so any other
request triggering a 'device_changed' failed.
closesodoo/odoo#66826
X-original-commit: 0850814dda9802973e48ef89d6a81d61fc36a646
Signed-off-by: Quentin Lejeune (qle) <qle@odoo.com>
Signed-off-by: Antoine Prieëls <aprieels@users.noreply.github.com>
Add possibilities to map actions for the drivers
To avoid a sequence of "if elif else" we integrate a '_actions()' dictionary
where the key is the name of the action and the value is
the name of the function to be executed in the drivers
with the action data as a parameter
closesodoo/odoo#63375
Related: odoo/enterprise#15310
Signed-off-by: pimodoo <pimodoo@users.noreply.github.com>
Add all the request data in events triggered by IoT actions.
closesodoo/odoo#61798
Taskid: 2320958
X-original-commit: a8c56602ba8301b6e901be7ffeaa219d77401f79
Related: odoo/enterprise#14763
Signed-off-by: Quentin Lejeune (qle) <qle@odoo.com>
Events coming from the IoT Box were lost in two cases:
1. Create a listener for device 1
2. Send an action to device 1
--> If the action arrives before the listener the event is never sent
to the DB
1. Setup up two listeners for devices 1 & 2
2. After a few seconds, send two consecutive actions to devices 1 & 2
--> Everytime a longpolling request arrives, a new threading.Event
object is created. The first action sets the event, then, before the
new longpolling request arrives, the second action sets the same event,
which is overwritten once the new longpolling request arrives.
We now maintain a list of events, and when a longpolling request
arrives on the IoT Box, we make sure that all events that occured in
the last 5 seconds were received by the DB. If no events were pending,
we wait 50 seconds to check if a new one pops up.
Taskid: 2320958
X-original-commit: e3260712ce96a8d81bf807574c334d92c37c6ae4
Add support for Star Line Mode protocol, used by most Star receipt
printers.
closesodoo/odoo#60371
Taskid: 2365648
X-original-commit: cd0545b98fc1e7a66dd46eb6a283736ef58ac4ff
Signed-off-by: Quentin Lejeune (qle) <qle@odoo.com>
Signed-off-by: Antoine Prieëls <aprieels@users.noreply.github.com>
We used to patch http.py using a diff. This was really not practical
because every time the file was modified, the diff had to be recreated.
We now override the specific methods directly.
closesodoo/odoo#60366
X-original-commit: a6012f03ff02f04a3d128e33326f932fd22f0ced
Signed-off-by: Quentin Lejeune (qle) <qle@odoo.com>
Signed-off-by: Antoine Prieëls <aprieels@users.noreply.github.com>
We sometimes encountered IoT Boxes crashing because the remount failed.
As this isn't a big issue, we won't check the return value of the call
to `mount`.
closesodoo/odoo#59438
X-original-commit: 5f9874da0f5f5b27c546cd248d08299f0e65544b
Signed-off-by: Quentin Lejeune (qle) <qle@odoo.com>
Signed-off-by: Antoine Prieëls <aprieels@users.noreply.github.com>
The path to folder of images of IoT has change.
So we adapt the path for the upgrade of IoT
closesodoo/odoo#57978
X-original-commit: 9512a23f48176fe0e7970039c824281c4af18162
Signed-off-by: Quentin Lejeune (qle) <qle@odoo.com>
If IoT Box is on access point mode the box try to reach https://iot-proxy.odoo.com
to get pairing code. So the box try while 5 minutes to reach iot-proxy
and send request on network every 10 secondes.
Now we add a condition 'if not access_point()' to send these request.
closesodoo/odoo#57976
X-original-commit: 901dc987c0204a7df2b811bb430f31eabf204fbb
Signed-off-by: Quentin Lejeune (qle) <qle@odoo.com>
We make request to iot-proxy.odoo.com every 10 secondes
while 5 minutes.
But we have a traceback if we don't have a internet connection.
So we put a 'try except' to catch error
Related 841c016913a8
closesodoo/odoo#57567
X-original-commit: 3227490e270a1f5b98ef7811edca59e9aa1b6b55
Signed-off-by: Quentin Lejeune (qle) <qle@odoo.com>
When printing a long receipt from the POS, the printer crashed, printed
random characters and needed to be rebooted to print other receipts.
The problem was that there's a limitation of height when printing
images with ESC/POS (see [ESC/POS documentation](http://www.starmicronics.com/support/mannualfolder/escpos_cm_en.pdf), page 158).
We then split the image into slices and print slices with separate
commands.
closesodoo/odoo#57512
X-original-commit: ab06df30557af90f3e704d4cfc1e6da66f7708b7
Signed-off-by: Quentin Lejeune (qle) <qle@odoo.com>
Signed-off-by: Antoine Prieëls <aprieels@users.noreply.github.com>
The threads of devices were still running after `disconnect` had been
called. We add a `_stopped` flag that is set when the thread should be
stopped.
closesodoo/odoo#56500
X-original-commit: 639a4e4fc72567a9655599eef150fabefaf1ff2e
Related: odoo/enterprise#12651
Signed-off-by: Quentin Lejeune (qle) <qle@odoo.com>
Signed-off-by: Antoine Prieëls <aprieels@users.noreply.github.com>
- Split driver.py to multiple files
- Remove hw_proxy module as most of its routes were not used and
move remaingin routes to a controller in hw_drivers
- Add missing coding and license lines at the beginning of files
- Reorder imports and remove unused ones
- Rename device_id to device_identifier for clarity
- Rename screen to display for consistency
- Other minors improvements
Taskid: 1973956
X-original-commit: 841c016913a87133bf7257c62ae5f6bf7d99e06d
`device_name` and `scanner_name` were defined outside of the scope of
the function where they were used in.
We move them and try to simplify the logic a bit.
closesodoo/odoo#56454
X-original-commit: e59e311578aa0b4539ef27580462a2c2e1dce970
Signed-off-by: Quentin Lejeune (qle) <qle@odoo.com>
Signed-off-by: Antoine Prieëls <aprieels@users.noreply.github.com>
Some scanner are detected like keyboard because they do not meet
the conditions to be supported as a scanner by the driver.
So we add the possibility to manually switch the type of device
between scanner and keyboard.
closesodoo/odoo#56053
Related: odoo/enterprise#12370
Signed-off-by: Quentin Lejeune (qle) <qle@odoo.com>
Some network Zebra printer are not detected because
the protocol 'socket' is not supported.
Now we add this protocol in the 'supported' function
closesodoo/odoo#56146
X-original-commit: f7fa40bdbbd765caf8fe528fff949b4dccf3d8c2
Signed-off-by: Quentin Lejeune (qle) <qle@odoo.com>
Signed-off-by: pimodoo <pimodoo@users.noreply.github.com>
We move the IoT Box version file from /home/pi to /var/odoo
so its not overriden after an auto-flash of the IoT Box.
closesodoo/odoo#54063
X-original-commit: ce0700ce401523267b5a8bd5665a368cfea24912
Signed-off-by: Quentin Lejeune (qle) <qle@odoo.com>
Trying to call display_refresh or update_url when no screen was
connected to the IoT Box and the default distant_display was created
resulted in an error.
closesodoo/odoo#53975
X-original-commit: 77768b93bc64d47abdbd4abd48c386acb293815e
Signed-off-by: Quentin Lejeune (qle) <qle@odoo.com>
Signed-off-by: Antoine Prieëls <aprieels@users.noreply.github.com>
In Chrome 84, mixed content will be completely blocked for security
reasons ([see blog](https://blog.chromium.org/2019/10/no-more-mixed-messages-about-https.html))
Other browsers will probably follow in the next months.
As IoT Boxes don't have a valid certificate before connecting to a DB,
we used mixed passive content to communicate with the boxes.
This won't be possible anymore, and we have no possible way to
communicate directly from the browser to the box.
- When an IoT Box boots without registered DB, a unique code will be
created with a validity of 5 minutes.
- This code will be shown on the customer display and printed on the
status ticket.
- The box will call a route on odoo.com and a record will be created
in odoo.com with the unique code.
- The user will have to enter the code manually in his DB to connect
to the IoT Box, the DB will then contact odoo.com to search for a
record containing the unique code. If it's found, the
`openerp.enterprise.database` will be added to the record.
- The box will then query odoo.com at regular intervals (10 seconds)
to check if a DB is linked to the code.
closesodoo/odoo#53623
Taskid: 2246535
X-original-commit: c55f12e32598a713105f3c049ac053e46ba15bb2
Related: odoo/enterprise#11421
Signed-off-by: pimodoo <pimodoo@users.noreply.github.com>
Using a few regex like
\((_\(.*%s.*)(\) % )([\w\[\]][\w .\[\]\(\)'"]*)\)
($1, $3))
Old syntax is still compatible but starts the migration to the new
syntax that catches error.
When we print a ticket status with a thermal printer we need printer's device-id
But if we add manually a printer this device-id doesn't exist
So now we update de devices list with a supported = True if
printer are manually added
closesodoo/odoo#53072
X-original-commit: 89bbc555ecf520ee34a9b1292a2bdb5c937b18e2
Signed-off-by: Quentin Lejeune (qle) <qle@odoo.com>
The IoT Box detects printers automatically under certain conditions.
And so there are printers that are not detected by the box
and cannot be used in Odoo.
With this commit we give the possibility to add printers manually
with Cups and to be able to use them in Odoo.
closesodoo/odoo#52154
Signed-off-by: Quentin Lejeune (qle) <qle@odoo.com>
When the route '/hw_drivers/box/connect' is called to connect an IoT Box to a DB,
the checkout on the branch of the DB is not performed and incompatibility can occur.
With this fix we relaunch Odoo via a parallel thread in order to be able to respond to the request...
closesodoo/odoo#52513
X-original-commit: 9aca7c464cef492c495a0c72d870b7075187dc63
Signed-off-by: Quentin Lejeune (qle) <qle@odoo.com>
- The checkout to switch to the branch of the connected DB was not
processed correctly because the command used to clear the drivers
failed, raising an exception:
rm: cannot remove '/home/pi/odoo/addons/hw_drivers/drivers/__pycache__': Is a directory
- The location of the drivers has been changed in master. So, even if we
perform a checkout, the addons/hw_drivers/drivers directory doesn't
exist. The get_resource_path('hw_drivers', 'drivers') then returned
False instead of the correct path and the extraction of the zip file
failed.
closesodoo/odoo#52448
Signed-off-by: Quentin Lejeune (qle) <qle@odoo.com>
The `get_string` method from the `pyusb` package has changed its
signature after version 1.0.0b1 so we used to force the IoT Box to use
this version to avoid an error. The problem is that version 1.0.0b1
has dependencies that raise DeprecationWarings in Raspbian Buster.
We then want to update the version of pyusb that is installed on the
IoT Box in 14.0.
As the Driver might be loaded to old versions of the IoT Box as well
as new ones, we need to check what version of the package is present
on the IoT Box before calling `get_string`.
This check will be removed in 14.0, as people will have to use the
latest version of the IoT Box.
closesodoo/odoo#52374
X-original-commit: e5475ae8ceca2121d15985ac7446f90dbd59b485
Signed-off-by: Quentin Lejeune (qle) <qle@odoo.com>
Signed-off-by: Antoine Prieëls <aprieels@users.noreply.github.com>
Previously, we tested the `supported` methods of all drivers
sequentially in alphabetical order of file names. If you wanted to
extend a driver, the `supported` method of your driver could never be
tested if the one of its parent was tested first.
We've now added a priority order to drivers so that by default the
extending driver will always be tested before the extended driver.
You can still do something similar to what `is_tested_last` did by
manually setting the priority of a driver to 0.
Ex: The way barcode scanners is really similar to keyboards, but still
requires a few modifications in the driver. We couldn't extend the
keyboard driver easily because the supported method of barcode scanners
had to be more strict than the one of keyboards. If the
KeyboardUSBDriver was tested first, scanners were recognized as
keyboard and didn't have all the specific features of scanners.
TaskID: 2082282
Until now, to detect new types of devices on the IoT Box, we had to
modify driver.py. If partners wanted to connect a new type of device,
they had to modify directly the files on the Box, meaning that after
each new build they had to re-apply all their modifications.
We remove the loops that detected the connected devices and replace
them by `Interfaces`. All interfaces will be loaded from the connected
Odoo instance with the corresponding drivers.
TaskID: 2082282
Exceptions were not logged correctly due to a typo in ExceptionLogger.
closesodoo/odoo#51191
X-original-commit: 9ac2ad249bddc631de9a9d587058d6109918f584
Signed-off-by: Quentin Lejeune (qle) <qle@odoo.com>
Signed-off-by: Antoine Prieëls <aprieels@users.noreply.github.com>
Steps to reproduce:
- Start the IoT Box with a monitor plugged in
- Unplug the monitor
- Restart the Odoo service (i.e. connect the IoT Box to a DB)
- No devices are detected
The problem came from the fact that `tvservice -l` and `tvservice -n`
have different behaviors when a monitor is disconnected:
- `tvservice -l` still says that a device is attached
- `tvservice -n` cannot detect the name of the device so it logs an
error to stderr but still has a return value of 0 so we read an empty
string from stdout.
The `get_connected_displays` function raised an exception because the
format of the returned string was not the one we excepted. The other
loops were then not started and no devices at all were detected.
closesodoo/odoo#50839
X-original-commit: ab6ec2ab6d30a86f9741da4b1986831772004d91
Signed-off-by: pimodoo <pimodoo@users.noreply.github.com>
Signed-off-by: Antoine Prieëls <aprieels@users.noreply.github.com>
When we change the version of branch we keep drivers.
But drivers are not compatible with all branch and Odoo
on the IoT Box can't start.
So we remove all drivers before checkout on another branch
closesodoo/odoo#50140
X-original-commit: 4e97aec6717697c742e5e0b09f00ab7dec09712f
Signed-off-by: pimodoo <pimodoo@users.noreply.github.com>
Before this commit, a lot of leftover import shims existed in the
codebase for py2-py3 compatibility, these are no longer needed since
Odoo 13.0+ doesn't support Python 2 anymore and is (finally) in EOL.
With this commit, these shims are dropped, making the code cleaner,
easier to read and with one less dependency.
Queue -> queue -> py2-py3 compatibility
xmlrpclib -> xmlrpc.client -> py2-py3 compatibility
ConfigParser -> configparser -> py2-py3 compatibility
itertools.izip_longest -> itertools.zip_longest -> py2-py3 compatibility
urllib -> urllib.request -> py2-py3 compatibility
__builtins__ -> builtins -> py2-py3 compatibility
_winreg -> winreg -> py2-py3 compatibility
mock -> unittest.mock -> merged into CPython
The debian/fedora packages and requirements.txt have been updated accordingly
closesodoo/odoo#44601
Related: odoo/enterprise#8141
Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
This reverts commit 9d43308a8f6b521d3d18f7fc472303f58f56a0c3.
No one should be using MPD in production at the moment but
we'll still leave it in the buiold of the Box, just to be sure.
X-original-commit: 129101815d5846d5b53148546b19bdd791f22aac
We use a library to get mac address of IoT in homepage.
however we already have a function that does this in the helper in hw_drivers
closesodoo/odoo#46631
X-original-commit: ae78e9cdde777ffac6f08a35dd00a540c92130bb
Signed-off-by: Quentin Lejeune (qle) <qle@odoo.com>
We had two issues when reading the weight from a scale connected to
the IoT Box :
When using the '/hw_proxy/scale_read' route, if the same weight was
read twice, the value in PoS was reset to 0.
If the product was placed on the scale before opening the weight
screen, the weight was never read.
closesodoo/odoo#46432
X-original-commit: a08c5157f0b042e2ee250fc7b431b90451c7781a
Signed-off-by: Antoine Prieëls <aprieels@users.noreply.github.com>
Remove the MPD server and Six configuration from the IoT Box.
MPD will be replaced by TIM, which doesn't require the IoT Box.
closesodoo/odoo#46424
Taskid: 2188566
X-original-commit: 9d43308a8f6b521d3d18f7fc472303f58f56a0c3
Signed-off-by: Antoine Prieëls <aprieels@users.noreply.github.com>
For update correctly the route list of IoT after loading driver
we need set 'http.addons_manifest' to a empty json
Linked to 97c09e1c77284836c7c46b4e70d4f12eb48ce91b
Reboot not needed after a update
Linked to b77486753b7ae220a531ee09c529fb5eb944b0e2
Linked to 181a62cb57e143611ca1fbf0779cfd041d2a3cf8
closesodoo/odoo#46386
X-original-commit: 87b127efed97c1f6fad18d6ee6b5924a9b2c70f2
Signed-off-by: Quentin Lejeune (qle) <qle@odoo.com>