Add support for percentage step size to fans (#8393)

This commit is contained in:
J. Nick Koston 2021-02-22 11:59:59 -10:00 committed by GitHub
parent 741ac679a0
commit ace7ee5622
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -79,6 +79,10 @@ class HaSlider extends PaperSliderClass {
return subTemplate;
}
_setImmediateValue(newImmediateValue) {
super._setImmediateValue(Math.round(newImmediateValue));
}
_calcStep(value) {
if (!this.step) {
return parseFloat(value);

View File

@ -52,6 +52,7 @@ class MoreInfoFan extends LocalizeMixin(EventsMixin(PolymerElement)) {
caption="[[localize('ui.card.fan.speed')]]"
min="0"
max="100"
step="[[computePercentageStepSize(stateObj)]]"
value="{{percentageSliderValue}}"
on-change="percentageChanged"
pin=""
@ -113,7 +114,7 @@ class MoreInfoFan extends LocalizeMixin(EventsMixin(PolymerElement)) {
<ha-attributes
state-obj="[[stateObj]]"
extra-filters="speed,preset_mode,preset_modes,speed_list,percentage,oscillating,direction"
extra-filters="percentage_step,speed,preset_mode,preset_modes,speed_list,percentage,oscillating,direction"
></ha-attributes>
`;
}
@ -154,6 +155,13 @@ class MoreInfoFan extends LocalizeMixin(EventsMixin(PolymerElement)) {
}
}
computePercentageStepSize(stateObj) {
if (stateObj.attributes.percentage_step) {
return stateObj.attributes.percentage_step;
}
return 1;
}
computeClassNames(stateObj) {
return (
"more-info-fan " +