8000 Migrate tplink integration to new module-based library api by sdb9696 · Pull Request #117839 · home-assistant/core · GitHub
[go: up one dir, main page]

Skip to content

Migrate tplink integration to new module-based library api #117839

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

Merged
merged 4 commits into from
May 22, 2024

Conversation

sdb9696
Copy link
Contributor
@sdb9696 sdb9696 commented May 21, 2024

Proposed change

Migrate the tplink integration to the new common module format of the kasa library api.

Also includes a small dependency bump to pick up some bugfixes found during testing:

https://github.com/python-kasa/python-kasa/releases/tag/0.7.0.dev1

See #117785 for an explanation of the approach for merging into the tplink_rewrite branch.

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
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format 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 8000 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 @rytilahti, @TheGardenMonkey, @bdraco, 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 pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign tplink Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

Copy link
Contributor Author
@sdb9696 sdb9696 left a comment

Choose a reason for hiding this comment

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

This could use some testing with an iot LightStrip.

Comment on lines 365 to +368
# If there is an effect in progress
# we have to set an HSV value to clear the effect
# we have to clear the effect
# before we can set a color temp
await self.device.set_hsv(0, 0, brightness)
await self._light_module.set_hsv(0, 0, brightness)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It might also be possible to call LightEffect.set_effect(LightEffect.LIGHT_EFFECTS_OFF) here but that needs to be tested with an iot` lightstrip.

Copy link
Member

Choose a reason for hiding this comment

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

Something that can be done in the light platform rewrite.

Comment on lines 104 to 108
"""Test no migration happens if the original entity id still exists."""
config_entry = MockConfigEntry(domain=DOMAIN, data={}, unique_id=MAC_ADDRESS)
config_entry.add_to_hass(hass)
dimmer = _mocked_dimmer()
dimmer = _mocked_device(alias="My dimmer", modules=[Module.Light])
rollout_unique_id = MAC_ADDRESS.replace(":", "").upper()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test does not appear to work as I haven't set the device type to dimmer and it still passes (maybe because it's creating the migrated entity entry?). Although I notice the async_fix_dimmer_unique_id function added in #57346 is no longer present so maybe the test is redundant?

Also to get the async_setup_component to properly run I had to add wait_background_tasks=True so I wonder if we need to be adding that in other tests as well.

@sdb9696 sdb9696 marked this pull request as ready for review May 21, 2024 07:59
@sdb9696 sdb9696 requested review from rytilahti and bdraco as code owners May 21, 2024 07:59
Copy link
Member
@rytilahti rytilahti left a comment

Choose a reason for hiding this comment

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

Looks good on the surface, I'll give it a try later.

rytilahti pushed a commit to python-kasa/python-kasa that referenced this pull request May 22, 2024
PR contains a number of fixes from testing with HA devices:

- Fixes a bug with turning the light on and off via `set_state`
- Aligns `set_brightness` behaviour across `smart` and `iot` devices
such that a value of 0 is off.
- Aligns `set_brightness` behaviour for `IotDimmer` such that setting
the brightness turns on the device with a transition of 1ms. ([HA
comment](home-assistant/core#117839 (comment)))
- Fixes a typing issue in `LightState`.
- Adds `ColorTempRange` and `HSV` to `__init__.py`
- Adds a `state` property to the interface returning `LightState` for
validating `set_state` changes.
- Adds tests for `set_state`
Copy link
Member
@rytilahti rytilahti left a comment

Choose a reason for hiding this comment

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

This is good to go, the platform code will be cleaned up in the following platform-specific PRs. Thanks for the PR! 🥇

@@ -312,19 +327,29 @@ def _handle_coordinator_update(self) -> None:
class TPLinkSmartLightStrip(TPLinkSmartBulb):
"""Representation of a TPLink Smart Light Strip."""

device: SmartLightStrip
def __init__(
Copy link
Member

Choose a reason for hiding this comment

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

We can get rid of this now, but that's something for the light platform rewrite 👍

Comment on lines 365 to +368
# If there is an effect in progress
# we have to set an HSV value to clear the effect
# we have to clear the effect
# before we can set a color temp
await self.device.set_hsv(0, 0, brightness)
await self._light_module.set_hsv(0, 0, brightness)
Copy link
Member

Choose a reason for hiding this comment

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

Something that can be done in the light platform rewrite.

@rytilahti rytilahti changed the title Migrate tplink integration to new common module kasa library api Migrate tplink integration to new module-based library api May 22, 2024
@rytilahti rytilahti merged commit 0bea84d into home-assistant:tplink_rewrite May 22, 2024
@sdb9696 sdb9696 deleted the tplink_rewrite branch May 22, 2024 16:57
rytilahti added a commit that referenced this pull request May 22, 2024
* Bump version to 0.7.0.dev0

* Convert SmartDeviceException->KasaException, SmartDevice->Device

* Implement feature-based entities & convert switch platform over

* Allow passing kwargs to descriptions

* Disable all but explicitly enabled debug features per default

* Convert SmartDeviceException->KasaException, SmartDevice->Device

* Migrate tplink integration to new common module kasa library api

* Add has_custom_effects check

* Remove NO_SWITCH_DEVICE_MODULES const

* Remove led test stuff

* Migrate tplink integration to new module-based library api (#117839)

Migrate the tplink integration to the new common module format of the kasa library api.

Also includes a small dependency bump to pick up some bugfixes found during testing:

https://github.com/python-kasa/python-kasa/releases/tag/0.7.0.dev1

See #117785 for an explanation of the approach for merging into the `tplink_rewrite` branch.

---------

Co-authored-by: Teemu Rytilahti <tpr@iki.fi>

* Remove leftover no switch module const

---------

Co-authored-by: Teemu Rytilahti <tpr@iki.fi>
@github-actions github-actions bot locked and limited conversation to collaborators May 23, 2024
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
0