2018-11-15 19:08:47 +02:00
|
|
|
part of '../main.dart';
|
|
|
|
|
|
|
|
class EntityWrapper {
|
|
|
|
|
|
|
|
String displayName;
|
|
|
|
String icon;
|
2018-12-14 14:28:23 +02:00
|
|
|
EntityUIAction uiAction;
|
2018-11-15 19:08:47 +02:00
|
|
|
Entity entity;
|
|
|
|
|
2018-11-16 22:32:43 +02:00
|
|
|
|
|
|
|
EntityWrapper({
|
|
|
|
this.entity,
|
|
|
|
String icon,
|
|
|
|
String displayName,
|
2018-12-14 14:28:23 +02:00
|
|
|
this.uiAction
|
2018-11-16 22:32:43 +02:00
|
|
|
}) {
|
2018-11-15 19:08:47 +02:00
|
|
|
this.icon = icon ?? entity.icon;
|
|
|
|
this.displayName = displayName ?? entity.displayName;
|
|
|
|
}
|
|
|
|
|
2018-11-23 15:06:42 +02:00
|
|
|
void handleTap() {
|
2018-12-14 14:28:23 +02:00
|
|
|
switch (uiAction.tapAction) {
|
|
|
|
case EntityUIAction.toggle: {
|
2018-11-23 15:06:42 +02:00
|
|
|
eventBus.fire(
|
|
|
|
ServiceCallEvent("homeassistant", "toggle", entity.entityId, null));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-12-14 14:28:23 +02:00
|
|
|
case EntityUIAction.callService: {
|
|
|
|
if (uiAction.tapService != null) {
|
|
|
|
eventBus.fire(
|
|
|
|
ServiceCallEvent(uiAction.tapService.split(".")[0],
|
|
|
|
uiAction.tapService.split(".")[1], null,
|
|
|
|
uiAction.tapServiceData));
|
|
|
|
}
|
2018-11-23 15:06:42 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-12-14 14:28:23 +02:00
|
|
|
case EntityUIAction.none: {
|
2018-11-23 15:06:42 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-12-14 14:28:23 +02:00
|
|
|
case EntityUIAction.moreInfo: {
|
2018-11-23 15:06:42 +02:00
|
|
|
eventBus.fire(
|
|
|
|
new ShowEntityPageEvent(entity));
|
|
|
|
break;
|
|
|
|
}
|
2018-12-14 14:28:23 +02:00
|
|
|
|
|
|
|
default: {
|
|
|
|
break;
|
|
|
|
}
|
2018-11-23 15:06:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void handleHold() {
|
2018-12-14 14:28:23 +02:00
|
|
|
switch (uiAction.holdAction) {
|
|
|
|
case EntityUIAction.toggle: {
|
2018-11-23 15:06:42 +02:00
|
|
|
eventBus.fire(
|
|
|
|
ServiceCallEvent("homeassistant", "toggle", entity.entityId, null));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-12-14 14:28:23 +02:00
|
|
|
case EntityUIAction.callService: {
|
|
|
|
if (uiAction.holdService != null) {
|
|
|
|
eventBus.fire(
|
|
|
|
ServiceCallEvent(uiAction.holdService.split(".")[0],
|
|
|
|
uiAction.holdService.split(".")[1], null,
|
|
|
|
uiAction.holdServiceData));
|
|
|
|
}
|
2018-11-23 15:06:42 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-12-14 14:28:23 +02:00
|
|
|
case EntityUIAction.moreInfo: {
|
2018-11-23 15:06:42 +02:00
|
|
|
eventBus.fire(
|
|
|
|
new ShowEntityPageEvent(entity));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default: {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-15 19:08:47 +02:00
|
|
|
}
|