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

Minor polishing for tplink #120868

Merged
merged 11 commits into from
Jul 2, 2024
Merged

Minor polishing for tplink #120868

merged 11 commits into from
Jul 2, 2024

Conversation

rytilahti
Copy link
Member

@rytilahti rytilahti commented Jun 30, 2024

Proposed change

This PR collects some minor improvements for the tplink based on earlier comments and testing during beta.

  • Enable basic effect support on all supported devices
  • Set color mode correctly when an effect is active
  • Allow current_consumption on light bulbs
  • Cleanup some unnecessary code spotted in previous code review rounds

TBD:

  • Fix light bulbs power consumption (currently hidden as it's a primary feature on a device with a specialized platform)
  • Bump to python-kasa 0.7.0.2: Bump python-kasa to 0.7.0.2 #120940

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 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 @bdraco, @sdb9696, 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.

@@ -144,21 +143,6 @@ class TPLinkSensorEntity(CoordinatedTPLinkFeatureEntity, SensorEntity):

entity_description: TPLinkSensorEntityDescription

def __init__(
Copy link
Member Author

Choose a reason for hiding this comment

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

No need for __init__s for sensor and switch as parent's async_added_to_hass takes care of updating the state.

Comment on lines -64 to -65
# fan
"fan_speed_level",
Copy link
Member Author

Choose a reason for hiding this comment

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

We have fan platform so this is not necessary anymore.

@rytilahti rytilahti mentioned this pull request Jul 1, 2024
20 tasks
@rytilahti rytilahti added this to the 2024.7.0 milestone Jul 1, 2024
@@ -371,6 +370,7 @@ def _async_update_attrs(self) -> None:
effect_module = self._effect_module
if effect_module.effect != LightEffect.LIGHT_EFFECTS_OFF:
self._attr_effect = effect_module.effect
self._attr_color_mode = ColorMode.BRIGHTNESS
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to set this back to the correct mode once the effect is switched off? It's slightly confusing because I see there's _determine_color_mode in super()._async_update_attrs but it's not clear whether that does as much as the TPLinkLightEntity constructor. Is there duplicated logic in there?

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 don't think we need to do that as it's taken care of through the _determine_color_mode, we just override that for this special case.

I don't see duplicate logic either, as the ctor only initializes the available modes and leaves setting the active one to the _async_update_attrs of the corresponding class.

@@ -73,7 +73,7 @@
"value": 121.1,
"type": "Sensor",
"category": "Primary",
"unit": "v",
"unit": "V",
Copy link
Member Author

Choose a reason for hiding this comment

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

This caused a warning due to incorrect unit for the device class.

rytilahti added 2 commits July 1, 2024 23:53
…ate in __init__

This is necessary as setting the attributes in async_added_to_hass is too late for snapshot testing
@rytilahti rytilahti marked this pull request as ready for review July 1, 2024 22:04
@rytilahti rytilahti requested a review from bdraco as a code owner July 1, 2024 22:04
@rytilahti rytilahti requested a review from sdb9696 July 1, 2024 22:22
@frenck frenck merged commit 90d622c into dev Jul 2, 2024
25 checks passed
@frenck frenck deleted the tplink/janitor/cleanup branch July 2, 2024 06:23
frenck pushed a commit that referenced this pull request Jul 2, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jul 3, 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.

4 participants