public CoxServiceResponse ChangeZone(string zone, string onOrOff) { var serviceResponse = new CoxServiceResponse(); if (!_loggedIn) { LogIn(); } var zoneEndpoint = GetZoneEndpoint(zone); var isBypassed = "false"; // true for bypassed, false for not bypassed if (onOrOff.ToLower() == "off") { isBypassed = "true"; } else { isBypassed = "false"; } var request = new RestRequest(zoneEndpoint, Method.POST); request.AddQueryParameter("value", isBypassed); request.AddHeader("X-format", "json"); request.AddHeader("X-ClientInfo", "7.3.4.90"); request.AddCookie("JSESSIONID", _jSessionId); IRestResponse httpResponse = _restClient.Execute(request); if (httpResponse.StatusCode == System.Net.HttpStatusCode.Accepted) { serviceResponse.AlexaSpokenResponse = $"Zone {zone} turned {onOrOff}"; serviceResponse.AlexaAppCardTitle = $"Zone {zone} changed"; serviceResponse.AlexaAppCardText = $"Zone {zone} successfully turned {onOrOff}"; } else { serviceResponse.AlexaSpokenResponse = $"Zone status failed to change"; serviceResponse.AlexaAppCardTitle = $"Failed to change zone {zone}"; serviceResponse.AlexaAppCardText = $"System failed to change {zone} {onOrOff}"; } return(serviceResponse); }
public CoxServiceResponse Disarm() { var serviceResponse = new CoxServiceResponse(); if (!_allowDisarm) { serviceResponse.AlexaSpokenResponse = "Sorry but I am not allowed to disarm the security system"; serviceResponse.AlexaAppCardTitle = "Not allowed to disarm"; serviceResponse.AlexaAppCardText = "Configuration doesn't allow disarming of the system"; return(serviceResponse); } if (!_loggedIn) { LogIn(); } var request = new RestRequest(_disarmEndpoint, Method.POST); request.AddParameter("code", _alarmCode); request.AddHeader("X-format", "json"); request.AddHeader("X-ClientInfo", "7.3.4.90"); request.AddCookie("JSESSIONID", _jSessionId); IRestResponse httpResponse = _restClient.Execute(request); if (httpResponse.StatusCode == System.Net.HttpStatusCode.Accepted) { serviceResponse.AlexaSpokenResponse = "System disarmed"; serviceResponse.AlexaAppCardTitle = "Disarmed"; serviceResponse.AlexaAppCardText = "System successfully disarmed"; } else { serviceResponse.AlexaSpokenResponse = $"System failed to arm"; serviceResponse.AlexaAppCardTitle = "Failed to disarm"; serviceResponse.AlexaAppCardText = "System failed to disarm"; } return(serviceResponse); }
public CoxServiceResponse Arm(ArmType armType) { var serviceResponse = new CoxServiceResponse(); if (!_loggedIn) { LogIn(); } var armTypeString = armType.ToString(); // 3 possible options are "night", "away", "stay" var request = new RestRequest(_armEndpoint, Method.POST); request.AddParameter("code", _alarmCode); request.AddParameter("armType", armTypeString); request.AddHeader("X-format", "json"); request.AddHeader("X-ClientInfo", "7.3.4.90"); request.AddCookie("JSESSIONID", _jSessionId); IRestResponse httpResponse = _restClient.Execute(request); if (httpResponse.StatusCode == System.Net.HttpStatusCode.Accepted) { serviceResponse.AlexaSpokenResponse = $"System arming {armTypeString}"; serviceResponse.AlexaAppCardTitle = $"Armed {armTypeString}"; serviceResponse.AlexaAppCardText = $"System successfully armed {armTypeString}"; } else { serviceResponse.AlexaSpokenResponse = $"System failed to arm"; serviceResponse.AlexaAppCardTitle = $"Failed to arm {armTypeString}"; serviceResponse.AlexaAppCardText = $"System failed to arm {armTypeString}"; } return(serviceResponse); }