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

Refactor switch for vesync #134409

Draft
wants to merge 17 commits into
base: dev
Choose a base branch
from
Draft

Conversation

cdnninja
Copy link
Contributor

@cdnninja cdnninja commented Jan 1, 2025

Proposed change

Refactor of switch sensor to support it offering more switches in the future, such as screen on off. This one will wait on the update coordinator merge first then update to reflect those changes. Creating a draft PR for early feedback.

I do not own a vesync switch or outlet so I would love to have someone test this on real hardware.

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.

To help with the load of incoming pull requests:

@home-assistant
Copy link

home-assistant bot commented Jan 1, 2025

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

Code owner commands

Code owners of vesync 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 vesync 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.

@cdnninja
Copy link
Contributor Author

cdnninja commented Jan 1, 2025

@iprak FYI. As two side notes you should add yourself as a code owner on this integration, your support has been incredible. Would love to connect more on the HA discord too.

@cdnninja
Copy link
Contributor Author

cdnninja commented Jan 1, 2025

I am thinking this PR should probably split the removal of the VeSyncDevice entity to a different PR. I don't see value in that class. Just complicates things. Thoughts?

@cdnninja cdnninja changed the title Refactor switch sensor so we can use it for more. Refactor switch sensor for vesync Jan 1, 2025
@cdnninja cdnninja changed the title Refactor switch sensor for vesync Refactor switch for vesync Jan 2, 2025
@cdnninja cdnninja marked this pull request as ready for review January 4, 2025 00:43
@cdnninja
Copy link
Contributor Author

cdnninja commented Jan 4, 2025

My one thought is I am not certain the names of the entities are unchanged for the two existing. I also can't test that hardware as I don't own it.

@iprak
Copy link
Contributor

iprak commented Jan 4, 2025

I am thinking this PR should probably split the removal of the VeSyncDevice entity to a different PR. I don't see value in that class. Just complicates things. Thoughts?

Sure, it definitely helps to keep PR small.

@cdnninja
Copy link
Contributor Author

cdnninja commented Jan 4, 2025

I am thinking this PR should probably split the removal of the VeSyncDevice entity to a different PR. I don't see value in that class. Just complicates things. Thoughts?

Sure, it definitely helps to keep PR small.

Other portion has been split to #134499.

Comment on lines 38 to 42
VeSyncSwitchEntityDescription(
key="device_status",
translation_key="on",
is_on=lambda device: device.device_status == "on",
),
Copy link
Member

Choose a reason for hiding this comment

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

Should we just use the power device class? We should either set the name to None (causing the entity to follow the device name, so switch.vesync_device) or if there already is another main feature of the device (say a climate entity or humidifier), we should use the device class translation for the POWER device class

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Any harm in us not filtering if say it is a fan or humidifer? name would be switch.vesync_device and allow a toggle for power. This keeps the code simple as I don't need to filter if one of those.

Copy link
Contributor

Choose a reason for hiding this comment

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

Duplicate entity? Humidifier and fan both derive from ToggleEntity and expose the same actions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will test this in conjunction with humidifier PR once that one is merged. Lets plan to merge this after that one.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry but why do we need this entity?

The device_status in pyvesync seems to reflect the on/off state which fan/humidifier entities will report as well via is_on. They also have turn_on/turn_off to change the status. I did not check but I think the same should be true for light entities.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They used to sell outlets and switches. As per: https://www.home-assistant.io/integrations/vesync/ so this would show on off for the light switch or outlet. I am thinking I should add a filter ability so it can be removed for select situations. In the future this switch platform can offer other items though, which is the driver for the refactor.

Copy link
Contributor

Choose a reason for hiding this comment

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

Switch and outlet would need that but I don't think they should be needed for fan/humidifiers.

My humidifier appears as following with off state.
image
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will add an additional check so we can adjust for that. I won't get to this right a way since I think humidifier merge and binary_sensor take priority.

homeassistant/components/vesync/switch.py Outdated Show resolved Hide resolved
homeassistant/components/vesync/switch.py Outdated Show resolved Hide resolved
homeassistant/components/vesync/switch.py Outdated Show resolved Hide resolved
@home-assistant
Copy link

home-assistant bot commented Jan 6, 2025

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@home-assistant home-assistant bot marked this pull request as draft January 6, 2025 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants