GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Migrate tplink integration to new module-based library api by sdb9696 · Pull Request #117839 · home-assistant/core

Conversation

@sdb9696

@sdb9696 sdb9696 commented May 21, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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:

  • Documentation added/updated for www.home-assistant.io

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:

  • I have reviewed two other open pull requests in this repository.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
rytilahti and others added 2 commits May 20, 2024 13:22
@rytilahti @sdb9696
Convert SmartDeviceException->KasaException, SmartDevice->Device
eb88b41
@sdb9696
Migrate tplink integration to new common module kasa library api
f83c0cd
@home-assistant home-assistant Bot added cla-signed code-quality has-tests integration: tplink labels May 21, 2024
@home-assistant home-assistant Bot assigned rytilahti and bdraco May 21, 2024
@home-assistant home-assistant Bot added by-code-owner Quality Scale: platinum labels May 21, 2024
@home-assistant

home-assistant Bot commented May 21, 2024

Copy link
Copy Markdown
Contributor

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.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

sdb9696
sdb9696 commented May 21, 2024
View reviewed changes

@sdb9696 sdb9696 left a comment

Copy link
Copy Markdown
Contributor Author

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.

This could use some testing with an iot LightStrip.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread homeassistant/components/tplink/const.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread homeassistant/components/tplink/light.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread homeassistant/components/tplink/light.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread homeassistant/components/tplink/light.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread homeassistant/components/tplink/light.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread homeassistant/components/tplink/light.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread homeassistant/components/tplink/light.py
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)

@sdb9696 sdb9696 May 21, 2024

Copy link
Copy Markdown
Contributor Author

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.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

rytilahti reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@rytilahti rytilahti May 22, 2024

Copy link
Copy Markdown
Member

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.

Something that can be done in the light platform rewrite.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread homeassistant/components/tplink/switch.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/components/tplink/test_init.py
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()

@sdb9696 sdb9696 May 21, 2024

Copy link
Copy Markdown
Contributor Author

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.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread tests/components/tplink/test_light.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@sdb9696
Add has_custom_effects check
179c071
@sdb9696
sdb9696 marked this pull request as ready for review May 21, 2024 07:59
@sdb9696
sdb9696 requested review from bdraco and rytilahti as code owners May 21, 2024 07:59
rytilahti
rytilahti reviewed May 21, 2024
View reviewed changes

@rytilahti rytilahti left a comment

Copy link
Copy Markdown
Member

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.

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread homeassistant/components/tplink/const.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread homeassistant/components/tplink/switch.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread homeassistant/components/tplink/switch.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/components/tplink/__init__.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread homeassistant/components/tplink/light.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@sdb9696 sdb9696 mentioned this pull request May 22, 2024
Fix set_state for common light modules python-kasa/python-kasa#929
Merged
@sdb9696
sdb9696 force-pushed the tplink_rewrite branch from 93ac781 to 179c071 Compare May 22, 2024 11:36
rytilahti pushed a commit to python-kasa/python-kasa that referenced this pull request May 22, 2024
@sdb9696
Fix set_state for common light modules (#929)
db6e335
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`
@sdb9696
Bump python-kasa to 0.7.0.dev1
f80628f
rytilahti
rytilahti approved these changes May 22, 2024
View reviewed changes

@rytilahti rytilahti left a comment •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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.

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread homeassistant/components/tplink/light.py
"""Representation of a TPLink Smart Light Strip."""

device: SmartLightStrip
def __init__(

@rytilahti rytilahti May 22, 2024

Copy link
Copy Markdown
Member

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.

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread homeassistant/components/tplink/light.py
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)

@rytilahti rytilahti May 22, 2024

Copy link
Copy Markdown
Member

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.

Something that can be done in the light platform rewrite.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@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
@sdb9696 @rytilahti
Merge api deprecation changes back into the switch branch (#117898)
9d56029
* 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 <[email protected]>

* Remove leftover no switch module const

---------

Co-authored-by: Teemu Rytilahti <[email protected]>
@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.

Reviewers

@rytilahti rytilahti rytilahti approved these changes
@bdraco bdraco Awaiting requested review from bdraco

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@bdraco bdraco

@rytilahti rytilahti

Labels

by-code-owner cla-signed code-quality has-tests integration: tplink Quality Scale: platinum

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@sdb9696 @rytilahti @bdraco
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402605 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.