Skip to content

Commit

Permalink
Order relays by number
Browse files Browse the repository at this point in the history
  • Loading branch information
thdfw committed Dec 30, 2024
1 parent 34a5b73 commit d55a1be
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion gw_spaceheat/admin/watch/watchex/relays2.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,12 @@ def _update_relay_row(self, relay_name: str) -> None:
for column_name, value in data.items():
table.update_cell(relay_name, column_name, value)

def _get_relay_number(self, relay_name: str) -> int:
if 'relay' in relay_name:
relay_number = int(relay_name.split('relay')[1])
return relay_number
return 1e3

def on_relays_config_change(self, message: Relays.ConfigChange) -> None:
message.prevent_default()
table = self.query_one("#relays_table", DataTable)
Expand All @@ -354,9 +360,17 @@ def on_relays_config_change(self, message: Relays.ConfigChange) -> None:
self._relays[relay_name] = RelayWidgetInfo(
config=RelayWidgetConfig.from_config(change.new_config)
)
insert_pos = 0
new_channel = self._get_relay_number(change.new_config.channel_name.lower())
for row in table.rows:
if new_channel > self._get_relay_number(self._relays[row.key.value].config.channel_name.lower()):
insert_pos += 1
else:
break
table.add_row(
*self._get_relay_row(relay_name,table.row_count),
key=relay_name
key=relay_name,
position=insert_pos
)

def _update_buttons(self, relay_name: str) -> None:
Expand Down

0 comments on commit d55a1be

Please sign in to comment.