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

Add type hints to smart_task.py #456

Merged
merged 15 commits into from
Mar 15, 2022
Merged

Conversation

ggravlingen
Copy link
Member

No description provided.

@ggravlingen
Copy link
Member Author

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.

self,
item: StartActionItem,
raw: TypeRaw,
state: int,
Copy link
Contributor

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.

Copy link
Member Author

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?

def devices(self):

That will remove one of the places StartActionItem is being used.

Copy link
Member Author

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.

@ggravlingen
Copy link
Member Author

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.

@MartinHjelmare
Copy link
Contributor

Looks good. I think it may be easier to verify the correctness of the change if we type the whole module in one PR.

@ggravlingen
Copy link
Member Author

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},
Copy link
Member Author

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.

pytradfri/smart_task.py Outdated Show resolved Hide resolved
pytradfri/smart_task.py Outdated Show resolved Hide resolved
@ggravlingen ggravlingen changed the title Add type hints StartActionItemController Add type hints to smart_task.py Mar 13, 2022
pytradfri/smart_task.py Outdated Show resolved Hide resolved
pytradfri/smart_task.py Outdated Show resolved Hide resolved
pytradfri/smart_task.py Outdated Show resolved Hide resolved
pytradfri/smart_task.py Outdated Show resolved Hide resolved
ggravlingen and others added 2 commits March 14, 2022 19:55
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
pytradfri/smart_task.py Outdated Show resolved Hide resolved
pytradfri/smart_task.py Outdated Show resolved Hide resolved
Copy link
Contributor

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

Great!

@ggravlingen ggravlingen merged commit 38c36fa into master Mar 15, 2022
@ggravlingen ggravlingen deleted the type-startactionitemcontroller branch March 15, 2022 06:25
ggravlingen added a commit that referenced this pull request Mar 15, 2022
* 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>
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