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

Implement pydantic for lights #436

Merged
merged 20 commits into from
Feb 27, 2022
Merged

Implement pydantic for lights #436

merged 20 commits into from
Feb 27, 2022

Conversation

ggravlingen
Copy link
Member

No description provided.

@ggravlingen
Copy link
Member Author

Figured we'd sort out the typing stuff before I move on to fixing the tests.

pytradfri/device/light.py Outdated Show resolved Hide resolved
pytradfri/device/light.py Outdated Show resolved Hide resolved
pytradfri/device/light.py Outdated Show resolved Hide resolved

@property
def dimmer(self):
def dimmer(self) -> int | None:
"""Return dimmer if present."""
if self.supported_features & SUPPORT_BRIGHTNESS:
Copy link
Contributor

Choose a reason for hiding this comment

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

dimmer is not optional in the response model. Can it still be not supported?

Copy link
Member Author

Choose a reason for hiding this comment

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

I can't think of any light device that is not dimmable. Perhaps we should drop this supported_features-check and just return the int?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, maybe. Ok to leave for the future though.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll leave it for now. I'm expecting to have to update a few tests in this PR so I con't want to mistakenly cause regression errors here.

pytradfri/device/light_control.py Outdated Show resolved Hide resolved
pytradfri/device/light_control.py Outdated Show resolved Hide resolved
ggravlingen and others added 4 commits February 26, 2022 21:17
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
return None

@property
def hsb_xy_color(self):
def hsb_xy_color(
Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe add checks for None here as well?

Copy link
Contributor

Choose a reason for hiding this comment

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

How is this used? Returning both hsb and xy together is unfamiliar to me.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@MartinHjelmare MartinHjelmare Feb 26, 2022

Choose a reason for hiding this comment

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

Side note for the future: Since we return xy color from another property I would expect this one to only return hsb color. Maybe add a property that does that and deprecate this one?

I agree that we should only return a tuple if all items are not None.

Copy link
Member Author

Choose a reason for hiding this comment

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

Want me to deprecate here in this PR?

Copy link
Contributor

Choose a reason for hiding this comment

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

Nah, just some thoughts for the future.

tests/test_color.py Outdated Show resolved Hide resolved
tests/test_color.py Outdated Show resolved Hide resolved
"""Test light on."""
device_data = deepcopy(LIGHT_WS)
device_data[ATTR_LIGHT_CONTROL][0][ATTR_DEVICE_STATE] = 1
device = Device(deepcopy(device_data))
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we copy twice?

Copy link
Member Author

Choose a reason for hiding this comment

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

A mistake, will remove

ggravlingen and others added 2 commits February 27, 2022 10:37
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
@ggravlingen
Copy link
Member Author

ggravlingen commented Feb 27, 2022

When this is merged, we should be good to bump in core I guess? And folliwing that, remove a few cast statements.

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.

Nice!

@MartinHjelmare
Copy link
Contributor

I would complete the typing so we can add py.typed before bumping in core if it's only for typing purposes.

@ggravlingen ggravlingen merged commit 1a6597f into master Feb 27, 2022
@ggravlingen ggravlingen deleted the pydantic-light branch February 27, 2022 10:08
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