mirror of
https://github.com/home-assistant/frontend.git
synced 2025-12-20 10:48:44 +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
54 lines
1.2 KiB
JavaScript
54 lines
1.2 KiB
JavaScript
import { h, Component } from 'preact';
|
|
|
|
import TriggerRow from './trigger_row.js';
|
|
import StateTrigger from './state.js';
|
|
|
|
export default class Trigger extends Component {
|
|
constructor() {
|
|
super();
|
|
|
|
this.addTrigger = this.addTrigger.bind(this);
|
|
this.triggerChanged = this.triggerChanged.bind(this);
|
|
}
|
|
|
|
addTrigger() {
|
|
const trigger = this.props.trigger.concat({
|
|
platform: 'state',
|
|
...StateTrigger.defaultConfig,
|
|
});
|
|
|
|
this.props.onChange(trigger);
|
|
}
|
|
|
|
triggerChanged(index, newValue) {
|
|
const trigger = this.props.trigger.concat();
|
|
|
|
if (newValue === null) {
|
|
trigger.splice(index, 1);
|
|
} else {
|
|
trigger[index] = newValue;
|
|
}
|
|
|
|
this.props.onChange(trigger);
|
|
}
|
|
|
|
render({ trigger, hass }) {
|
|
return (
|
|
<div class="triggers">
|
|
{trigger.map((trg, idx) => (
|
|
<TriggerRow
|
|
index={idx}
|
|
trigger={trg}
|
|
onChange={this.triggerChanged}
|
|
hass={hass}
|
|
/>))}
|
|
<paper-card>
|
|
<div class='card-actions add-card'>
|
|
<paper-button onTap={this.addTrigger}>Add trigger</paper-button>
|
|
</div>
|
|
</paper-card>
|
|
</div>
|
|
);
|
|
}
|
|
}
|