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`
[[_computeLabel(stateObj.state, _interceptable)]]
`;
}
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);