Skip to content

Commit

Permalink
many improvements (#393)
Browse files Browse the repository at this point in the history
* many improvements

* removes debug log statements

* bugfixes in midpoint calculation

* publish constants to dbus

* black and flake8
* update documentation

* remove getting data from ini

* flake8

Co-authored-by: Philip Puetsch <[email protected]>
  • Loading branch information
ppuetsch and Philip Puetsch authored Jan 11, 2023
1 parent ce601fb commit 133f310
Show file tree
Hide file tree
Showing 27 changed files with 356 additions and 264 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
max-line-length = 120
exclude =
./etc/dbus-serialbattery/ant.py,
./etc/dbus-serialbattery/battery.py,
./etc/dbus-serialbattery/battery_template.py,
./etc/dbus-serialbattery/daly.py,
./etc/dbus-serialbattery/dbus-serialbattery.py,
Expand All @@ -17,6 +16,7 @@ exclude =
./etc/dbus-serialbattery/sinowealth.py,
./etc/dbus-serialbattery/test_max17853.py,
./etc/dbus-serialbattery/util_max17853.py,
./velib_python
venv
extend-ignore:
# E203 whitespace fefore ':' conflicts with black code formatting. Will be ignored in flake8
Expand Down
32 changes: 13 additions & 19 deletions .github/workflows/analyse.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,28 @@ on:
- '**'

jobs:
CodeQL:
analyse:
name: Analyze Using GitHub CodeQL
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Python environment
uses: actions/setup-python@v4
with:
python-version: "3.8.13"
- name: Clone velib_python and add it to PYTHONPATH for subsequent steps
run: |
git clone https://github.com/victronenergy/velib_python.git
echo PYTHONPATH=$PYTHONPATH:$(pwd)/velib_python >> $GITHUB_ENV
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: python

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
lint:
name: Check Code Formatting
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Execute black lint check
uses: psf/black@stable

- name: Set up Python environment
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: flake8 Lint
uses: py-actions/flake8@v2
- name: Execute black lint check
uses: psf/black@stable
- name: flake8 Lint
uses: py-actions/flake8@v2
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,6 @@ BMS-trials
.project
.pydevproject
*.prefs

# Local Clone of velib_python
velib_python
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,24 @@ The driver will communicate with a Battery Management System (BMS) that support
If you find this driver helpful please considder supporting this project. You can buy me a Ko-Fi or get in contact if you would like to donate hardware.

[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/Z8Z73LCW1) or using [Paypal.me](https://paypal.me/innernet)

### Developer Remarks
To develop this project, install the requirements. This project makes use of velib_python which is pre-installed on
Venus-OS Devices under `/opt/victronenergy/dbus-systemcalc-py/ext/velib_python`. To use the python files locally,
`git clone` the [velib_python](https://github.com/victronenergy/velib_python) project to velib_python and add
velib_python to the `PYTHONPATH` environment variable.

#### How it works
* Each supported BMS needs to implement the abstract base class `Battery` from `battery.py`.
* `dbus-serialbattery.py` tries to figure out the correct connected BMS by looping through all known implementations of
`Battery` and executing its `test_connection()`. If this returns true, `dbus-serialbattery.py` sticks with this battery
and then periodically executes `dbushelpert.publish_battery()`. `publish_battery()` executes `Battery.refresh_data()` which
updates the fields of Battery. It then publishes those fields to dbus using `dbushelper.publish_dbus()`
* The Victron Device will be "controlled" by the values published on `/Info/` - namely:
* `/Info/MaxChargeCurrent `
* `/Info/MaxDischargeCurrent`
* `/Info/MaxChargeVoltage`
* `/Info/BatteryLowVoltage`
* `/Info/ChargeRequest` (not implemented in dbus-serialbattery)

For more details on the victron dbus interface see [the official victron dbus documentation](https://github.com/victronenergy/venus/wiki/dbus)
4 changes: 2 additions & 2 deletions etc/dbus-serialbattery/ant.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@


class Ant(Battery):
def __init__(self, port, baud):
super(Ant, self).__init__(port, baud)
def __init__(self, port, baud, address):
super(Ant, self).__init__(port, baud, address)
self.type = self.BATTERYTYPE

command_general = b"\xDB\xDB\x00\x00\x00\x00"
Expand Down
Loading

0 comments on commit 133f310

Please sign in to comment.