Skip to content

Commit b79b1a7

Browse files
author
Greg Brooks
committed
Move BusState conversion to util.py (#1956)
1 parent b12ab13 commit b79b1a7

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

can/interfaces/pcan/pcan.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -268,12 +268,6 @@ def __init__(
268268

269269
self.check_api_version()
270270

271-
if not isinstance(state, BusState):
272-
try:
273-
state = BusState[state]
274-
except KeyError as e:
275-
raise ValueError("State must be ACTIVE or PASSIVE") from e
276-
277271
if state in [BusState.ACTIVE, BusState.PASSIVE]:
278272
self.state = state
279273
else:

can/util.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,12 @@ def _create_bus_config(config: dict[str, Any]) -> typechecking.BusConfig:
249249
if "fd" in config:
250250
config["fd"] = config["fd"] not in (0, False)
251251

252+
if "state" in config:
253+
try:
254+
config["state"] = can.BusState[config["state"]]
255+
except KeyError as e:
256+
raise ValueError("State config not valid!") from e
257+
252258
return cast("typechecking.BusConfig", config)
253259

254260

0 commit comments

Comments
 (0)