HueLibrary.Bridge.GetLightAsync C# (CSharp) Method

GetLightAsync() public method

Gets a light with the given id known to the bridge, or null if no light is found.
public GetLightAsync ( string id ) : Task
id string
return Task
        public async Task<Light> GetLightAsync(string id)
        {
            HttpResponseMessage response = await HttpGetAsync($"lights/{id}");
            Light light = JsonConvert.DeserializeObject<Light>(await response.Content.ReadAsStringAsync());
            if (null != light)
            {
                light.Id = id;
                light._bridge = this;
                light.State._light = light;
            }
            return light;
        }

Usage Example

コード例 #1
0
ファイル: Light.cs プロジェクト: sven-borden/SmartMirror
        /// <summary>
        /// Attempts to refresh this object to match the current state of its physical light.
        /// </summary>
        public async Task SyncAsync()
        {
            Light copy = await _bridge.GetLightAsync(Id);

            if (null != copy)
            {
                State = copy.State;
            }
        }