Skip to content

Commit

Permalink
Online status (#72)
Browse files Browse the repository at this point in the history
* online status update

#17  Show when bank is online/offline
Exit with status 1 to show error status when not connected
Fix cannot change device instance when handling change setting.
  • Loading branch information
Louisvdw authored Nov 15, 2021
1 parent 6c705db commit 6c22d7e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
1 change: 1 addition & 0 deletions etc/dbus-serialbattery/battery.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def __init__(self, port, baud):
self.role = 'battery'
self.type = 'Generic'
self.poll_interval = 1000
self.online = True

self.hardware_version = None
self.voltage = None
Expand Down
4 changes: 2 additions & 2 deletions etc/dbus-serialbattery/dbus-serialbattery.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def get_port():
# exit if no battery could be found
if battery is None:
logger.error("ERROR >>> No battery connection at " + port)
return
sys.exit(1)

# Have a mainloop, so we can send/receive asynchronous calls to and from dbus
DBusGMainLoop(set_as_default=True)
Expand All @@ -92,7 +92,7 @@ def get_port():
helper = DbusHelper(battery)
if not helper.setup_vedbus():
logger.error("ERROR >>> Problem with battery set up at " + port)
return
sys.exit(1)
logger.warning('Battery connected to dbus from ' + port)


Expand Down
26 changes: 23 additions & 3 deletions etc/dbus-serialbattery/dbushelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ def get_role_instance(self):
def handle_changed_setting(self, setting, oldvalue, newvalue):
if setting == 'instance':
self.battery.role, self.instance = self.get_role_instance()
self._dbusservice['/DeviceInstance'] = self.instance
logger.debug("DeviceInstance = %d", self.instance)
return

def setup_vedbus(self):
# Set up dbus service and device instance
# and notify of all the attributes we intend to update
# This is only called once when a battery is initiated
self.setup_instance()
logger.debug("%s" % ("com.victronenergy.battery." + self.battery.port[self.battery.port.rfind('/') + 1:]))

Expand Down Expand Up @@ -135,11 +135,29 @@ def setup_vedbus(self):
return True

def publish_battery(self, loop):
# This is called every battery.poll_interval milli second as set up per battery type to read and update the data
try:
self.battery.refresh_data()
error_count = 0
# Call the battery's refresh_data function
success = self.battery.refresh_data()
if success:
error_count = 0
self.battery.online = True
else:
error_count += 1
# If the battery is offline for more than 10 polls (polled every second for most batteries)
if error_count >= 10:
self.battery.online = False




# This is to mannage CCCL
self.battery.manage_charge_current()
# self.battery.manage_control_charging(max_voltage, min_voltage, total_voltage, balance)

# publish all the data fro the battery object to dbus
self.publish_dbus()

except:
traceback.print_exc()
loop.quit()
Expand Down Expand Up @@ -172,6 +190,8 @@ def publish_dbus(self):
(self.battery.charge_fet and self.battery.control_allow_charge) else 1
self._dbusservice['/System/NrOfModulesBlockingDischarge'] = 0 if self.battery.discharge_fet is None \
or self.battery.discharge_fet else 1
self._dbusservice['/System/NrOfModulesOnline'] = 1 if self.battery.online else 0
self._dbusservice['/System/NrOfModulesOffline'] = 0 if self.battery.online else 1
self._dbusservice['/System/MinCellTemperature'] = self.battery.get_min_temp()
self._dbusservice['/System/MaxCellTemperature'] = self.battery.get_max_temp()

Expand Down
2 changes: 1 addition & 1 deletion etc/dbus-serialbattery/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

# Constants - Need to dynamically get them in future
DRIVER_VERSION = 0.9
DRIVER_SUBVERSION = ''
DRIVER_SUBVERSION = '.1'
zero_char = chr(48)
degree_sign = u'\N{DEGREE SIGN}'
# Cell min/max voltages - used with the cell count to get the min/max battery voltage
Expand Down

0 comments on commit 6c22d7e

Please sign in to comment.