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

Fix for exception when checking if fan without speed is on #39096

Merged
merged 3 commits into from
Aug 21, 2020

Conversation

kbickar
Copy link
Contributor

@kbickar kbickar commented Aug 21, 2020

Proposed change

The is_on function was generating an exception for fans without a speed such as an MQTT fan

This change updates that to first check if there's a speed attribute and if it can't find one it uses the state instead.

The MQTT fan component has also been standardized from using a boolean state to using STATE_ON/STATE_OFF

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)
  • 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
  • The code has been formatted using Black (black --fast 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.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

To help with the load of incoming pull requests:

@probot-home-assistant
Copy link

Hey there @home-assistant/core, @emontnemery, mind taking a look at this pull request as its been labeled with an integration (mqtt) you are listed as a codeowner for? Thanks!
(message by CodeOwnersMention)

Copy link
Contributor

@bachya bachya left a comment

Choose a reason for hiding this comment

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

Thanks!

@bachya bachya merged commit 2ec546d into home-assistant:dev Aug 21, 2020
@kbickar kbickar deleted the fan_on branch August 21, 2020 14:25
@@ -335,7 +337,7 @@ def assumed_state(self):
@property
def is_on(self):
"""Return true if device is on."""
return self._state
return self._state == 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.

This change wasn't needed. We prefer to just use a boolean.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not strictly needed given the state property uses is_on, but I thought it makes it more clear given the variable is called _state, not _is_on

Copy link
Member

Choose a reason for hiding this comment

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

We prefer to keep it simple.

Copy link
Contributor

Choose a reason for hiding this comment

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

@MartinHjelmare This PR was maybe merged a bit too quickly, do you think it should be reverted?

Copy link
Member

Choose a reason for hiding this comment

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

The fix for is_on function is good. The changes around the property are not wanted and we should revert those.

@emontnemery
Copy link
Contributor

@kbickar Can you give an example of when is_on in the base component generated exceptions?

@MartinHjelmare
Copy link
Member

If a fan entity doesn't support set speed it won't have ATTR_SPEED in the state attributes so there would be a KeyError.

if supported_features & SUPPORT_SET_SPEED:
data[ATTR_SPEED] = self.speed

@kbickar
Copy link
Contributor Author

kbickar commented Aug 22, 2020

Here's an example configuration that would cause the issue:

  - platform: mqtt
    name: "Sonoff Fan"
    state_topic: "stat/box_fan/POWER"
    command_topic: "cmnd/box_fan/power"

As @MartinHjelmare said, since the speed attribute is optional and not set if it's not a supported feature, it generates a KeyError

@emontnemery
Copy link
Contributor

Thanks @kbickar and @MartinHjelmare!

emontnemery added a commit to emontnemery/home-assistant that referenced this pull request Aug 27, 2020
@emontnemery emontnemery mentioned this pull request Aug 27, 2020
21 tasks
weissm pushed a commit to weissm/core that referenced this pull request Aug 28, 2020
…stant#39096)

* Fix for exception when checking if fan without speed is on

* Organized imports

* Space
leikoilja pushed a commit to leikoilja/core that referenced this pull request Sep 6, 2020
…stant#39096)

* Fix for exception when checking if fan without speed is on

* Organized imports

* Space
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.

5 participants