-
Notifications
You must be signed in to change notification settings - Fork 130
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
Add type hints to smart_task.py #456
Conversation
I'm breaking this down, probably class by class. I'm seeing code here that we really should deprecate and remove but let's do that after all typing is done. |
pytradfri/smart_task.py
Outdated
self, | ||
item: StartActionItem, | ||
raw: TypeRaw, | ||
state: int, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There seem to be some ambiguity about the state type as there are two different origins of StartActionItem
. For one state is a boolean and for the other it's an integer. A boolean is a subtype of an integer but we may need to convert it to a number if we expect that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is a horrible mess (I don't blame anyone, I wrote this code when I just got into Python).
I believe we can drop this property as I can't see it being used anywhere?
pytradfri/pytradfri/smart_task.py
Line 203 in 421a923
def devices(self): |
That will remove one of the places StartActionItem
is being used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
state
is normally a bool
throughout the code so I went for that option and converted them to an int
where needed.
I touched a few lins that I hadn't planned on being in scope for this PR. It, hoever, felt motivated to make it clear what is going on. |
Looks good. I think it may be easier to verify the correctness of the change if we type the whole module in one PR. |
OK, I'll push more changes here. |
@@ -14,6 +14,7 @@ | |||
"15013": [ | |||
{"5712": 18000, "5851": 254, "9003": 65537}, | |||
{"5712": 18000, "5851": 254, "9003": 65538}, | |||
{"5712": 19000, "5851": 230, "9003": 65539}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasn't sure if the devices_list
property worked properly so I added one more record here.
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great!
* Add type hints StartActionItemController * Fix typo * Add type hints * Convert to int * Add type hints * FIx test * Make transition time optional * Implement calibration method * Improve setter * Remove setter * Refactor * Update pytradfri/smart_task.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Remove type annotation * Fix? * Remove type hints Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
No description provided.