diff --git a/src/more-infos/more-info-cover.html b/src/more-infos/more-info-cover.html index b27f502ec6..3db3dcd060 100644 --- a/src/more-infos/more-info-cover.html +++ b/src/more-infos/more-info-cover.html @@ -4,6 +4,8 @@ + + @@ -16,6 +18,10 @@ .has-current_tilt_position .current_tilt_position { max-height: 90px; } + + [invisible] { + visibility: hidden !important; + } @@ -26,6 +32,7 @@ min='0' max='100' value='{{coverPositionSliderValue}}' step='1' pin + disabled='[[!entityObj.supportsSetPosition]]' on-change='coverPositionSliderChanged'> @@ -33,16 +40,20 @@ Tilt position + invisible$='[[!entityObj.supportsOpenTilt]]' + disabled='[[entityObj.isFullyOpenTilt]]'> + invisible$='[[!entityObj.supportsStopTilt]]' + title='Stop tilt'> + invisible$='[[!entityObj.supportsCloseTilt]]' + disabled='[[entityObj.isFullyClosedTilt]]'> @@ -64,6 +75,11 @@ Polymer({ observer: 'stateObjChanged', }, + entityObj: { + type: Object, + computed: 'computeEntityObj(hass, stateObj)', + }, + coverPositionSliderValue: { type: Number, }, @@ -73,6 +89,10 @@ Polymer({ }, }, + computeEntityObj: function (hass, stateObj) { + return new window.CoverEntity(hass, stateObj); + }, + stateObjChanged: function (newVal) { this.coverPositionSliderValue = newVal.attributes.current_position; this.coverTiltPositionSliderValue = newVal.attributes.current_tilt_position; @@ -84,40 +104,23 @@ Polymer({ }, coverPositionSliderChanged: function (ev) { - this.hass.callService('cover', 'set_cover_position', { - entity_id: this.stateObj.entity_id, - position: ev.target.value, - }); + this.entityObj.setCoverPosition(ev.target.value); }, coverTiltPositionSliderChanged: function (ev) { - this.hass.callService('cover', 'set_cover_tilt_position', { - entity_id: this.stateObj.entity_id, - tilt_position: ev.target.value, - }); - }, - - computeIsFullyOpenTilt: function (stateObj) { - return stateObj.attributes.current_tilt_position === 100; - }, - - computeIsFullyClosedTilt: function (stateObj) { - return stateObj.attributes.current_tilt_position === 0; + this.entityObj.setCoverTiltPosition(ev.target.value); }, onOpenTiltTap: function () { - this.hass.callService('cover', 'open_cover_tilt', - { entity_id: this.stateObj.entity_id }); + this.entityObj.openCoverTilt(); }, onCloseTiltTap: function () { - this.hass.callService('cover', 'close_cover_tilt', - { entity_id: this.stateObj.entity_id }); + this.entityObj.closeCoverTilt(); }, onStopTiltTap: function () { - this.hass.callService('cover', 'stop_cover_tilt', - { entity_id: this.stateObj.entity_id }); + this.entityObj.stopCoverTilt(); }, }); diff --git a/src/state-summary/state-card-cover.html b/src/state-summary/state-card-cover.html index c673a934a5..ea8c047b0a 100644 --- a/src/state-summary/state-card-cover.html +++ b/src/state-summary/state-card-cover.html @@ -6,6 +6,8 @@ + + @@ -19,16 +21,23 @@ white-space: nowrap; width: 127px; } + + [invisible] { + visibility: hidden !important; + } - + invisible$='[[!entityObj.supportsOpen]]' + disabled='[[entityObj.isFullyOpen]]'> + + invisible$='[[!entityObj.supportsClose]]' + disabled='[[entityObj.isFullyClosed]]'> @@ -51,35 +60,27 @@ Polymer({ stateObj: { type: Object, }, + + entityObj: { + type: Object, + computed: 'computeEntityObj(hass, stateObj)', + }, }, - computeIsFullyOpen: function (stateObj) { - if (stateObj.attributes.current_position !== undefined) { - return stateObj.attributes.current_position === 100; - } - return stateObj.state === 'open'; - }, - - computeIsFullyClosed: function (stateObj) { - if (stateObj.attributes.current_position !== undefined) { - return stateObj.attributes.current_position === 0; - } - return stateObj.state === 'closed'; + computeEntityObj: function (hass, stateObj) { + return new window.CoverEntity(hass, stateObj); }, onOpenTap: function () { - this.hass.callService('cover', 'open_cover', - { entity_id: this.stateObj.entity_id }); + this.entityObj.openCover(); }, onCloseTap: function () { - this.hass.callService('cover', 'close_cover', - { entity_id: this.stateObj.entity_id }); + this.entityObj.closeCover(); }, onStopTap: function () { - this.hass.callService('cover', 'stop_cover', - { entity_id: this.stateObj.entity_id }); + this.entityObj.stopCover(); }, }); diff --git a/src/util/cover-model.html b/src/util/cover-model.html new file mode 100644 index 0000000000..7c039c9403 --- /dev/null +++ b/src/util/cover-model.html @@ -0,0 +1,113 @@ +