Skip to content

Commit

Permalink
Merge pull request #880 from mr-manuel/dev
Browse files Browse the repository at this point in the history
Changes 2023.11.28
  • Loading branch information
mr-manuel authored Nov 28, 2023
2 parents da73f05 + 0e6dbd8 commit c6d5bb6
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 13 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

## Breaking changes

* Driver version greater or equal to `v1.0.20231126beta`
* Driver version greater or equal to `v1.0.20231128beta`

The custom name is not saved to the config file anymore, but to the dbus service com.victronenergy.settings. You have to re-enter it once.
* The custom name is not saved to the config file anymore, but to the dbus service com.victronenergy.settings. You have to re-enter it once.

* If you selected a specific device in `Settings -> System setup -> Battery monitor` and/or `Settings -> DVCC -> Controlling BMS` you have to reselect it.

* Driver version greater or equal to `v1.0.20230629beta` and smaller or equal to `v1.0.20230926beta`:

Expand Down
51 changes: 41 additions & 10 deletions etc/dbus-serialbattery/dbushelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ def __init__(self, battery):
)
self.path_battery = None
self.save_charge_details_last = {
"allow_max_voltage": None,
"max_voltage_start_time": None,
"soc_reset_last_reached": None,
"allow_max_voltage": self.battery.allow_max_voltage,
"max_voltage_start_time": self.battery.max_voltage_start_time,
"soc_reset_last_reached": self.battery.soc_reset_last_reached,
}

def setup_instance(self):
Expand All @@ -65,6 +65,7 @@ def setup_instance(self):
# bms_id = self.battery.production if self.battery.production is not None else \
# self.battery.port[self.battery.port.rfind('/') + 1:]
# bms_id = self.battery.port[self.battery.port.rfind("/") + 1 :]
logger.debug("setup_instance(): start")

custom_name = self.battery.custom_name()
device_instance = "1"
Expand All @@ -76,11 +77,15 @@ def setup_instance(self):
self.settings = SettingsDevice(
get_bus(), self.EMPTY_DICT, self.handle_changed_setting
)
logger.debug("setup_instance(): SettingsDevice")

# get all the settings from the dbus
settings_from_dbus = self.getSettingsWithValues(
get_bus(), "com.victronenergy.settings", "/Settings/Devices"
get_bus(),
"com.victronenergy.settings",
"/Settings/Devices",
)
logger.debug("setup_instance(): getSettingsWithValues")
# output:
# {
# "Settings": {
Expand Down Expand Up @@ -205,10 +210,30 @@ def setup_instance(self):
["ClassAndVrmInstance"],
)
logger.info(
f"Remove /Settings/Devices/{key} from dbus."
f"Remove /Settings/Devices/{key} from dbus. "
+ f"Old entry. Delete result: {del_return}"
)

if "ruuvi" in key:
# check if Ruuvi tag is enabled, if not remove entry.
if (
"Enabled" in value
and value["Enabled"] == "0"
and "ClassAndVrmInstance" not in value
):
del_return = self.removeSetting(
get_bus(),
"com.victronenergy.settings",
"/Settings/Devices/" + key,
["CustomName", "Enabled", "TemperatureType"],
)
logger.info(
f"Remove /Settings/Devices/{key} from dbus. "
+ f"Ruuvi tag was disabled and had no ClassAndVrmInstance. Delete result: {del_return}"
)

logger.debug("setup_instance(): for loop ended")

# create class and crm instance
class_and_vrm_instance = "battery:" + str(device_instance)

Expand Down Expand Up @@ -899,6 +924,10 @@ def publish_dbus(self):
)
pass

# save settings every 15 seconds to dbus
if int(time()) % 15:
self.saveBatteryOptions()

if self.battery.soc is not None:
logger.debug("logged to dbus [%s]" % str(round(self.battery.soc, 2)))
self.battery.log_cell_data()
Expand Down Expand Up @@ -1008,16 +1037,18 @@ def custom_name_callback(self, path, value) -> str:
)
return value if result else None

# save charge mode to dbus
def saveChargeDetails(self) -> bool:
# save battery options to dbus
def saveBatteryOptions(self) -> bool:
result = True

if (
self.battery.allow_max_voltage
!= self.save_charge_details_last["allow_max_voltage"]
):
self.save_charge_details_last[
"allow_max_voltage"
] = self.battery.allow_max_voltage
result = self.setSetting(
result = result + self.setSetting(
get_bus(),
"com.victronenergy.settings",
self.path_battery,
Expand Down Expand Up @@ -1065,8 +1096,8 @@ def saveChargeDetails(self) -> bool:
self.battery.soc_reset_last_reached,
)
logger.info(
f"Saved SocResetLastReached. Before {self.save_charge_details_last['soc_reset_last_reached']}, ",
+f"after {self.battery.soc_reset_last_reached}",
f"Saved SocResetLastReached. Before {self.save_charge_details_last['soc_reset_last_reached']}, "
+ f"after {self.battery.soc_reset_last_reached}",
)

return result
2 changes: 1 addition & 1 deletion etc/dbus-serialbattery/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def _get_list_from_config(


# Constants
DRIVER_VERSION = "1.0.20231126dev"
DRIVER_VERSION = "1.0.20231128dev"
zero_char = chr(48)
degree_sign = "\N{DEGREE SIGN}"

Expand Down

0 comments on commit c6d5bb6

Please sign in to comment.