Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make rows slimmer, enable shutter stopping, bump max shutters to 8 #277

Merged
merged 2 commits into from
Sep 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 11 additions & 23 deletions tdmgr/GUI/delegates/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ class RectSpacing:


RECT_ADJUSTMENT = (2, 2, -1, -1)
SHUTTER_RECT_SIZE = QSize(
RECT_SIZE.width() * 3 + RectSpacing.h * 2, RECT_SIZE.height() * 2 + RectSpacing.v
)
SHUTTER_RECT_SIZE = QSize(RECT_SIZE.width() * 2 + RectSpacing.h * 2, RECT_SIZE.height())


def get_pixmap_for_rssi(rssi: int) -> QPixmap:
Expand Down Expand Up @@ -73,7 +71,7 @@ def get_relays_height():
return 6 + self.get_relays_rect_size(relay_data).height()
return 0

hint_height = max(42, get_relays_height(), 6 + SHUTTER_RECT_SIZE.height())
hint_height = max(28, get_relays_height())
return QSize(QStyledItemDelegate().sizeHint(option, index).width(), hint_height)
return QStyledItemDelegate().sizeHint(option, index)

Expand Down Expand Up @@ -218,17 +216,13 @@ def paint(self, p: QPainter, option, index):
def draw_rssi_pixmap(self, index, option, p):
p.save()
px = self.rssi_offline
rssi = 'offln'
if index.data(DeviceRoles.LWTRole):
rssi = index.data(DeviceRoles.RSSIRole)
px = get_pixmap_for_rssi(rssi)

px_y = option.rect.y() + (option.rect.height() - 38) // 2
px_y = option.rect.y() + (option.rect.height() - 24) // 2
px_rect = QRect(option.rect.x() + 2, px_y, 24, 24)
p.drawPixmap(px_rect, px.scaled(24, 24))
rssi_rect = QRect(option.rect.x() + 2, px_rect.y() + px_rect.height() + 2, 24, 12)
p.setFont(self.font_8pt)
p.drawText(rssi_rect, Qt.AlignCenter, str(rssi))
p.restore()

def draw_relay_state(self, p: QPainter, target_rect: QRect, relay_data: dict):
Expand Down Expand Up @@ -259,32 +253,26 @@ def draw_shutters_state(self, p: QPainter, target_rect: QRect, shutter_pos_data:
title_rect = QRect(rect)
title_rect.setHeight(RECT_SIZE.height())

state_rect = QRect(rect)
state_rect.moveTop(title_rect.bottom() + 1)
state_rect.setBottom(rect.bottom())
state_rect.adjust(*RECT_ADJUSTMENT)

p.drawText(title_rect, Qt.AlignCenter, f'Shutter {shutter}')

direction = shutter_state['Direction']
arrow_direction = {-1: ARROW_DN, 1: ARROW_UP}

position = (
'CLOSED'
'CLS'
if shutter_state['Position'] == 0
else 'OPEN' if shutter_state['Position'] == 100 else shutter_state['Position']
else 'OPN' if shutter_state['Position'] == 100 else shutter_state['Position']
)

arrow_direction = {-1: ARROW_DN, 1: ARROW_UP}

if direction != 0:
p.save()
p.setPen(self.hltext_pen)
p.fillRect(state_rect, GREEN)
p.drawText(state_rect, Qt.AlignCenter, f"{arrow_direction[direction]} {position}")
p.fillRect(title_rect, GREEN)
p.drawText(title_rect, Qt.AlignCenter, f"{arrow_direction[direction]} {position}")
p.restore()
else:
p.drawText(state_rect, Qt.AlignCenter, f"{position}")
p.drawText(title_rect, Qt.AlignCenter, f'SHT{shutter} {position}')
for r in [title_rect, rect]:
p.drawRect(r)

shutter_col += 1

def draw_rssi_rect(self, p: QPainter, rect, index):
Expand Down
7 changes: 5 additions & 2 deletions tdmgr/GUI/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def create_actions(self):
self.agShutters = QActionGroup(self)
self.agShutters.setVisible(False)
self.agShutters.setExclusive(False)
for shutter_idx in range(1, 5):
for shutter_idx in range(1, 9):
for idx, arrow in enumerate([ARROW_UP, ARROW_DN]):
px = make_relay_pixmap(arrow)
self.agShutters.addAction(
Expand Down Expand Up @@ -410,7 +410,10 @@ def toggle_power_all(self, action):
def move_shutter(self, action):
idx = 1 + self.agShutters.actions().index(action)
shutter = (idx + 1) // 2
action = "ShutterClose" if idx % 2 == 0 else "ShutterOpen"
direction = self.device.p[f"Shutter{shutter}"]["Direction"]
action = (
"ShutterStop" if direction != 0 else "ShutterClose" if idx % 2 == 0 else "ShutterOpen"
)
self.mqtt.publish(self.device.cmnd_topic(f"{action}{shutter}"))

def set_color(self):
Expand Down
2 changes: 1 addition & 1 deletion tdmgr/GUI/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def setupColumns(self, columns, hidden=None):

def setupView(self, view):
for i, c in enumerate(view):
if c in ("Device", "Module", "Topic", "FullTopic"):
if c in ("Device",):
self.horizontalHeader().setSectionResizeMode(i, QHeaderView.Stretch)
else:
self.horizontalHeader().setSectionResizeMode(i, QHeaderView.ResizeToContents)
Expand Down
4 changes: 0 additions & 4 deletions tdmgr/models/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ def deviceAtRow(self, row):

def notify_change(self, d, key):
row = self.tasmota_env.devices.index(d)
# if key.startswith("POWER") and "Power" in self.columns:
# power_idx = self.columns.index("Power")
# idx = self.index(row, power_idx)
# self.dataChanged.emit(idx, idx)

if any(
[
Expand Down
6 changes: 3 additions & 3 deletions tdmgr/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def initial_commands():
commands = [(command, "") for command in commands]
commands += [("status", "0"), ("gpios", "255")]

for sht in range(4):
for sht in range(8):
commands.append([f"shutterrelay{sht + 1}", ""])
commands.append([f"shutterposition{sht + 1}", ""])

Expand Down Expand Up @@ -343,12 +343,12 @@ def power(self):
def shutters(self) -> dict:
return {
k: self.p[f"ShutterRelay{k}"]
for k in range(1, 5)
for k in range(1, 9)
if f"ShutterRelay{k}" in self.p and self.p[f"ShutterRelay{k}"] != 0
}

def shutter_positions(self) -> dict:
x = {k: self.p[f"Shutter{k}"] for k in range(1, 5) if f"Shutter{k}" in self.p}
x = {k: self.p[f"Shutter{k}"] for k in range(1, 9) if f"Shutter{k}" in self.p}
return x

def pwm(self):
Expand Down
Loading