Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude devices from driver startup #690

Merged
merged 3 commits into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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