-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Nanoleaf Lights support #56
Labels
Comments
Example code for chect chatGPT, it looks like nanoleaf is doing direct calls to the device using rust import 'dart:convert';
import 'package:http/http.dart' as http;
const String baseUrl = 'http://192.168.1.100';
const String authToken = 'YourAuthToken';
class NanoleafAPI {
// Function to retrieve the current state of the lights
Future<Map<String, dynamic>> getState() async {
var url = '$baseUrl/state';
var headers = {
'Authorization': 'Bearer $authToken',
'Content-Type': 'application/json',
};
var response = await http.get(url, headers: headers);
if (response.statusCode != 200) {
throw Exception('Failed to retrieve state');
}
return jsonDecode(response.body);
}
// Function to turn the lights on
Future<void> turnOn() async {
var url = '$baseUrl/state';
var headers = {
'Authorization': 'Bearer $authToken',
'Content-Type': 'application/json',
};
var body = jsonEncode({'on': {'value': true}});
var response = await http.put(url, headers: headers, body: body);
if (response.statusCode != 200) {
throw Exception('Failed to turn on lights');
}
}
// Function to turn the lights off
Future<void> turnOff() async {
var url = '$baseUrl/state';
var headers = {
'Authorization': 'Bearer $authToken',
'Content-Type': 'application/json',
};
var body = jsonEncode({'on': {'value': false}});
var response = await http.put(url, headers: headers, body: body);
if (response.statusCode != 200) {
throw Exception('Failed to turn off lights');
}
}
}
|
guyluz11
added
the
new vendor support
Request for adding support to a specific Vendor
label
Mar 26, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Let's add support for Nanoleaf Lights
Currntly 1.3% of home assistant users are using it.
The text was updated successfully, but these errors were encountered: