Skip to content

Commit

Permalink
Merge pull request #690 from mr-manuel/dev
Browse files Browse the repository at this point in the history
Exclude devices from driver startup
  • Loading branch information
mr-manuel authored Jun 5, 2023
2 parents f6219f6 + 43cf469 commit e638433
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog

## v1.0.0
## v1.0.x
* Added: Exclude a device from beeing used by the dbus-serialbattery driver by @mr-manuel
* Added: Implement callback function for update by @seidler2547

## v1.0.20230531

### ATTENTION: Breaking changes! The config is now done in the `config.ini`. All values from the `utils.py` gets lost. The changes in the `config.ini` will persists future updates.

Expand Down
4 changes: 4 additions & 0 deletions etc/dbus-serialbattery/config.default.ini
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ TIME_TO_SOC_INC_FROM = False
; Ant, MNB, Sinowealth
BMS_TYPE =

; Exclute this serial devices from the driver startup
; Example: /dev/ttyUSB2, /dev/ttyUSB4
EXCLUDED_DEVICES =

; Publish the config settings to the dbus path "/Info/Config/"
PUBLISH_CONFIG_VALUES = 1

Expand Down
12 changes: 11 additions & 1 deletion etc/dbus-serialbattery/dbus-serialbattery.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,17 @@ def get_battery(_port) -> Union[Battery, None]:
def get_port() -> str:
# Get the port we need to use from the argument
if len(sys.argv) > 1:
return sys.argv[1]
port = sys.argv[1]
if port not in utils.EXCLUDED_DEVICES:
return port
else:
logger.info(
"Stopping dbus-serialbattery: "
+ str(port)
+ " is excluded trough the config file"
)
sleep(86400)
sys.exit(0)
else:
# just for MNB-SPI
logger.info("No Port needed")
Expand Down
11 changes: 9 additions & 2 deletions etc/dbus-serialbattery/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,18 @@ def _get_list_from_config(
) -> List[Any]:
rawList = config[group][option].split(",")
return list(
map(mapper, [item for item in rawList if item != "" and item is not None])
map(
mapper,
[item.strip() for item in rawList if item != "" and item is not None],
)
)


# battery types
# if not specified: baud = 9600

# Constants - Need to dynamically get them in future
DRIVER_VERSION = "1.0.20230531"
DRIVER_VERSION = "1.0.20230526dev"
zero_char = chr(48)
degree_sign = "\N{DEGREE SIGN}"

Expand Down Expand Up @@ -272,6 +275,10 @@ def _get_list_from_config(
# Ant, MNB, Sinowealth
BMS_TYPE = config["DEFAULT"]["BMS_TYPE"]

EXCLUDED_DEVICES = _get_list_from_config(
"DEFAULT", "EXCLUDED_DEVICES", lambda v: str(v)
)

# Publish the config settings to the dbus path "/Info/Config/"
PUBLISH_CONFIG_VALUES = int(config["DEFAULT"]["PUBLISH_CONFIG_VALUES"])

Expand Down

0 comments on commit e638433

Please sign in to comment.