Skip to content

Commit

Permalink
Make SERIAL_DEVICE unoverrideable in container
Browse files Browse the repository at this point in the history
Force users to make a mapping. If we make it overrideable, users may
be tempted to set SERIAL_DEVICE=/dev/ttyUSB0 and map that device
directly, without relying on /dev/serial/by-id. This is to be
discouraged.
  • Loading branch information
antonijn committed Jan 25, 2024
1 parent 869866a commit e860412
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ WORKDIR /app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD [ "./mqtt4dsmr.py" ]
CMD [ "env", "SERIAL_DEVICE=/dev/ttyDSMR", "./mqtt4dsmr.py" ]
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,24 @@ for more information. (Optional)

`V4`

</td>
</tr>
<tr>
<td>

`SERIAL_DEVICE`

</td>
<td>

Path to serial device file.

**NOTE:** This option is for testing purposes only. When running in a
container, `SERIAL_DEVICE` always has the value `/dev/ttyDSMR` and
cannot be overridden. Make sure to map the host device accordingly.

</td>
<td>
</td>
</tr>
</table>
2 changes: 1 addition & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __init__(self):
dsmr_version = get_env_opt('DSMR_VERSION', dsmr_versions, False, 'V4')

self.SERIAL_SETTINGS = getattr(dsmr_parser.clients, serial_settings_pfx + serial_settings)
self.SERIAL_PORT = get_env_opt('SERIAL_PORT', str, False, '/dev/ttyDSMR')
self.SERIAL_DEVICE = get_env_opt('SERIAL_DEVICE', str, True)
self.DSMR_VERSION = getattr(telegram_specifications, dsmr_version)

self.MQTT_HOST = get_env_opt('MQTT_HOST', str, True)
Expand Down
2 changes: 1 addition & 1 deletion mqtt4dsmr.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def main():
client.publish(avail, 'online', retain=True)

serial_reader = SerialReader(
device=cfg.SERIAL_PORT,
device=cfg.SERIAL_DEVICE,
serial_settings=cfg.SERIAL_SETTINGS,
telegram_specification=cfg.DSMR_VERSION
)
Expand Down

0 comments on commit e860412

Please sign in to comment.