Esempio n. 1
0
        /// <summary>
        /// Refresh the device details for a Sesame.
        /// </summary>
        /// <param name="sesame">The sesame to refresh.</param>
        /// <returns>A task that indicates when the refresh operation is complete.</returns>
        public async Task RefreshSesameAsync(Sesame sesame)
        {
            string syncTaskId = await this.ControlSesameAsync(sesame, ControlOperation.Sync);

            await this.WaitForOperationAsync(syncTaskId);

            Sesame updated = await this.GetSesameStateAsync(sesame.DeviceId);

            sesame.IsLocked     = updated.IsLocked;
            sesame.Battery      = updated.Battery;
            sesame.IsResponsive = updated.IsResponsive;
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the current state information for a Sesame.
        /// </summary>
        /// <remarks>
        /// This method only returns the state for the Sesame.  The get detailed device information such as nickname
        /// and Sesame model you must use <see cref="ListSesamesAsync"/> then use <see cref="RefreshSesameAsync"/>
        /// to populate the device state.</remarks>
        /// <param name="deviceId">The device ID of the Sesame to get details for.</param>
        /// <returns>The state information for the Sesame with the given device ID.</returns>
        public async Task <Sesame> GetSesameStateAsync(string deviceId)
        {
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, $"{ApiVersion}/sesame/{deviceId}");

            using (HttpResponseMessage response = await this.SendAsync(request))
            {
                await this.EnsureSuccessStatusCodeAsync(response);

                Sesame sesame = await response.Content.ReadAsJsonAsync <Sesame>();

                sesame.Client = this;
                // Currently DeviceId is not returned by this call so we need to manually set it if we want to use it.
                sesame.DeviceId = deviceId;
                return(sesame);
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Send a control request to a Sesame to execute an operation.
 /// </summary>
 /// <param name="sesame">The Sesame to control.</param>
 /// <param name="operation">The operation to execute.</param>
 /// <returns>A task that indicates when the control operation is complete.</returns>
 public async Task <string> ControlSesameAsync(Sesame sesame, ControlOperation operation)
 {
     return(await this.ControlSesameAsync(sesame.DeviceId, operation.ToString().ToLower()));
 }