mirror of
https://github.com/home-assistant/frontend.git
synced 2025-12-20 02:38:53 +00:00
* Ignore hass changes while dropdown is open * Upgrade vaadin-combo-box * Fix styling on dev-service panel * Fix styling for ha-entity-dropdown * Fix height vaadin-combo-box dropdown * Rename ha-entity-dropdown to ha-entity-picker * More entity improvement (#675) * Update script and automation editor to use entity picker * Add entity and service picker to service dev panel * Lint
73 lines
1.8 KiB
JavaScript
73 lines
1.8 KiB
JavaScript
import { h, Component } from 'preact';
|
|
|
|
import NumericStateCondition from './numeric_state.js';
|
|
import StateCondition from './state.js';
|
|
import SunCondition from './sun.js';
|
|
import TemplateCondition from './template.js';
|
|
import TimeCondition from './time.js';
|
|
import ZoneCondition from './zone.js';
|
|
|
|
const TYPES = {
|
|
state: StateCondition,
|
|
numeric_state: NumericStateCondition,
|
|
sun: SunCondition,
|
|
template: TemplateCondition,
|
|
time: TimeCondition,
|
|
zone: ZoneCondition,
|
|
};
|
|
|
|
const OPTIONS = Object.keys(TYPES).sort();
|
|
|
|
export default class ConditionRow extends Component {
|
|
constructor() {
|
|
super();
|
|
|
|
this.typeChanged = this.typeChanged.bind(this);
|
|
}
|
|
|
|
typeChanged(ev) {
|
|
const type = ev.target.selectedItem.innerHTML;
|
|
|
|
if (type !== this.props.condition.condition) {
|
|
this.props.onChange(this.props.index, {
|
|
condition: type,
|
|
...TYPES[type].defaultConfig
|
|
});
|
|
}
|
|
}
|
|
|
|
render({ index, condition, onChange, hass }) {
|
|
const Comp = TYPES[condition.condition];
|
|
const selected = OPTIONS.indexOf(condition.condition);
|
|
|
|
if (!Comp) {
|
|
return (
|
|
<div>
|
|
Unsupported condition: {condition.condition}
|
|
<pre>{JSON.stringify(condition, null, 2)}</pre>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<div>
|
|
<paper-dropdown-menu-light label="Condition Type" no-animations>
|
|
<paper-listbox
|
|
slot="dropdown-content"
|
|
selected={selected}
|
|
oniron-select={this.typeChanged}
|
|
>
|
|
{OPTIONS.map(opt => <paper-item>{opt}</paper-item>)}
|
|
</paper-listbox>
|
|
</paper-dropdown-menu-light>
|
|
<Comp
|
|
index={index}
|
|
condition={condition}
|
|
onChange={onChange}
|
|
hass={hass}
|
|
/>
|
|
</div>
|
|
);
|
|
}
|
|
}
|