public void RunStorage(JobSettings.Job job, Bootstrap bootstrap)
        {
            var totStorage       = Math.Round(bootstrap.nvr.storageInfo.totalSize / 1e+9, 1);
            var usedStorage      = Math.Round(bootstrap.nvr.storageInfo.totalSpaceUsed / 1e+9, 1);
            var currentSpaceUsed = Math.Round(((usedStorage * 100) / totStorage), 1);

            PostChangedValue(job, currentSpaceUsed);
        }
 public void RunState(JobSettings.Job job, Bootstrap bootstrap)
 {
     if (!bootstrap.TryGetCamera(job.Id, out var camera))
     {
         Log.Write($"Camera {job.Id} not found.");
         return;
     }
     PostChangedValue(job, camera.state);
 }
 public void RunUptime(JobSettings.Job job, Bootstrap bootstrap)
 {
     if (!bootstrap.TryGetCamera(job.Id, out var camera))
     {
         Log.Write($"Camera {job.Id} not found.");
         return;
     }
     PostChangedValue(job, camera.upSince.FromUnixTime());
 }
        private bool PostChangedValue(JobSettings.Job job, string value)
        {
            if (value == job.LastValue)
            {
                return(false);
            }
            var response = PostOpenHabApi(job.Item, value);

            if (!response.IsSuccessStatusCode)
            {
                var error = response.ParseResponseJson <OpenHabError>();
                Log.Write($"Update to {job.Item} failed. {error.Error.Message}");
                return(false);
            }
            job.LastRun   = DateTime.Now;
            job.LastValue = value;
            Log.Write($"{job.Item} updated to {value}.");
            return(true);
        }
 private bool PostChangedValue(JobSettings.Job job, long value)
 {
     return(PostChangedValue(job, value.ToString()));
 }
        // public void RunSnap(JobSettings.Job job, Bootstrap data)
        // {
        //     // Yeah, I'm stuck here.
        //     var url = $"{config["unifiApiUrl"]}/cameras/{job.Id}/snapshot?accessKey={data.accessKey}";
        //     var req = new HttpRequestMessage(HttpMethod.Post, url);
        //     var response = CallUniFiApi(req);

        //     if (response == null || !response.IsSuccessStatusCode)
        //     {
        //         Log.Write(
        //             (response != null)
        //             ? $"Camera Snapshot failed. {response?.ReasonPhrase} ({response?.StatusCode})"
        //             : "Camera Snapshot failed."
        //             );
        //     }
        //     var responseData = response.Content.ReadAsByteArrayAsync();

        // }

        private bool PostChangedValue(JobSettings.Job job, DateTime value)
        {
            return(PostChangedValue(job, value.ToOpenHabTimeString()));
        }