Skip to content

Add mode attribute to number entity#43867

Closed
Shulyaka wants to merge 4 commits intohome-assistant:devfrom
Shulyaka:number_mode
Closed

Add mode attribute to number entity#43867
Shulyaka wants to merge 4 commits intohome-assistant:devfrom
Shulyaka:number_mode

Conversation

@Shulyaka
Copy link
Copy Markdown
Contributor

@Shulyaka Shulyaka commented Dec 2, 2020

Proposed change

Since the basic support for the number entity is merged (#42735), it's time to add additional features to it.
The most important is the mode attribute like with input_number. It will be used to define the type of control that is more natural to the entity. The entities that are more analogue by nature could enjoy the nice slider in the frontend, while the ones that are more digital would provide input as text.

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

Example entry for configuration.yaml:

# Example configuration.yaml
demo:

Additional information

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
Copy Markdown

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

@probot-home-assistant
Copy link
Copy Markdown

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

@github-actions
Copy link
Copy Markdown

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days.
Thank you for your contributions.

@github-actions github-actions bot added the stale label Jan 26, 2021
@Shulyaka
Copy link
Copy Markdown
Contributor Author

Dear bot, please remove the stale label. Thank you.

@github-actions
Copy link
Copy Markdown

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days.
Thank you for your contributions.

@github-actions github-actions bot added the stale label Feb 25, 2021
@Shulyaka
Copy link
Copy Markdown
Contributor Author

May I ask someone to re-trigger the CI pipeline please?

@github-actions github-actions bot removed the stale label Feb 25, 2021
@frenck
Copy link
Copy Markdown
Member

frenck commented Mar 1, 2021

This requires a frontend PR as well?

@Shulyaka
Copy link
Copy Markdown
Contributor Author

Shulyaka commented Mar 2, 2021

Probably, yes (after home-assistant/frontend#8325).

@JeffLIrion
Copy link
Copy Markdown
Contributor

Probably, yes (after home-assistant/frontend#8325).

Are the changes required as simple as reverting that pull request?

I want to use the number platform in a custom component of mine and I like the slider view much better than the box view, so I'm trying to push this through!👍

return step

@property
def mode(self) -> str:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Isn't this competing with device class?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How is that?

Copy link
Copy Markdown
Member

@balloob balloob Mar 18, 2021

Choose a reason for hiding this comment

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

It's an attribute that further classifies this entity which influences how it is represented.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That is true, so is the device class, icon, name, picture and such itself.
There must be a way for an integration to provide details on e.g., min/max, but also a representation. I could see the frontend being able to override that (e.g., in a Lovelace configuration).

Alternatively, we could indeed introduce device classes to the number integration, although, in general, the input is not always related to the unit shown.

E.g., Speed. Could be something between 0-100%/1-255, or something between 500-15000rpm. The first would be a nice slider, the second... probably not that much.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

AAAAAAAAAAAAAAAAAH 😆

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Correct me if I'm mistaken, but I assume that these changes are beyond the scope of this pull request.

Are there any changes necessary to get this merged in?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It would be an alternative that would render this PR not needed.

Copy link
Copy Markdown
Contributor Author

@Shulyaka Shulyaka Mar 21, 2021

Choose a reason for hiding this comment

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

The advantage of the mode attribute is that it gives a platform more control over the representation, and the platform knows better whether the value it has is more discrete or monotonous. So, I would consider this PR as more about the nature of the data than just about a representation.
Also, it gives the control for the user to override it using the existing customize functionality.

As a compromise for the both, I can suggest to implement the same nice algorithm but as a default value for the attribute, e.g. instead of return MODE_SLIDER it would be more like return MODE_SLIDER if (max - min) / steps <= 255 else MODE_BOX.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also, it gives the control for the user to override it using the existing customize functionality.

That is not something that should be used to adjust UI behavior, for these things we have the UI itself.

I agree with the suggestion given by balloob for that matter.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should start with my suggestion and then we can see if this PR is still needed. Let's not apply multiple solutions at once.

@github-actions
Copy link
Copy Markdown

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days.
Thank you for your contributions.

@github-actions github-actions bot added the stale label Apr 20, 2021
@github-actions github-actions bot closed this Apr 27, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Apr 28, 2021
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.

6 participants