| @@ -30,11 +30,49 @@ class EntityState { | |||||||
|   static const problem = 'problem'; |   static const problem = 'problem'; | ||||||
| } | } | ||||||
|  |  | ||||||
| class EntityTapAction { | class EntityUIAction { | ||||||
|   static const moreInfo = 'more-info'; |   static const moreInfo = 'more-info'; | ||||||
|   static const toggle = 'toggle'; |   static const toggle = 'toggle'; | ||||||
|   static const callService = 'call-service'; |   static const callService = 'call-service'; | ||||||
|  |   static const navigate = 'navigate'; | ||||||
|   static const none = 'none'; |   static const none = 'none'; | ||||||
|  |  | ||||||
|  |   String tapAction = EntityUIAction.moreInfo; | ||||||
|  |   String tapNavigationPath; | ||||||
|  |   String tapService; | ||||||
|  |   Map<String, dynamic> tapServiceData; | ||||||
|  |   String holdAction = EntityUIAction.none; | ||||||
|  |   String holdNavigationPath; | ||||||
|  |   String holdService; | ||||||
|  |   Map<String, dynamic> holdServiceData; | ||||||
|  |  | ||||||
|  |   EntityUIAction({rawEntityData}) { | ||||||
|  |     if (rawEntityData != null) { | ||||||
|  |       if (rawEntityData["tap_action"] != null) { | ||||||
|  |         if (rawEntityData["tap_action"] is String) { | ||||||
|  |           tapAction = rawEntityData["tap_action"]; | ||||||
|  |         } else { | ||||||
|  |           tapAction = | ||||||
|  |               rawEntityData["tap_action"]["action"] ?? EntityUIAction.moreInfo; | ||||||
|  |           tapNavigationPath = rawEntityData["tap_action"]["navigation_path"]; | ||||||
|  |           tapService = rawEntityData["tap_action"]["service"]; | ||||||
|  |           tapServiceData = rawEntityData["tap_action"]["service_data"]; | ||||||
|  |         } | ||||||
|  |       } | ||||||
|  |       if (rawEntityData["hold_action"] != null) { | ||||||
|  |         if (rawEntityData["hold_action"] is String) { | ||||||
|  |           holdAction = rawEntityData["hold_action"]; | ||||||
|  |         } else { | ||||||
|  |           holdAction = | ||||||
|  |               rawEntityData["hold_action"]["action"] ?? EntityUIAction.none; | ||||||
|  |           holdNavigationPath = rawEntityData["hold_action"]["navigation_path"]; | ||||||
|  |           holdService = rawEntityData["hold_action"]["service"]; | ||||||
|  |           holdServiceData = rawEntityData["hold_action"]["service_data"]; | ||||||
|  |         } | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
| class CardType { | class CardType { | ||||||
|   | |||||||
| @@ -4,12 +4,7 @@ class EntityWrapper { | |||||||
|  |  | ||||||
|   String displayName; |   String displayName; | ||||||
|   String icon; |   String icon; | ||||||
|   String tapAction; |   EntityUIAction uiAction; | ||||||
|   String holdAction; |  | ||||||
|   String tapActionService; |  | ||||||
|   Map<String, dynamic> tapActionServiceData; |  | ||||||
|   String holdActionService; |  | ||||||
|   Map<String, dynamic> holdActionServiceData; |  | ||||||
|   Entity entity; |   Entity entity; | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -17,59 +12,65 @@ class EntityWrapper { | |||||||
|     this.entity, |     this.entity, | ||||||
|     String icon, |     String icon, | ||||||
|     String displayName, |     String displayName, | ||||||
|     this.tapAction: EntityTapAction.moreInfo, |     this.uiAction | ||||||
|     this.holdAction: EntityTapAction.none, |  | ||||||
|     this.tapActionService, |  | ||||||
|     this.tapActionServiceData, |  | ||||||
|     this.holdActionService, |  | ||||||
|     this.holdActionServiceData |  | ||||||
|   }) { |   }) { | ||||||
|     this.icon = icon ?? entity.icon; |     this.icon = icon ?? entity.icon; | ||||||
|     this.displayName = displayName ?? entity.displayName; |     this.displayName = displayName ?? entity.displayName; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   void handleTap() { |   void handleTap() { | ||||||
|     TheLogger.debug(tapAction); |     switch (uiAction.tapAction) { | ||||||
|     switch (tapAction) { |       case EntityUIAction.toggle: { | ||||||
|       case EntityTapAction.toggle: { |  | ||||||
|         eventBus.fire( |         eventBus.fire( | ||||||
|             ServiceCallEvent("homeassistant", "toggle", entity.entityId, null)); |             ServiceCallEvent("homeassistant", "toggle", entity.entityId, null)); | ||||||
|         break; |         break; | ||||||
|       } |       } | ||||||
|  |  | ||||||
|       case EntityTapAction.callService: { |       case EntityUIAction.callService: { | ||||||
|         eventBus.fire( |         if (uiAction.tapService != null) { | ||||||
|             ServiceCallEvent(tapActionService.split(".")[0], tapActionService.split(".")[1], null, tapActionServiceData)); |           eventBus.fire( | ||||||
|  |               ServiceCallEvent(uiAction.tapService.split(".")[0], | ||||||
|  |                   uiAction.tapService.split(".")[1], null, | ||||||
|  |                   uiAction.tapServiceData)); | ||||||
|  |         } | ||||||
|         break; |         break; | ||||||
|       } |       } | ||||||
|  |  | ||||||
|       case EntityTapAction.none: { |       case EntityUIAction.none: { | ||||||
|  |         break; | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       case EntityUIAction.moreInfo: { | ||||||
|  |         eventBus.fire( | ||||||
|  |             new ShowEntityPageEvent(entity)); | ||||||
|         break; |         break; | ||||||
|       } |       } | ||||||
|  |  | ||||||
|       default: { |       default: { | ||||||
|         eventBus.fire( |  | ||||||
|             new ShowEntityPageEvent(entity)); |  | ||||||
|         break; |         break; | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   void handleHold() { |   void handleHold() { | ||||||
|       switch (holdAction) { |       switch (uiAction.holdAction) { | ||||||
|         case EntityTapAction.toggle: { |         case EntityUIAction.toggle: { | ||||||
|           eventBus.fire( |           eventBus.fire( | ||||||
|               ServiceCallEvent("homeassistant", "toggle", entity.entityId, null)); |               ServiceCallEvent("homeassistant", "toggle", entity.entityId, null)); | ||||||
|           break; |           break; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         case EntityTapAction.callService: { |         case EntityUIAction.callService: { | ||||||
|           eventBus.fire( |           if (uiAction.holdService != null) { | ||||||
|               ServiceCallEvent(tapActionService.split(".")[0], tapActionService.split(".")[1], null, tapActionServiceData)); |             eventBus.fire( | ||||||
|  |                 ServiceCallEvent(uiAction.holdService.split(".")[0], | ||||||
|  |                     uiAction.holdService.split(".")[1], null, | ||||||
|  |                     uiAction.holdServiceData)); | ||||||
|  |           } | ||||||
|           break; |           break; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         case EntityTapAction.moreInfo: { |         case EntityUIAction.moreInfo: { | ||||||
|           eventBus.fire( |           eventBus.fire( | ||||||
|               new ShowEntityPageEvent(entity)); |               new ShowEntityPageEvent(entity)); | ||||||
|           break; |           break; | ||||||
|   | |||||||
| @@ -450,28 +450,12 @@ class HomeAssistant { | |||||||
|         } else { |         } else { | ||||||
|           if (entities.isExist(rawEntity["entity"])) { |           if (entities.isExist(rawEntity["entity"])) { | ||||||
|             Entity e = entities.get(rawEntity["entity"]); |             Entity e = entities.get(rawEntity["entity"]); | ||||||
|             String tapAction = EntityTapAction.moreInfo; |  | ||||||
|             String holdAction = EntityTapAction.none; |  | ||||||
|             if (card.type == CardType.glance || card.type == CardType.entityButton) { |  | ||||||
|               if (rawEntity["tap_action"] != null) { |  | ||||||
|                 if (rawEntity["tap_action"] is String) { |  | ||||||
|                   tapAction = rawEntity["tap_action"]; |  | ||||||
|                   holdAction = rawEntity["hold_action"]; |  | ||||||
|                 } else { |  | ||||||
|                   tapAction = rawEntity["tap_action"]["action"]; |  | ||||||
|                   holdAction = rawEntity["hold_action"]["action"]; |  | ||||||
|                 } |  | ||||||
|               } |  | ||||||
|             } |  | ||||||
|             card.entities.add( |             card.entities.add( | ||||||
|                 EntityWrapper( |                 EntityWrapper( | ||||||
|                     entity: e, |                     entity: e, | ||||||
|                     displayName: rawEntity["name"], |                     displayName: rawEntity["name"], | ||||||
|                     icon: rawEntity["icon"], |                     icon: rawEntity["icon"], | ||||||
|                     tapAction: tapAction, |                     uiAction: EntityUIAction(rawEntityData: rawEntity) | ||||||
|                     holdAction: holdAction, |  | ||||||
|                     //tapActionService: rawEntity["service"], |  | ||||||
|                     //tapActionServiceData: rawEntity["service_data"] ?? {"entity_id": e.entityId} |  | ||||||
|                 ) |                 ) | ||||||
|             ); |             ); | ||||||
|           } |           } | ||||||
| @@ -479,26 +463,12 @@ class HomeAssistant { | |||||||
|       }); |       }); | ||||||
|       if (rawCard["entity"] != null) { |       if (rawCard["entity"] != null) { | ||||||
|         var en = rawCard["entity"]; |         var en = rawCard["entity"]; | ||||||
|         String tapAction = EntityTapAction.moreInfo; |  | ||||||
|         String holdAction = EntityTapAction.none; |  | ||||||
|         if (rawCard["tap_action"] != null) { |  | ||||||
|           if (rawCard["tap_action"] is String) { |  | ||||||
|             tapAction = rawCard["tap_action"]; |  | ||||||
|             holdAction = rawCard["hold_action"]; |  | ||||||
|           } else { |  | ||||||
|             tapAction = rawCard["tap_action"]["action"]; |  | ||||||
|             holdAction = rawCard["hold_action"]["action"]; |  | ||||||
|           } |  | ||||||
|         } |  | ||||||
|         if (en is String) { |         if (en is String) { | ||||||
|           if (entities.isExist(en)) { |           if (entities.isExist(en)) { | ||||||
|             Entity e = entities.get(en); |             Entity e = entities.get(en); | ||||||
|             card.linkedEntityWrapper = EntityWrapper( |             card.linkedEntityWrapper = EntityWrapper( | ||||||
|                 entity: e, |                 entity: e, | ||||||
|                 tapAction: tapAction, |                 uiAction: EntityUIAction(rawEntityData: rawCard) | ||||||
|                 holdAction: holdAction, |  | ||||||
|                 //tapActionService: rawCard["service"], |  | ||||||
|                 //tapActionServiceData: rawCard["service_data"] ?? {"entity_id": e.entityId} |  | ||||||
|             ); |             ); | ||||||
|           } |           } | ||||||
|         } else { |         } else { | ||||||
| @@ -508,10 +478,7 @@ class HomeAssistant { | |||||||
|                 entity: e, |                 entity: e, | ||||||
|                 icon: en["icon"], |                 icon: en["icon"], | ||||||
|                 displayName: en["name"], |                 displayName: en["name"], | ||||||
|                 tapAction: tapAction, |                 uiAction: EntityUIAction(rawEntityData: rawCard) | ||||||
|                 holdAction: holdAction, |  | ||||||
|                 tapActionService: rawCard["service"], |  | ||||||
|                 tapActionServiceData: rawCard["service_data"] ?? {"entity_id": e.entityId} |  | ||||||
|             ); |             ); | ||||||
|           } |           } | ||||||
|         } |         } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user