private bool setTpLinkState(RpmSmartPlugState plugState)
        {
            try
            {
                var tp = new TPLink_SmartPlug.HS1XX(System.Net.IPAddress.Parse(IpAddress), 10000, 0, 0);
                switch (plugState)
                {
                case RpmSmartPlugState.off:
                    var rOff = tp.SwitchRelayState(TPLink_SmartPlug.RelayAction.TurnOff);
                    return(rOff.ErrorCode == 0);

                case RpmSmartPlugState.on:
                    var rOn = tp.SwitchRelayState(TPLink_SmartPlug.RelayAction.TurnOn);
                    return(rOn.ErrorCode == 0);

                case RpmSmartPlugState.unknown:
                default:
                    return(false);
                }
            }
            catch (Exception ex)
            {
                throw new RpmSmartPlugCommunicationException($"Could not set the state of plug. Message: {ex.Message}", RpmSmartPlugs.TPLinkHS110, IpAddress, ex);
            }
        }
 private RpmSmartPlugState getTpLinkState()
 {
     try
     {
         var tp       = new TPLink_SmartPlug.HS1XX(System.Net.IPAddress.Parse(IpAddress), 10000, 0, 0);
         var dev_info = tp.GetDeviceInfo();
         return(dev_info != null ? dev_info.RelayState == (byte)0 ? RpmSmartPlugState.off : RpmSmartPlugState.on : RpmSmartPlugState.unknown);
     }
     catch (Exception ex)
     {
         throw new RpmSmartPlugCommunicationException($"Could not get state from plug. Message: {ex.Message}", RpmSmartPlugs.TPLinkHS110, IpAddress, ex);
     }
 }
 private double getTpLinkCurrentPowerConsumption()
 {
     try
     {
         var tp = new TPLink_SmartPlug.HS1XX(System.Net.IPAddress.Parse(IpAddress), 10000, 0, 0);
         var e  = tp.GetEmeterRealtime();
         return(e != null ? e.Power : 0);
     }
     catch (Exception ex)
     {
         throw new RpmSmartPlugCommunicationException($"Could not get current power consumption from plug. Message: {ex.Message}", RpmSmartPlugs.TPLinkHS110, IpAddress, ex);
     }
 }
 private string getTpLinkAlias()
 {
     try
     {
         var tp       = new TPLink_SmartPlug.HS1XX(System.Net.IPAddress.Parse(IpAddress), 10000, 0, 0);
         var dev_info = tp.GetDeviceInfo();
         return(dev_info?.Alias);
     }
     catch (Exception ex)
     {
         throw new RpmSmartPlugCommunicationException($"Could not get name from plug. Message: {ex.Message}", RpmSmartPlugs.TPLinkHS110, IpAddress, ex);
     }
 }