Exemplo n.º 1
0
        protected async Task <ShellyResult <T> > ExecuteAsync(IRestRequest restRequest, Method method, CancellationToken cancellationToken)
        {
            var client   = GetRestClient();
            var response = await client.ExecuteAsync(restRequest, method, cancellationToken);

            if (response.StatusCode == 0)
            {
                // RestSharp will return with a status code of 0 if timeout is reached
                return(ShellyResult <T> .Failure(true, "Device did not respond within timeout period"));
            }
            if (response.StatusCode == HttpStatusCode.ServiceUnavailable)
            {
                return(ShellyResult <T> .Failure(true, "Device responded with ServiceUnavailable"));
            }
            if (response.StatusCode == HttpStatusCode.NotFound)
            {
                return(ShellyResult <T> .Success(default, "Device responded with NotFound"));
Exemplo n.º 2
0
        protected override ShellyResult <Shelly1PmStatusDto> HandleOkResponse(IRestResponse response)
        {
            var shelly1Status = JsonConvert.DeserializeObject <Shelly1PmStatusDto>(response.Content);

            return(ShellyResult <Shelly1PmStatusDto> .Success(shelly1Status));
        }