Skip to content

Dataclasses - #39

Open
M-Chan wants to merge 45 commits into
new-mainfrom
dataclasses
Open

Dataclasses#39
M-Chan wants to merge 45 commits into
new-mainfrom
dataclasses

Conversation

@M-Chan

@M-Chan M-Chan commented Aug 3, 2026

Copy link
Copy Markdown

Use dataclasses for polling status

M-Chan and others added 30 commits June 19, 2026 13:27
only motor_responses are parsed into the nested dataclass

still need to parse the other statuses in
bring across changes from comms_qtthread to original comms_thread file
remove now duplicate file
bring across changes from comms_qtthread_2 to original comms_thread file and now use the original file in program
remove now duplicate file
needs to be picked apart later as some code may still be needed (ie. watches)
@M-Chan
M-Chan requested a review from JamesOHeaDLS August 5, 2026 11:29
M-Chan and others added 2 commits August 5, 2026 14:49
Code was duplicated during the rebase

@JamesOHeaDLS JamesOHeaDLS left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@M-Chan - I have made a first pass of the code and picked out some of the key changes that are needed. It is probably easiest to make the changes to the dataclasses first as these will then have an impact elsewhere in the code.

I can then review again once these changes are made.

Comment thread src/dls_pmac_control/__main__.py Outdated
try:
# if isinstance(self.pmac, PPmacSshInterface):
self.update_identity(status.coordinate_systems[0].identifier_i65)
self.PpmacGlobalStatusScreen.update_status(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to be careful here as, looking at the original code, the PowerBrick responses include a $ on the hex value which is stripped off before being passed to update_status. The non-PowerBrick responses don't require this character stripping

Comment thread src/dls_pmac_control/__main__.py Outdated
i2t_fault = False
over_current = False

for motor_row in status.motors:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest renaming motor_row to motor as this better matches your new dataclass approach. The motor_row name comes from the way large rows of motor data were passed in the old status update method

Comment thread src/dls_pmac_control/__main__.py Outdated
Comment on lines +704 to +711
if isinstance(self.pmac, PPmacSshInterface):
self.__item(motor_row.number - 1, 1).setText(
str(motor_row.velocity)
)
else:
self.__item(motor_row.number - 1, 1).setText(
str(round(float(motor_row.velocity) * self.servoCycleTime, 1))
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perform the velocity calculation separately so you call a single setText command

eg

if isinstance(self.pmac, PPmacSshInterface):
    velocity = ...
else
    velocity = ...

self.__item(motor_row.number - 1, 1).setText(velocity)

This is the approach in the current codebase.

Comment on lines +720 to +721
# if int(value[5]) > 0:
# over_current = True

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are 2 amplifier status checks which are performed for PowerBricks - I2tFaultStatus amd OverCurrent. So having a single amplifier_status field in the dataclass is not enough.

# number: int
# running: bool
# in_position: bool
identifier_i65: int

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i65 can move into ControllerStatus as it is a per-controller value

if time.time() - self.parent.pmac.last_comm_time < 1.0 / self.max_pollrate:
return
def generate_cmd(self):
print("generate_cmd \n")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want to lose the pollrate calculation. (It may be refactored later but we should keep hold of it for now)

Comment thread src/dls_pmac_control/comms_thread.py Outdated
return None

cmd = self.generate_cmd()
return_thing = self.parsed_poll_response(self.parent.pmac.sendCommand(cmd))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Careful - it is better to handle the success/failure response of sendCommand here rather than pass everything into parsed_poll_response

Also, we need a better variable name than 'return_thing' :)

Comment thread tests/test_csstatus.py Outdated
self.pmac = Mock()
self.commsThread = Mock()
self.commsThread.CSNum = 1
self.comms_worker = Mock()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be reverted again to commsThread as done on the polling branch. Neither will work at the moment in the test, but it will be easier to correct the test as part of your test branch

Comment thread tests/test_watches.py Outdated
QMainWindow.__init__(self, parent)
self.pmac = Mock()
self.commsThread = Mock()
self.comms_worker = Mock()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as previous comment - revert to commsThread

@M-Chan
M-Chan requested a review from JamesOHeaDLS August 19, 2026 08:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants