This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var command = new LightCommand { Brightness = 120 }; | |
await client.SendCommandAsync(command); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var command = new LightCommand { On = false }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private async void Button_Clicked(object sender, EventArgs e) | |
{ | |
var bridgeIP = "XXX.XXX.XX.XX"; | |
var appKey = "abcdefghijklmnopqrstuvwxyz1234567890"; | |
ILocalHueClient client = new LocalHueClient(bridgeIP); | |
client.Initialize(appKey); | |
var command = new LightCommand { Brightness = 120 }; | |
await client.SendCommandAsync(command); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private readonly string access_key = "XXXXXXXXXXXXXXXXXXXXX"; | |
private readonly string secret_token = "XXXXXXXXXXXXXXXXXXXXX"; | |
private readonly HttpClient httpClient = new HttpClient(); | |
private readonly StringContent stringData = new StringContent(string.Empty); | |
public MillheatClient() | |
{ | |
httpClient.BaseAddress = new Uri("https://api.millheat.com/"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task<string> GetAuthorizationCode() | |
{ | |
httpClient.DefaultRequestHeaders.Add("access_key", access_key); | |
httpClient.DefaultRequestHeaders.Add("secret_token", secret_token); | |
var response = await httpClient.PostAsync("share/applyAuthCode", stringData); | |
var result = await response.Content.ReadAsStringAsync(); | |
var jsonResult = JsonSerializer.Deserialize<ApplyAuthCodeResponse>(result); | |
return jsonResult.Data.AuthorizationCode; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task<string> GetAccessToken(string authCode) | |
{ | |
httpClient.DefaultRequestHeaders.Remove("access_key"); | |
httpClient.DefaultRequestHeaders.Remove("secret_token"); | |
httpClient.DefaultRequestHeaders.Add("authorization_code", authCode); | |
var requestUrl = $"share/applyAccessToken?password={Constants.Password}&username={Constants.Username}"; | |
var response = await httpClient.PostAsync(requestUrl, stringData); | |
var result = await response.Content.ReadAsStringAsync(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task<Home> GetHome(string accessToken) | |
{ | |
httpClient.DefaultRequestHeaders.Remove("authorization_code"); | |
httpClient.DefaultRequestHeaders.Add("access_token", accessToken); | |
var requestUrl = $"uds/selectHomeList"; | |
var response = await httpClient.PostAsync(requestUrl, stringData); | |
var result = await response.Content.ReadAsStringAsync(); | |
var jsonResult = JsonSerializer.Deserialize<SelectHomeListResponse>(result); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task<Room> GetRoom(Home home) | |
{ | |
var requestUrl = $"uds/selectRoombyHome?homeId={home.homeId}"; | |
var response = await httpClient.PostAsync(requestUrl, stringData); | |
var result = await response.Content.ReadAsStringAsync(); | |
var jsonResult = JsonSerializer.Deserialize<SelectRoombyHomeResponse>(result); | |
return jsonResult.data.roomList.First(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task<Device> GetDevice(Room room) | |
{ | |
var requestUrl = $"uds/selectDevicebyRoom?roomId={room.roomId}"; | |
var response = await httpClient.PostAsync(requestUrl, stringData); | |
var result = await response.Content.ReadAsStringAsync(); | |
var jsonResult = JsonSerializer.Deserialize<SelectDevicebyRoomResponse>(result); | |
return jsonResult.data.deviceList.First(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task SetDevice(Device device, int temperature, int operation, int status) | |
{ | |
var requestUrl = $"uds/deviceControlForOpenApi?deviceId={device.deviceId}&holdTemp={temperature}&operation={operation}&status={status}"; | |
var response = await httpClient.PostAsync(requestUrl, stringData); | |
var result = await response.Content.ReadAsStringAsync(); | |
} |