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); } }
public bool SetPlugState(RpmSmartPlugState plugState) { try { switch (PlugType) { case RpmSmartPlugs.WeMoInsightSwitch: default: return(setWemoState(plugState)); case RpmSmartPlugs.TPLinkHS110: return(setTpLinkState(plugState)); } } catch (RpmSmartPlugCommunicationException) { throw; } catch (Exception ex) { throw new RpmApiException("Setting plug state failed in SmartPlugHandler", "SetPlugState", RpmExceptionType.Exception, ex); } }
private bool setWemoState(RpmSmartPlugState plugState) { try { var ApiAddress = $"http://{IpAddress}"; var v = new WemoNet.Wemo(); switch (plugState) { case RpmSmartPlugState.off: return(v.TurnOffWemoPlugAsync(ApiAddress).GetAwaiter().GetResult()); case RpmSmartPlugState.on: return(v.TurnOnWemoPlugAsync(ApiAddress).GetAwaiter().GetResult()); case RpmSmartPlugState.unknown: default: return(false); } } catch (Exception ex) { throw new RpmSmartPlugCommunicationException($"Could not set the state of plug. Message: {ex.Message}", RpmSmartPlugs.WeMoInsightSwitch, IpAddress, ex); } }