Skip to content

Commit

Permalink
Added authentication. (#447)
Browse files Browse the repository at this point in the history
  • Loading branch information
ATATC committed Nov 18, 2024
1 parent 18a1b0e commit 4c6bfdd
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion leads/dt/sobd.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@


class SOBD(Device, Entity, _AutoIdentity):
def __init__(self, port: str | _Literal["auto"], baud_rate: int = 9600) -> None:
def __init__(self, port: str | _Literal["auto"], baud_rate: int = 9600, password: str = "") -> None:
Device.__init__(self)
Entity.__init__(self, -1, _SOBDCallback(self))
_AutoIdentity.__init__(self, port == "auto")
self._serial: _Serial = _Serial()
self._serial.baudrate = baud_rate
self._connection: _SerialConnection | None = None
self._serial.port = self.suggest_next_port() if port == "auto" else port
self._password: str = password
self._locked: bool = password != ""

@_override
def port(self) -> str:
Expand All @@ -30,6 +32,13 @@ def initialize(self, *parent_tags: str) -> None:

@_override
def update(self, data: str) -> None:
if data.startswith("pwd="):
if data[4:] != self._password:
self.close()
else:
self._locked = False
if self._locked:
return
if data.startswith("dbl="):
require_config().w_debug_level = data[4:].upper()
else:
Expand Down

0 comments on commit 4c6bfdd

Please sign in to comment.