Skip to content

Commit

Permalink
added baud rate to config flow
Browse files Browse the repository at this point in the history
  • Loading branch information
flip555 committed Mar 23, 2024
1 parent d355b63 commit a532ca5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
3 changes: 3 additions & 0 deletions custom_components/bms_connector/config_flows/bms/seplos.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ async def async_step_seplos_bms_v2_device(self, user_input=None):
# Include dynamic listing of USB ports in the schema
data_schema = vol.Schema({
vol.Required("usb_port", default=default_port): vol.In(ports),
vol.Required("baud_rate", default=19200): int,
vol.Required("name_prefix", default="Seplos BMS HA - "): str,
vol.Required("battery_pack_count", default=1): vol.All(vol.Coerce(int), vol.Range(min=1, max=16)),
})
Expand All @@ -43,12 +44,14 @@ async def async_step_seplos_options_bms_v2(self, user_input=None):
ports = [port.device for port in list_ports.comports()]
usb_port = self.config_entry.data.get("usb_port", ports[0] if ports else "/dev/ttyUSB0") # Fallback or current setting
name_prefix = self.config_entry.data.get("name_prefix", f"Seplos BMS HA - ")
baud_rate = self.config_entry.data.get("baud_rate", 19200)
sensor_update_frequency = self.config_entry.data.get("sensor_update_frequency", 5)

return self.async_show_form(
step_id="seplos_options_bms_v2",
data_schema=vol.Schema({
vol.Required("usb_port", default=usb_port): vol.In(ports),
vol.Required("baud_rate", default=baud_rate): int,
vol.Required("name_prefix", default=name_prefix): str,
vol.Required("battery_pack_count", default=battery_pack_count): vol.All(vol.Coerce(int), vol.Range(min=1, max=16)),
vol.Required("sensor_update_frequency", default=sensor_update_frequency): int,
Expand Down
3 changes: 2 additions & 1 deletion custom_components/bms_connector/modules/bms/seplos/v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def __init__(self, hass, entry):
self.writer = None
self.ha_update_time = entry.data.get("sensor_update_frequency")
self.usb_port = entry.data.get("usb_port")
self.baud_rate = entry.data.get("baud_rate", 19200)
self.battery_pack_count = entry.data.get("battery_pack_count")
self.name_prefix = entry.data.get("name_prefix")
self.comm_type = "usb_serial"
Expand Down Expand Up @@ -106,7 +107,7 @@ async def initialize_serial_connection(self):
"""Open serial connection and store reader and writer."""
try:
self.reader, self.writer = await serial_asyncio.open_serial_connection(
url=self.usb_port, baudrate=19200)
url=self.usb_port, baudrate=self.baud_rate)
_LOGGER.debug(f"Serial port {self.usb_port} opened successfully.")
except Exception as e:
_LOGGER.error(f"Failed to open serial port {self.usb_port}: {e}")
Expand Down
4 changes: 3 additions & 1 deletion custom_components/bms_connector/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"description": "Please select the connection port and select the number of battery packs are attached to your BMS.",
"data": {
"usb_port": "USB Serial Port",
"baud_rate": "Serial Baud Rate",
"battery_address": "Battery Address",
"name_prefix": "Please enter your desired sensor prefix",
"battery_pack_count": "Number of Battery Packs",
Expand Down Expand Up @@ -81,7 +82,8 @@
"battery_address": "Battery Address",
"name_prefix": "Entity Name Prefix **CHANGING THIS WILL RENAME ENTITIES**",
"battery_pack_count": "Number of Battery Packs",
"sensor_update_frequency": "Update Frequency (s)"
"sensor_update_frequency": "Update Frequency (s)",
"baud_rate": "Serial Baud Rate"
}
}
}
Expand Down

0 comments on commit a532ca5

Please sign in to comment.