Exemple #1
0
 public PanelTouchHandler(string serviceAction, ResponseExpected responseExpected)
 {
     ServiceActionForSupportedFeatureMap = new Dictionary <uint, string>()
     {
         { 0, serviceAction }
     };
     Response = responseExpected;
 }
Exemple #2
0
 /// <summary>
 /// Returns panel opacity back to its current state.
 /// </summary>
 /// <param name="panel"></param>
 /// <param name="responseExpected"></param>
 private void MarkPanelStatePerExpectedResponse(Panel panel, ResponseExpected responseExpected)
 {
     if (responseExpected == ResponseExpected.EntityUpdated)
     {
         MarkPanelAsUpdateRequired(panel);
     }
     else
     {
         MarkPanelAsDefaultState(panel);
     }
 }
Exemple #3
0
        /// <summary>
        /// Send data request to Home Assistant with no JSON body in the request.
        /// </summary>
        /// <param name="panel"></param>
        /// <param name="panelData"></param>
        private void SendPanelDataSimple(Panel panel, PanelData panelData, ResponseExpected responseExpected)
        {
            MarkPanelStatePerExpectedResponse(panel, responseExpected);

            if (panelData.ChildrenEntities != null)
            {
                throw new NotImplementedException();
            }
            else
            {
                WebRequests.SendActionNoData(panelData.Entity.EntityId);
            }
        }
Exemple #4
0
 public PanelTouchHandler(Dictionary <uint, string> serviceAction, ResponseExpected responseExpected)
 {
     ServiceActionForSupportedFeatureMap = serviceAction;
     Response = responseExpected;
 }
Exemple #5
0
        /// <summary>
        /// Send data request to Home Assistant to the requested service.
        /// </summary>
        /// <param name="panel"></param>
        /// <param name="panelData"></param>
        private void SendPanelDataWithJson(Panel panel, PanelData panelData, string serviceToInvoke, ResponseExpected responseExpected)
        {
            MarkPanelStatePerExpectedResponse(panel, responseExpected);

            if (panelData.ChildrenEntities != null)
            {
                WebRequests.SendAction(serviceToInvoke, panelData.ChildrenEntities.Select(x => x.EntityId));

                Panel parentPanel       = (Panel)VisualTreeHelper.GetParent(panel);
                int   indexOfGroupPanel = parentPanel.Children.IndexOf(panel);

                for (int i = indexOfGroupPanel + 1; i < indexOfGroupPanel + 1 + panelData.ChildrenEntities.Count(); i++)
                {
                    MarkPanelStatePerExpectedResponse(panel, responseExpected);
                }
            }
            else
            {
                WebRequests.SendAction(panelData.Entity.EntityId, serviceToInvoke);
            }
        }
Exemple #6
0
        /// <summary>
        /// Panel interaction handler. Sends a web request to home assistant or opens the popup control.
        /// Changes visual state of the panel to match.
        /// </summary>
        /// <param name="panel"></param>
        /// <param name="panelData"></param>
        /// <param name="serviceToInvoke"></param>
        /// <param name="responseExpected"></param>
        private void HandleTouchEvent(Panel panel, PanelData panelData, string serviceToInvoke, ResponseExpected responseExpected)
        {
            if (string.IsNullOrEmpty(serviceToInvoke))
            {
                // This is a simple web request which has no associated JSON payload
                SendPanelDataSimple(panel, panelData, responseExpected);
            }
            else
            {
                // Reroute tap actions to launch a custom control panel when the requested name matches a named Popup control
                if (popupUserControlList.Any(x => string.Equals(x, serviceToInvoke, StringComparison.InvariantCultureIgnoreCase)))
                {
                    ShowPopupControl(serviceToInvoke, panelData.Entity, panelData.ChildrenEntities);

                    MarkPanelAsDefaultState(panel);
                }
                else
                {
                    SendPanelDataWithJson(panel, panelData, serviceToInvoke, responseExpected);
                }
            }
        }