* Changed vacuum state-card
* Stupid copy/paste error
* Added support for vacuum in lovelace
* Implement backwards compat.
* Remove lovelace changes
* Added new lovelace
* Updated lovelace code to reflect changes in entity
* Hopefully fix me being bad at git?
* even more fixes
* remove lovelace for now
* Fixed styling errors
* fix styling
* Fallback to toggle
* Fixed errors
* 🐫
* Updated ui
* fix lint error
* Added error to translation
* Added translations
* Removed a comma
* Added the last translations
* Support translation for actions
* Styling
* abcd, removed states from ui.card.vacuum, and moved actions to ui.card.vacuum.actions
* abcd and use this._interceptable
* Removed unused import
* _computeLabel(state, interceptable)
90 lines
2.2 KiB
JavaScript
90 lines
2.2 KiB
JavaScript
import '@polymer/paper-button/paper-button.js';
|
|
import { html } from '@polymer/polymer/lib/utils/html-tag.js';
|
|
import { PolymerElement } from '@polymer/polymer/polymer-element.js';
|
|
|
|
import LocalizeMixin from '../mixins/localize-mixin.js';
|
|
|
|
const STATES_INTERCEPTABLE = {
|
|
cleaning: {
|
|
action: 'return_to_base',
|
|
service: 'return_to_base'
|
|
},
|
|
docked: {
|
|
action: 'start_cleaning',
|
|
service: 'start_pause'
|
|
},
|
|
idle: {
|
|
action: 'start_cleaning',
|
|
service: 'start_pause'
|
|
},
|
|
off: {
|
|
action: 'turn_on',
|
|
service: 'turn_on'
|
|
},
|
|
on: {
|
|
action: 'turn_off',
|
|
service: 'turn_off'
|
|
},
|
|
paused: {
|
|
action: 'resume_cleaning',
|
|
service: 'start_pause'
|
|
},
|
|
};
|
|
|
|
/*
|
|
* @appliesMixin LocalizeMixin
|
|
*/
|
|
class HaVacuumState extends LocalizeMixin(PolymerElement) {
|
|
static get template() {
|
|
return html`
|
|
<style>
|
|
paper-button {
|
|
color: var(--primary-color);
|
|
font-weight: 500;
|
|
top: 3px;
|
|
height: 37px;
|
|
margin-right: -.57em;
|
|
}
|
|
paper-button[disabled] {
|
|
background-color: transparent;
|
|
color: var(--secondary-text-color);
|
|
}
|
|
</style>
|
|
|
|
<paper-button
|
|
on-click="_callService"
|
|
disabled="[[!_interceptable]]"
|
|
>[[_computeLabel(stateObj.state, _interceptable)]]</paper-button>
|
|
`;
|
|
}
|
|
|
|
static get properties() {
|
|
return {
|
|
hass: Object,
|
|
stateObj: Object,
|
|
_interceptable: {
|
|
type: Boolean,
|
|
computed: '_computeInterceptable(stateObj.state, stateObj.attributes.supported_features)'
|
|
}
|
|
};
|
|
}
|
|
|
|
_computeInterceptable(state, supportedFeatures) {
|
|
return state in STATES_INTERCEPTABLE && supportedFeatures !== 0;
|
|
}
|
|
|
|
_computeLabel(state, interceptable) {
|
|
return interceptable ?
|
|
this.localize(`ui.card.vacuum.actions.${STATES_INTERCEPTABLE[state].action}`)
|
|
: this.localize(`state.vacuum.${state}`);
|
|
}
|
|
|
|
_callService(ev) {
|
|
ev.stopPropagation();
|
|
const stateObj = this.stateObj;
|
|
const service = STATES_INTERCEPTABLE[stateObj.state].service;
|
|
this.hass.callService('vacuum', service, { entity_id: stateObj.entity_id });
|
|
}
|
|
}
|
|
customElements.define('ha-vacuum-state', HaVacuumState);
|