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

FAST Neuron should ignore switches on other platforms #1837

Merged
merged 3 commits into from
Oct 4, 2024

Conversation

bosh
Copy link
Contributor

@bosh bosh commented Sep 20, 2024

If using multiple platforms for switches, the Neuron communicator will try to look up every switch as though they are connected to FAST hardware, causing a crash. This is a bad assumption and it keeps a machine creator from declaring virtual switches when using a Neuron.

Virtual switches can be useful in letting a machine developer add switches to configs before they're wired into the machine, or even by creating virtual-only switches that will never be physically implemented, but can be used in mpf-monitor for debugging and arbitrary event creation.

First commit changes Neuron platform tests to be explicit about which platform they're using (instead of defaulting) but should be green. (Action run: https://github.com/bosh/mpf/actions/runs/10966582957 )
Second commit changes the test to include a cross-platform switch that causes crashes (9x crash in that test file due to Neuron not filtering switch platform) (Action run: https://github.com/bosh/mpf/actions/runs/10966584585 )
Third commit fixes the Neuron communicator code. I'm not sure of the best syntax for this in Python (could we filter the .values() call?) but it works :)

@@ -294,6 +294,9 @@ def update_switches_from_hw_data(self):
it will process it like any switch change.
"""
for switch in self.machine.switches.values():
if switch.platform != self.platform:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I expect there's a better way in python to filter, and then not even need the continue

Copy link
Collaborator

Choose a reason for hiding this comment

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

You should be able to do it like this:

for switch in self.machine.switches.values() if switch.platform == self.platform:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Took a few whacks at it and found the final syntax. It's a little awkward imo, but it's in :)

Copy link

sonarcloud bot commented Oct 2, 2024

@bosh
Copy link
Contributor Author

bosh commented Oct 2, 2024

PR is all ready for final review! I've also tested the current version (with the list comprehension) on my neuron, no problems.

Copy link
Collaborator

@avanwinkle avanwinkle left a comment

Choose a reason for hiding this comment

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

Great fix, thanks!

@avanwinkle avanwinkle merged commit 172b5d9 into missionpinball:dev Oct 4, 2024
15 checks passed
@bosh bosh deleted the fast_switch_filter_pr branch October 15, 2024 08:57
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