2018-11-15 19:08:47 +02:00
|
|
|
part of '../main.dart';
|
|
|
|
|
|
|
|
class EntityWrapper {
|
|
|
|
|
2020-03-15 18:28:45 +02:00
|
|
|
String overrideName;
|
|
|
|
final String overrideIcon;
|
2018-12-14 14:28:23 +02:00
|
|
|
EntityUIAction uiAction;
|
2018-11-15 19:08:47 +02:00
|
|
|
Entity entity;
|
2020-03-15 18:28:45 +02:00
|
|
|
String unitOfMeasurementOverride;
|
|
|
|
final List stateFilter;
|
2018-11-15 19:08:47 +02:00
|
|
|
|
2020-03-15 18:28:45 +02:00
|
|
|
String get icon => overrideIcon ?? entity.icon;
|
|
|
|
String get entityPicture => entity.entityPicture;
|
|
|
|
String get displayName => overrideName ?? entity.displayName;
|
|
|
|
String get unitOfMeasurement => unitOfMeasurementOverride ?? entity.unitOfMeasurement;
|
2018-11-16 22:32:43 +02:00
|
|
|
|
|
|
|
EntityWrapper({
|
|
|
|
this.entity,
|
2020-03-15 18:28:45 +02:00
|
|
|
this.overrideIcon,
|
|
|
|
this.overrideName,
|
2020-03-12 23:16:07 +02:00
|
|
|
this.uiAction,
|
|
|
|
this.stateFilter
|
2018-11-16 22:32:43 +02:00
|
|
|
}) {
|
2019-03-13 00:56:57 +02:00
|
|
|
if (entity.statelessType == StatelessEntityType.NONE || entity.statelessType == StatelessEntityType.CALL_SERVICE || entity.statelessType == StatelessEntityType.WEBLINK) {
|
2019-03-12 23:35:33 +02:00
|
|
|
if (uiAction == null) {
|
|
|
|
uiAction = EntityUIAction();
|
|
|
|
}
|
2018-12-14 16:31:41 +02:00
|
|
|
}
|
2018-11-15 19:08:47 +02:00
|
|
|
}
|
|
|
|
|
2018-11-23 15:06:42 +02:00
|
|
|
void handleTap() {
|
2018-12-14 14:28:23 +02:00
|
|
|
switch (uiAction.tapAction) {
|
|
|
|
case EntityUIAction.toggle: {
|
2019-11-08 21:37:41 +02:00
|
|
|
ConnectionManager().callService(domain: "homeassistant", service: "toggle", entityId: entity.entityId);
|
2018-11-23 15:06:42 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-12-14 14:28:23 +02:00
|
|
|
case EntityUIAction.callService: {
|
|
|
|
if (uiAction.tapService != null) {
|
2019-11-08 21:37:41 +02:00
|
|
|
ConnectionManager().callService(
|
|
|
|
domain: uiAction.tapService.split(".")[0],
|
|
|
|
service: uiAction.tapService.split(".")[1],
|
|
|
|
data: uiAction.tapServiceData
|
|
|
|
);
|
2018-12-14 14:28:23 +02:00
|
|
|
}
|
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(
|
2019-09-14 18:32:44 +03:00
|
|
|
new ShowEntityPageEvent(entity: entity));
|
2018-11-23 15:06:42 +02:00
|
|
|
break;
|
|
|
|
}
|
2018-12-14 14:28:23 +02:00
|
|
|
|
2019-03-13 00:56:57 +02:00
|
|
|
case EntityUIAction.navigate: {
|
2019-11-29 14:45:59 +02:00
|
|
|
if (uiAction.tapService != null && uiAction.tapService.startsWith("/")) {
|
2019-03-13 00:56:57 +02:00
|
|
|
//TODO handle local urls
|
|
|
|
Logger.w("Local urls is not supported yet");
|
|
|
|
} else {
|
2019-09-02 21:08:20 +03:00
|
|
|
Launcher.launchURL(uiAction.tapService);
|
2019-03-13 00:56:57 +02:00
|
|
|
}
|
|
|
|
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: {
|
2019-11-08 21:37:41 +02:00
|
|
|
ConnectionManager().callService(domain: "homeassistant", service: "toggle", entityId: entity.entityId);
|
2018-11-23 15:06:42 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-12-14 14:28:23 +02:00
|
|
|
case EntityUIAction.callService: {
|
|
|
|
if (uiAction.holdService != null) {
|
2019-11-08 21:37:41 +02:00
|
|
|
ConnectionManager().callService(
|
|
|
|
domain: uiAction.holdService.split(".")[0],
|
|
|
|
service: uiAction.holdService.split(".")[1],
|
|
|
|
data: uiAction.holdServiceData
|
|
|
|
);
|
2018-12-14 14:28:23 +02:00
|
|
|
}
|
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(
|
2019-09-14 18:32:44 +03:00
|
|
|
new ShowEntityPageEvent(entity: entity));
|
2018-11-23 15:06:42 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-03-13 00:56:57 +02:00
|
|
|
case EntityUIAction.navigate: {
|
2019-11-29 14:45:59 +02:00
|
|
|
if (uiAction.holdService != null && uiAction.holdService.startsWith("/")) {
|
2019-03-13 00:56:57 +02:00
|
|
|
//TODO handle local urls
|
|
|
|
Logger.w("Local urls is not supported yet");
|
|
|
|
} else {
|
2019-09-02 21:08:20 +03:00
|
|
|
Launcher.launchURL(uiAction.holdService);
|
2019-03-13 00:56:57 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-11-23 15:06:42 +02:00
|
|
|
default: {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-14 20:12:11 +02:00
|
|
|
void handleDoubleTap() {
|
|
|
|
switch (uiAction.doubleTapAction) {
|
|
|
|
case EntityUIAction.toggle: {
|
|
|
|
ConnectionManager().callService(domain: "homeassistant", service: "toggle", entityId: entity.entityId);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case EntityUIAction.callService: {
|
|
|
|
if (uiAction.doubleTapService != null) {
|
|
|
|
ConnectionManager().callService(
|
|
|
|
domain: uiAction.doubleTapService.split(".")[0],
|
|
|
|
service: uiAction.doubleTapService.split(".")[1],
|
|
|
|
data: uiAction.doubleTapServiceData
|
|
|
|
);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case EntityUIAction.moreInfo: {
|
|
|
|
eventBus.fire(
|
|
|
|
new ShowEntityPageEvent(entity: entity));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case EntityUIAction.navigate: {
|
|
|
|
if (uiAction.doubleTapService != null && uiAction.doubleTapService.startsWith("/")) {
|
|
|
|
//TODO handle local urls
|
|
|
|
Logger.w("Local urls is not supported yet");
|
|
|
|
} else {
|
|
|
|
Launcher.launchURL(uiAction.doubleTapService);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default: {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-15 19:08:47 +02:00
|
|
|
}
|