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

Use device-native kelvins for tplink color temperature #85646

Merged
merged 3 commits into from
Feb 21, 2023

Conversation

rytilahti
Copy link
Member

@rytilahti rytilahti commented Jan 10, 2023

Proposed change

This PR converts tplink's light platform to use device-native kelvins for color temperature handling which allows getting rid of mired<->kelvin conversions.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

@home-assistant
Copy link

Hey there @TheGardenMonkey, mind taking a look at this pull request as it has been labeled with an integration (tplink) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of tplink can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Change the title of the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign tplink Removes the current integration label and assignees on the issue, add the integration domain after the command.

@rytilahti
Copy link
Member Author

rytilahti commented Jan 11, 2023

I have no clue why the mypy is still failing:

Error: homeassistant/components/tplink/light.py:216: error: Argument "transition" to "turn_on" of "SmartBulb" has incompatible type "Optional[int]"; expected "int" [arg-type]

The variable in question on 216 is typed to be optional:

    async def _async_turn_on_with_brightness(
        self, brightness: int | None, transition: int | None
    ) -> None:
        # Fallback to adjusting brightness or turning the bulb on
        if brightness is not None:
            await self.device.set_brightness(brightness, transition=transition)
            return
        await self.device.turn_on(transition=transition)

which is what the upstream library also expects: https://github.com/python-kasa/python-kasa/blob/master/kasa/smartbulb.py#L483

edit: Potentially related to the use of implicit optionals (https://github.com/python-kasa/python-kasa/blob/0.5.0/kasa/smartbulb.py#L382) which was fixed in python-kasa/python-kasa#401 that has not yet been released.

Any ideas for the simplest fix without preparing a new release?

@rytilahti rytilahti force-pushed the janitor/tplink/use_kelvins branch from b4fa01b to d981f27 Compare February 18, 2023 22:57
@rytilahti
Copy link
Member Author

rytilahti commented Feb 18, 2023

python-kasa 0.5.0 uses implicit optionals causing mypy to fail, this should get fixed when #88416 gets merged and this PR gets rebased.

edit: looks like that fixes it, so after the bump PR gets merged I'll rebase this again on top of the dev.

@rytilahti rytilahti mentioned this pull request Feb 18, 2023
19 tasks
@rytilahti rytilahti force-pushed the janitor/tplink/use_kelvins branch from d981f27 to e57a588 Compare February 19, 2023 00:16
@rytilahti rytilahti marked this pull request as draft February 19, 2023 01:07
@rytilahti rytilahti force-pushed the janitor/tplink/use_kelvins branch from e57a588 to 192a543 Compare February 19, 2023 14:41
@rytilahti rytilahti marked this pull request as ready for review February 19, 2023 14:41
@rytilahti rytilahti requested a review from bdraco February 20, 2023 00:39
@bdraco
Copy link
Member

bdraco commented Feb 20, 2023

I think this looks good. Need to find time to test it

Copy link
Member

@bdraco bdraco left a comment

Choose a reason for hiding this comment

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

Tested with

KL125(US)
by TP-Link
Firmware: 1.0.7 Build 210811 Rel.171439
Hardware: 2.0

👍

@bdraco
Copy link
Member

bdraco commented Feb 21, 2023

Thanks @rytilahti

@bdraco bdraco merged commit a93b4e7 into home-assistant:dev Feb 21, 2023
@bdraco
Copy link
Member

bdraco commented Feb 21, 2023

Screenshot_2023-02-21_at_12_55_45_PM

Also did some more testing with the 5s update interval.. seems like it will be just fine 😉

@bdraco
Copy link
Member

bdraco commented Feb 21, 2023

@rytilahti rytilahti deleted the janitor/tplink/use_kelvins branch February 21, 2023 19:29
@github-actions github-actions bot locked and limited conversation to collaborators Feb 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants