Add input_text component#9112
Conversation
There was a problem hiding this comment.
line too long (82 > 79 characters)
There was a problem hiding this comment.
line too long (80 > 79 characters)
There was a problem hiding this comment.
line too long (91 > 79 characters)
|
Regarding the name, perhaps input_text or input_textbox? |
There was a problem hiding this comment.
Why would we include those patterns in Python? We can just include them in the frontend only.
|
I agree, please rename to I don't think that this component should support numbers/steps/minimum/maximum at all. People can use the input_slider for that. (which should have been called |
|
@balloob Regarding patterns in frontend vs Python, I can make that work (would just have to pass the mode forward and set it in the frontend), but wanted to allow an end user (or someone extending the component) to specify a custom validation pattern if they had a use for it. As for removing numbers & etc, I have a use for a numeric input which isn't a slider, because the range will be user-defined and can be from 0..65535 potentially, but more commonly is going to be well under 0..100 generally - however if using a larger range, using a slider to set to a precise number is cumbersome. I initially built this by copying input_slider, so steps are still in there, and I had considered adding an optional slider for numeric input (so you can use the slider or input a direct number) but I haven't taken the time to figure out how to put in two Polymer widgets together like that. For simplicity, I'm not opposed to removing steps, but the entire reason I'm building this is to use it for primarily numeric input myself (though I have seen requests for generic text inputs / value storage so was enabling all use cases). Min/max for numeric input would be a min/max range just like it is on input_slider, while min/max for non-numeric input would be min/max limitations for text length in characters. |
|
input_slider should be renamed to input_number and should allow an attribute that allows the frontend to switch between a slider and an input type number . input_text should not do any number specific things. Probably also better to skip validation via patterns. |
|
@balloob Renaming input_slider may be quite the breaking change probably ? ... but enhancing it to allow either being slider or input box could be done without breakage |
|
I think that we can justify the breaking change, to align all the |
|
To summarize, proposed changes are:
I think we could still leave in the pattern validation as an optional thing on input_text, but not set in Python (or rather set to |
|
@balloob Do you want me to make all these changes in this PR including changes to input_slider -> input_number, etc, or do we want to handle that separately? |
|
Please create a separate PR for change of input_slider -> input_number. |
|
Will do. I'll finish up input_text first then, then work on the input_number PR. |
9ab2ba4 to
efeca65
Compare
|
Looks like Travis CI failed because Tox took too long to run ? I get various errors on unrelated code locally, but my code isn't currently throwing any tox error locally, I even have tests now... edit: it re-ran itself and passed, looks like. If nobody has any further suggested changes, I'll write up the documentation and submit a PR to the home-assistant.github.io repo for it next. |
|
I restarted the build for you. Glad it passed! We are having a few timeouts lately, and I am not sure what the cause is. |
|
I just made some edits to the OP of PR, with updated yaml config examples and so on. |
|
Don't forget:
|
|
@pvizeli There's nothing specifically number related, not even the pattern validation functionality (if the user choses to use a regex pattern that only validates numbers that's on the user), which is just exposing underlying Polymer functionality. Even if you do so, you only get a I can remove pattern validation if that's really what everyone wants, but why not leave it in for anyone who wants it? If you don't configure it, it's like it's not even there. Min/max are for string length not numeric range limits. There are no number-related configuration options. |
|
Please leave the optional validation and optional min/max length config vars. |
|
Currently default string length min/max are 0/100, could increase default max to something much larger, or allow both to be zero and disable length checking at all in that case (and default both to zero), or just leave as-is. |
|
Added PR for documentation. Let me know whether the defaults and behavior for min/max length are fine as-is, or if I should change them, and if so I'll update the PRs accordingly. If defaults are fine currently, then I think |
|
Thanks for your patience with us and great work ! 👍 🐬 |
Description:
See also PR for polymer side of this feature : home-assistant/frontend#408
WIP, haven't written any documentation yet, but wanted to get feedback and relevant suggestions.This is pretty much finished up, I think, other than submitting a PR for documentation.This implements an input box which can accept strings as well as integers/floats. I need this functionality to implement some features for my Elk M1 security/automation integration, and I figured better to make a generic component that others can use as well.Per PR discussions, only implementing string functionality. We will be renaming input_slider to input_numeric and giving it the ability to be slider or input box as a separate PR, which is what I'll end up using for my Elk integration generally rather than input_text.Client side validation of min/max range on numbers not yet implemented, and it doesn't passPasses tox.toxyet.Specifically I have lint failures due to lines that are too long (I'm not sure the preferred way to shorten these, as some are long if .. and .. conditions and one is a really long string literal), as well as 'Anomalous backslash in string' for some regex's being passed into Polymer. I suppose I could move setting those default patterns to the Polymer side of things, but lint suggests turning them into python regex withPasses tox.rprefix, I suspect this is not actually a good idea since I'm not using them as regex in python itself? I may misunderstand the purpose ofrprefix though.There's also no tests implemented yet.Tests implemented.I'm open to suggestions to change the name to something else, if anyone has a preference for it to be named something else.Was renamed to input_text per discussion in PR.Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#3301
Just strings, no numbers (except that strings can contain numbers, of course, but they're going to be type
strnotfloatorint). Can specify min/max string length, as well as an optional pattern (since Polymer's input text box functionality supports this easily), all of which is client side validated.Example entry for
configuration.yaml(if applicable):Checklist:
If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
toxrun successfully. Your PR cannot be merged unless tests passREQUIREMENTSvariable (example).requirements_all.txtby runningscript/gen_requirements_all.py..coveragerc.If the code does not interact with devices:
toxrun successfully. Your PR cannot be merged unless tests pass