Skip to content

Add evaporative humidifier for switchbot integration #146235

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

Conversation

zerzhang
Copy link
Contributor

@zerzhang zerzhang commented Jun 6, 2025

Breaking change

Proposed change

  • Add evaporative humidifier

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:
  • Link to developer documentation pull request:
  • Link to frontend 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 Jun 6, 2025

Hey there @Danielhiversen, @RenierM26, @murtas, @Eloston, @dsypniewski, mind taking a look at this pull request as it has been labeled with an integration (switchbot) you are listed as a code owner for? Thanks!

Code owner commands

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

@zerzhang zerzhang force-pushed the feature/add_evaporative_humidifier branch from c155a2e to 1731b68 Compare June 6, 2025 10:33
@zerzhang zerzhang force-pushed the feature/add_evaporative_humidifier branch from 64e13b0 to 444c7ae Compare June 11, 2025 06:48
@zerzhang
Copy link
Contributor Author

@joostlek could you help to review this pr?

async def async_set_humidity(self, humidity: int) -> None:
"""Set new target humidity."""
_LOGGER.debug("Setting target humidity to: %s %s", humidity, self._address)
self._last_run_success = bool(await self._device.set_target_humidity(humidity))
Copy link
Member

Choose a reason for hiding this comment

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

I think this is more a general comment, but currently we set _last_run_success and I think instead we should raise a translated exception if the integration did not do what we expect it to do

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 has been implemented, I have raised the exception in pyswitchbot
image

Copy link
Member

Choose a reason for hiding this comment

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

But if it fails, it doesn't set the last update success anymore right? I think this is something we can deprecate and remove from all switchbot entities

"water_level": SensorEntityDescription(
key="water_level",
translation_key="water_level",
icon="mdi:water-check",
Copy link
Member

Choose a reason for hiding this comment

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

use icon translations for this one

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@home-assistant home-assistant bot marked this pull request as draft June 17, 2025 08:32
@home-assistant
Copy link

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.

@zerzhang zerzhang force-pushed the feature/add_evaporative_humidifier branch from 444c7ae to f86c4e9 Compare June 18, 2025 09:11
@zerzhang zerzhang marked this pull request as ready for review June 18, 2025 09:21
@home-assistant home-assistant bot requested a review from joostlek June 18, 2025 09:21
Comment on lines 165 to 177
@property
def icon(self) -> str | None:
"""Return the icon based on the sensor's state."""

if self.entity_description.key != "water_level":
return super().icon
icons = {
"empty": "mdi:water-off",
"low": "mdi:water-outline",
"medium": "mdi:water",
"high": "mdi:water-check",
}
return icons.get(str(self.native_value), "mdi:water-alert")
Copy link
Member

Choose a reason for hiding this comment

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

use icon translations instead

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 have fixed this

Comment on lines 152 to 158
"state_attributes": {
"last_run_success": {
"state": {
"true": "[%key:component::binary_sensor::entity_component::problem::state::off%]",
"false": "[%key:component::binary_sensor::entity_component::problem::state::on%]"
}
},
Copy link
Member

Choose a reason for hiding this comment

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

these arent used anymore right

Copy link
Contributor Author

Choose a reason for hiding this comment

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

these arent used anymore right

i have removed from this pr, but others not, I will remove all of these in a Independent PR

Copy link
Member

Choose a reason for hiding this comment

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

note: we need to deprecate them, so I would suggest to add a comment to the places where we set it, and then just set the variable like we did before, write state, and then raise. That PR would be marked as deprecation and we should explain in the breaking changes section what is changing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For the newly added products, we deprecate the last_run_success attribute. For the already supported products, I will remove this attribute and make a breaking statement. right?

Copy link
Member

Choose a reason for hiding this comment

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

Newly added products won't get it at all, while we need to deprecate it for existing devices and announce it first and then remove in 6 months

Copy link
Member

Choose a reason for hiding this comment

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

But we should still remove it here right

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But we should still remove it here right

I have removed it now and i have create a PR #147473 to remove for other products

@home-assistant home-assistant bot marked this pull request as draft June 23, 2025 13:17
@zerzhang zerzhang marked this pull request as ready for review June 23, 2025 14:02
@home-assistant home-assistant bot requested a review from joostlek June 23, 2025 14:02
"water_level": {
"name": "Water level",
"state": {
"empty": "Empty",
Copy link
Contributor

Choose a reason for hiding this comment

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

@joostlek If we merged #146646 before this one we could change this to "[%key:common::state::empty%]".

@joostlek joostlek merged commit d0b2d1d into home-assistant:dev Jun 25, 2025
34 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Jun 26, 2025
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