theengs / gateway

Multi platform Multi devices BLE Bluetooth to MQTT gateway leveraging Theengs Decoder
https://gateway.theengs.io
GNU General Public License v3.0
118 stars 31 forks source link

TypeError: unsupported format - Docker version #205

Open radim-kliment opened 10 months ago

radim-kliment commented 10 months ago

Describe the bug After a start of a service via docker compose I get this error:

blegatt  | Traceback (most recent call last):
blegatt  |   File "<frozen runpy>", line 198, in _run_module_as_main
blegatt  |   File "<frozen runpy>", line 88, in _run_code
blegatt  |   File "/opt/venv/lib/python3.11/site-packages/TheengsGateway/__main__.py", line 5, in <module>
blegatt  |     main()
blegatt  |   File "/opt/venv/lib/python3.11/site-packages/TheengsGateway/__init__.py", line 57, in main
blegatt  |     run(configuration, config_path)
blegatt  |   File "/opt/venv/lib/python3.11/site-packages/TheengsGateway/ble_gateway.py", line 591, in run
blegatt  |     asyncio.run(diagnostics(config_path))
blegatt  |   File "/usr/local/lib/python3.11/asyncio/runners.py", line 190, in run
blegatt  |     return runner.run(main)
blegatt  |            ^^^^^^^^^^^^^^^^
blegatt  |   File "/usr/local/lib/python3.11/asyncio/runners.py", line 118, in run
blegatt  |     return self._loop.run_until_complete(task)
blegatt  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
blegatt  |   File "/usr/local/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
blegatt  |     return future.result()
blegatt  |            ^^^^^^^^^^^^^^^
blegatt  |   File "/opt/venv/lib/python3.11/site-packages/TheengsGateway/diagnose.py", line 172, in diagnostics
blegatt  |     await _adapters()
blegatt  |   File "/opt/venv/lib/python3.11/site-packages/TheengsGateway/diagnose.py", line 155, in _adapters
blegatt  |     _section(adapter, properties)  # type: ignore[arg-type]
blegatt  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
blegatt  |   File "/opt/venv/lib/python3.11/site-packages/TheengsGateway/diagnose.py", line 55, in _section
blegatt  |     print(f"| {name:{max_name}} | {value:{max_value}} |")

Environment last version of docker and docker compose on raspberry pi 3b yml:

version: '3.8'
services:
  ble2mqtt:
    container_name: blegatt
    restart: unless-stopped
    image: theengs/gateway
    volumes:
      - /var/run/dbus:/var/run/dbus
    environment:
      - TZ=Europe/Berlin
      - MQTT_HOST=redacted
      - MQTT_USERNAME=redacted
      - MQTT_PASSWORD=redacted
      - LOG_LEVEL=DEBUG
      - ENABLE_TLS=true
      - ENABLE_WEBSOCKET=true

Additional context


blegatt  | 
blegatt  | ## Package Versions
blegatt  | 
blegatt  | | Name               | Value  |
blegatt  | |--------------------|--------|
blegatt  | | Theengs Gateway    | 1.2.0  |
blegatt  | | Theengs Decoder    | 1.6.4  |
blegatt  | | Bleak              | 0.21.1 |
blegatt  | | Bluetooth Clocks   | 0.2.0  |
blegatt  | | Bluetooth Numbers  | 1.1.1  |
blegatt  | | Paho MQTT          | 1.6.1  |
blegatt  | | Bluetooth Adapters | 0.16.1 |
blegatt  | 
blegatt  | ## Python
blegatt  | 
blegatt  | | Name           | Value                 |
blegatt  | |----------------|-----------------------|
blegatt  | | Version        | 3.11.7                |
blegatt  | | Implementation | CPython               |
blegatt  | | Compiler       | GCC 10.2.1 20210110   |
blegatt  | | Executable     | /opt/venv/bin/python3 |
blegatt  | 
blegatt  | ## Operating System
blegatt  | 
blegatt  | | Name         | Value                                  |
blegatt  | |--------------|----------------------------------------|
blegatt  | | System       | Linux                                  |
blegatt  | | Release      | 6.1.21-v7+                             |
blegatt  | | Version      | #1642 SMP Mon Apr  3 17:20:52 BST 2023 |
blegatt  | | Machine type | armv7l                                 |
blegatt  | | Distribution | Debian GNU/Linux 11 (bullseye)         |
blegatt  | 
blegatt  | ## Configuration
blegatt  | 
blegatt  | File: /root/theengsgw.conf
blegatt  | 
blegatt  | ```
blegatt  | {
blegatt  |     "adapter": "hci0",
blegatt  |     "bindkeys": {},
blegatt  |     "ble_scan_time": 60,
blegatt  |     "ble_time_between_scans": 60,
blegatt  |     "discovery": true,
blegatt  |     "discovery_device_name": "TheengsGateway",
blegatt  |     "discovery_filter": "[IBEACON]",
blegatt  |     "discovery_topic": "homeassistant",
blegatt  |     "enable_tls": true,
blegatt  |     "enable_websocket": true,
blegatt  |     "hass_discovery": true,
blegatt  |     "host": "redacted",
blegatt  |     "identities": {},
blegatt  |     "log_level": "DEBUG",
blegatt  |     "lwt_topic": "home/TheengsGateway/LWT",
blegatt  |     "pass": "***",
blegatt  |     "port": 1883,
blegatt  |     "presence": false,
blegatt  |     "presence_topic": "home/presence/TheengsGateway",
blegatt  |     "publish_advdata": false,
blegatt  |     "publish_all": true,
blegatt  |     "publish_topic": "home/TheengsGateway/BTtoMQTT",
blegatt  |     "scanning_mode": "active",
blegatt  |     "subscribe_topic": "home/+/BTtoMQTT/undecoded",
blegatt  |     "time_format": "0",
blegatt  |     "time_sync": [
blegatt  |         "INVALID ADDRESS",
blegatt  |         "INVALID ADDRESS"
blegatt  |     ],
blegatt  |     "user": "***"
blegatt  | }
blegatt  | ```
blegatt  | 
blegatt  | ## Bluetooth adapters
blegatt  | 
blegatt  | Default adapter: hci0
blegatt  | 
blegatt  | ### hci0
blegatt  | 
blegatt  | | Name         | Value                   |
blegatt  | |--------------|-------------------------|
blegatt  | | address      | B8:27:EB:XX:XX:XX       |
blegatt  | | sw_version   | raspberrypi             |
blegatt  | | hw_version   | usb:v1D6Bp0246d0537     |
blegatt  | | passive_scan |                       0 |
blegatt  | | manufacturer | Raspberry Pi Foundation |```
koenvervloesem commented 10 months ago

Have you removed the anonymized Configuration section, or does it just not show?

Do you really have a backtick after ENABLE_WEBSOCKET=true in your Docker Compose file, or is that an error in pasting the output here?

radim-kliment commented 10 months ago

@koenvervloesem I updated anonymised conf. Backtick removed it is an error by pasting it there.

koenvervloesem commented 10 months ago

Ok with your edited backtrace I can see now that the error seems to happen in the Bluetooth adapters section. I'm not sure why this happens. Do you have the same error if you run python3 -m TheengsGateway.diagnose directly on your Raspberry Pi, not in a Docker container?

radim-kliment commented 10 months ago

Ok with your edited backtrace I can see now that the error seems to happen in the Bluetooth adapters section. I'm not sure why this happens. Do you have the same error if you run python3 -m TheengsGateway.diagnose directly on your Raspberry Pi, not in a Docker container?

yes

/usr/lib/python3.9/runpy.py:127: RuntimeWarning: 'TheengsGateway.diagnose' found in sys.modules after import of package 'TheengsGateway', but prior to execution of 'TheengsGateway.diagnose'; this may result in unpredictable behaviour
  warn(RuntimeWarning(msg))
# Theengs Gateway Diagnostics

## Package Versions

| Name               | Value  |
|--------------------|--------|
| Theengs Gateway    | 1.2.0  |
| Theengs Decoder    | 1.6.7  |
| Bleak              | 0.21.1 |
| Bluetooth Clocks   | 0.2.0  |
| Bluetooth Numbers  | 1.1.1  |
| Paho MQTT          | 1.6.1  |
| Bluetooth Adapters | 0.16.0 |

## Python

| Name           | Value               |
|----------------|---------------------|
| Version        | 3.9.2               |
| Implementation | CPython             |
| Compiler       | GCC 10.2.1 20210110 |
| Executable     | /usr/bin/python3    |

## Operating System

| Name         | Value                                  |
|--------------|----------------------------------------|
| System       | Linux                                  |
| Release      | 6.1.21-v7+                             |
| Version      | #1642 SMP Mon Apr  3 17:20:52 BST 2023 |
| Machine type | armv7l                                 |

## Configuration

File: /root/theengsgw.conf

Configuration file not found

## Bluetooth adapters

Default adapter: hci0

### hci0

| Name         | Value                   |
|--------------|-------------------------|
| address      | B8:27:EB:XX:XX:XX       |
| sw_version   | raspberrypi             |
| hw_version   | usb:v1D6Bp0246d0537     |
| passive_scan |                       0 |
| manufacturer | Raspberry Pi Foundation |
Traceback (most recent call last):
  File "/usr/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.9/dist-packages/TheengsGateway/diagnose.py", line 190, in <module>
    asyncio.run(diagnostics(config_path))
  File "/usr/lib/python3.9/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "/usr/local/lib/python3.9/dist-packages/TheengsGateway/diagnose.py", line 172, in diagnostics
    await _adapters()
  File "/usr/local/lib/python3.9/dist-packages/TheengsGateway/diagnose.py", line 155, in _adapters
    _section(adapter, properties)  # type: ignore[arg-type]
  File "/usr/local/lib/python3.9/dist-packages/TheengsGateway/diagnose.py", line 55, in _section
    print(f"| {name:{max_name}} | {value:{max_value}} |")
TypeError: unsupported format string passed to NoneType.__format__
koenvervloesem commented 10 months ago

I verified this on a Raspberry Pi and found the error. Fixed in https://github.com/theengs/gateway/pull/206, which will be in the next Theengs Gateway release.

1technophile commented 10 months ago

In the meantime changing your log level to INFO may solve the issue

radim-kliment commented 10 months ago

In the meantime changing your log level to INFO may solve the issue

Thanks, I solved it for now by disabling internal rpi bluetooth adapter and use external usb bluetooth dongle.