-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
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
Migrate tplink integration to new module-based library api #117839
Conversation
Hey there @rytilahti, @TheGardenMonkey, @bdraco, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
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.
# 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) |
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.
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.
"""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() |
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.
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.
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`
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! 🥇
@@ -312,19 +327,29 @@ def _handle_coordinator_update(self) -> None: | |||
class TPLinkSmartLightStrip(TPLinkSmartBulb): | |||
"""Representation of a TPLink Smart Light Strip.""" | |||
|
|||
device: SmartLightStrip | |||
def __init__( |
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 👍
# 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) |
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.
* 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>
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
Additional information
Checklist
ruff format homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
..coveragerc
.To help with the load of incoming pull requests: