Skip to content
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

Open
guyluz11 opened this issue Dec 26, 2022 · 2 comments
Open

Add Nanoleaf Lights support #56

guyluz11 opened this issue Dec 26, 2022 · 2 comments
Labels
new vendor support Request for adding support to a specific Vendor Open API Vendors with open API

Comments

@guyluz11
Copy link
Member

guyluz11 commented Dec 26, 2022

Let's add support for Nanoleaf Lights

Currntly 1.3% of home assistant users are using it.

nanoleaf_icon2

@guyluz11
Copy link
Member Author

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 guyluz11 added the new vendor support Request for adding support to a specific Vendor label Mar 26, 2023
@guyluz11 guyluz11 added the Open API Vendors with open API label Jan 2, 2024
@guyluz11
Copy link
Member Author

guyluz11 commented Jan 2, 2024

@guyluz11 guyluz11 transferred this issue from CyBear-Jinni/cbj_hub Jan 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new vendor support Request for adding support to a specific Vendor Open API Vendors with open API
Projects
None yet
Development

No branches or pull requests

1 participant