public async Task <SubscriptionOnStateValue> Subscribe(string sentinelHost, string packageHost, string stateValueName)
        {
            using (var client = new HomeConnectionClient(HomeHubConnection))
            {
                var stateValueKey = new StateValueKey(sentinelHost, packageHost, stateValueName);
                await SubscribeOnValueChanged(stateValueKey);

                var subscriptionKeyValue = await client.PostAsJson <string>("subscription",
                                                                            new Subscription(SentinelHost.GetName(), sentinelHost, packageHost, stateValueName));

                if (!string.IsNullOrEmpty(subscriptionKeyValue))
                {
                    var subscriptionKey = new SubscriptionKey(subscriptionKeyValue);
                    if (subscriptionKey.IsValid())
                    {
                        var subscriptionOnStateValue = new SubscriptionOnStateValue(subscriptionKey, stateValueKey);
                        AddSubscriptionInStore(stateValueKey, subscriptionOnStateValue);

                        return(subscriptionOnStateValue);
                    }
                }
                else
                {
                    await UnSubscribeOnValueChanged(new StateValueKey(sentinelHost, packageHost, stateValueName));
                }
            }

            return(null);
        }
 private void AddSubscriptionInStore(StateValueKey stateValueKey, SubscriptionOnStateValue subscriptionOnStateValue)
 {
     if (_subscriptionsStore.ContainsKey(stateValueKey))
     {
         _subscriptionsStore[stateValueKey] = subscriptionOnStateValue;
     }
     else
     {
         _subscriptionsStore.Add(stateValueKey, subscriptionOnStateValue);
     }
 }