Handle entity taps and holds in one place

This commit is contained in:
Yegor Vialov
2018-11-23 15:06:42 +02:00
parent 67fbdb13c6
commit a0235ee385
7 changed files with 72 additions and 111 deletions

View File

@ -22,44 +22,12 @@ class EntityIcon extends StatelessWidget {
),
onLongPress: () {
if (entityModel.handleTap) {
switch (entityModel.entityWrapper.holdAction) {
case EntityTapAction.toggle: {
eventBus.fire(
ServiceCallEvent("homeassistant", "toggle", entityModel.entityWrapper.entity.entityId, null));
break;
}
default: {
eventBus.fire(
new ShowEntityPageEvent(entityModel.entityWrapper.entity));
break;
}
}
entityModel.entityWrapper.handleHold();
}
},
onTap: () {
if (entityModel.handleTap) {
switch (entityModel.entityWrapper.tapAction) {
case EntityTapAction.toggle: {
eventBus.fire(
ServiceCallEvent("homeassistant", "toggle", entityModel.entityWrapper.entity.entityId, null));
break;
}
case EntityTapAction.callService: {
eventBus.fire(
ServiceCallEvent(entityModel.entityWrapper.actionService.split(".")[0], entityModel.entityWrapper.actionService.split(".")[1], null, entityModel.entityWrapper.actionServiceData));
break;
}
default: {
eventBus.fire(
new ShowEntityPageEvent(entityModel.entityWrapper.entity));
break;
}
}
entityModel.entityWrapper.handleTap();
}
}