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

Reduce code duplication with _toggle_state() function in Flashlight #4586

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

omamkaz
Copy link
Contributor

@omamkaz omamkaz commented Dec 16, 2024

Just some tricks that I think might improve the code! :)

Description

Test Code

# Test code for the review of this PR

Type of change

Checklist

  • I signed the CLA.
  • I have performed a self-review of my own code

Screenshots

Additional details

Summary by Sourcery

Enhancements:

  • Refactor flashlight state management by introducing a private method _toggle_state to handle state changes, reducing code duplication.

## Just some tricks that I think might improve the code! :)
@FeodorFitsner
Copy link
Contributor

I'm wondering if flashlight is turned off on device side are we getting the state change back in Python code?

@omamkaz
Copy link
Contributor Author

omamkaz commented Dec 17, 2024

I'm wondering if flashlight is turned off on device side are we getting the state change back in Python code?

Thanks, I think I made a mistake in the _toggle_state method so that the update will be like

def _toggle_state(self, sr: str, state: bool=True) -> bool:
    if ("1" == sr):
        self.turned_on = state
    return self.turned_on

Is it true or what?

Copy link
Contributor

@bleudev bleudev left a comment

Choose a reason for hiding this comment

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

Good work, but can you fix this? It's strange looking.

@bleudev
Copy link
Contributor

bleudev commented Mar 15, 2025

Can you change title like this: Reduce code duplication with _toggle_state() function in Flashlight?

@omamkaz omamkaz changed the title Update flashlight.py Reduce code duplication with _toggle_state() function in Flashlight Mar 15, 2025
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.

3 participants