Skip to content

Commit

Permalink
Clenup GH Actions, Consistently use the same indentation (4 Spaces), …
Browse files Browse the repository at this point in the history
…Apply Black Code Formatting and include into GH Actions, Apply flake8 to utils and jkbms (and include in GH Actions)
  • Loading branch information
Philip Puetsch committed Jan 2, 2023
1 parent 3685d15 commit f434402
Show file tree
Hide file tree
Showing 26 changed files with 2,562 additions and 2,029 deletions.
23 changes: 23 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[flake8]
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,
./etc/dbus-serialbattery/dbushelper.py,
./etc/dbus-serialbattery/ecs.py,
./etc/dbus-serialbattery/lifepower.py,
./etc/dbus-serialbattery/lltjbd.py,
./etc/dbus-serialbattery/minimalmodbus.py,
./etc/dbus-serialbattery/mnb.py,
./etc/dbus-serialbattery/renogy.py,
./etc/dbus-serialbattery/revov.py,
./etc/dbus-serialbattery/sinowealth.py,
./etc/dbus-serialbattery/test_max17853.py,
./etc/dbus-serialbattery/util_max17853.py,
venv
extend-ignore:
# E203 whitespace fefore ':' conflicts with black code formatting. Will be ignored in flake8
E203
39 changes: 39 additions & 0 deletions .github/workflows/analyse.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: "CodeChecks"

on:
push:
branches:
- '**'

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

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

- 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
67 changes: 0 additions & 67 deletions .github/workflows/codeql-analysis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion conf/serial-starter.d
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
service sbattery dbus-serialbattery
service sbattery dbus-serialbattery
alias default gps:vedirect:sbattery
alias rs485 cgwacs:fzsonick:imt:modbus:sbattery
77 changes: 49 additions & 28 deletions etc/dbus-serialbattery/ant.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class Ant(Battery):

def __init__(self, port, baud):
super(Ant, self).__init__(port, baud)
self.type = self.BATTERYTYPE
Expand Down Expand Up @@ -54,55 +53,77 @@ def read_status_data(self):
if status_data is False:
return False

voltage = unpack_from('>H', status_data, 4)
self.voltage = voltage[0]*0.1
current, self.soc = unpack_from('>lB', status_data, 70)
voltage = unpack_from(">H", status_data, 4)
self.voltage = voltage[0] * 0.1
current, self.soc = unpack_from(">lB", status_data, 70)
self.current = 0.0 if current == 0 else current / -10

self.cell_count = unpack_from('>b', status_data, 123)[0]
self.cell_count = unpack_from(">b", status_data, 123)[0]
self.max_battery_voltage = MAX_CELL_VOLTAGE * self.cell_count
self.min_battery_voltage = MIN_CELL_VOLTAGE * self.cell_count

cell_max_no, cell_max_voltage, cell_min_no, cell_min_voltage = unpack_from('>bhbh', status_data, 115)
cell_max_no, cell_max_voltage, cell_min_no, cell_min_voltage = unpack_from(
">bhbh", status_data, 115
)
self.cell_max_no = cell_max_no - 1
self.cell_min_no = cell_min_no - 1
self.cell_max_voltage = cell_max_voltage / 1000
self.cell_min_voltage = cell_min_voltage / 1000
capacity = unpack_from('>L', status_data, 75)

capacity = unpack_from(">L", status_data, 75)
self.capacity = capacity[0] / 1000000

capacity_remain = unpack_from('>L', status_data, 79)
capacity_remain = unpack_from(">L", status_data, 79)
self.capacity_remain = capacity_remain[0] / 1000000
total_ah_drawn = unpack_from('>L', status_data, 83)
self.total_ah_drawn = total_ah_drawn[0] / 1000

total_ah_drawn = unpack_from(">L", status_data, 83)
self.total_ah_drawn = total_ah_drawn[0] / 1000
self.cycles = self.total_ah_drawn / self.capacity

self.charge_fet, self.discharge_fet, self.balancing = unpack_from('>bbb',status_data, 103)

self.temp1, self.temp2 = unpack_from('>bxb',status_data, 96)
self.charge_fet, self.discharge_fet, self.balancing = unpack_from(
">bbb", status_data, 103
)

self.temp1, self.temp2 = unpack_from(">bxb", status_data, 96)

self.hardware_version = "ANT BMS " + str(self.cell_count) + " cells"

# Alarms
self.protection.voltage_high = 2 if self.charge_fet==2 else 0
self.protection.voltage_low = 2 if self.discharge_fet==2 or self.discharge_fet==5 else 0
self.protection.voltage_cell_low = 2 if self.cell_min_voltage < MIN_CELL_VOLTAGE - 0.1 else 1 if self.cell_min_voltage < MIN_CELL_VOLTAGE else 0
self.protection.temp_high_charge = 1 if self.charge_fet==3 or self.charge_fet==6 else 0
self.protection.temp_high_discharge = 1 if self.discharge_fet==7 or self.discharge_fet==6 else 0
self.protection.current_over = 2 if self.charge_fet==3 else 0
self.protection.current_under = 2 if self.discharge_fet==3 else 0

self.protection.voltage_high = 2 if self.charge_fet == 2 else 0
self.protection.voltage_low = (
2 if self.discharge_fet == 2 or self.discharge_fet == 5 else 0
)
self.protection.voltage_cell_low = (
2
if self.cell_min_voltage < MIN_CELL_VOLTAGE - 0.1
else 1
if self.cell_min_voltage < MIN_CELL_VOLTAGE
else 0
)
self.protection.temp_high_charge = (
1 if self.charge_fet == 3 or self.charge_fet == 6 else 0
)
self.protection.temp_high_discharge = (
1 if self.discharge_fet == 7 or self.discharge_fet == 6 else 0
)
self.protection.current_over = 2 if self.charge_fet == 3 else 0
self.protection.current_under = 2 if self.discharge_fet == 3 else 0

return True
def get_balancing(self):

def get_balancing(self):
return 1 if self.balancing or self.balancing == 2 else 0

def read_serial_data_ant(self, command):
# use the read_serial_data() function to read the data and then do BMS spesific checks (crc, start bytes, etc)
data = read_serial_data(command, self.port, self.baud_rate,
self.LENGTH_POS, self.LENGTH_CHECK, self.LENGTH_FIXED)
data = read_serial_data(
command,
self.port,
self.baud_rate,
self.LENGTH_POS,
self.LENGTH_CHECK,
self.LENGTH_FIXED,
)
if data is False:
logger.error(">>> ERROR: Incorrect Data")
return False
Expand Down
Loading

0 comments on commit f434402

Please sign in to comment.