Git Product home page Git Product logo

Comments (9)

Rabbitminers avatar Rabbitminers commented on July 24, 2024

My Code:
package com.company;

import java.net.URLEncoder;
import io.github.zeroone3010.yahueapi.;
import io.github.zeroone3010.yahueapi.discovery.
;
import io.github.zeroone3010.yahueapi.Color;

public class Main {

public static void main(String[] args) {
    // Define IP & API UserName
    final String bridgeIp = "(Filled In the Code)";
    final String apiKey = "(Filled In the Code)";

    // Define Hue Bridge (1st Bridge) & Define Room Affected
    final Hue hue = new Hue(bridgeIp, apiKey);
    final Room room = hue.getRoomByName("Filled in code").get();

    // Change State
    room.setState(State.builder().color(Color.of(java.awt.Color.PINK)).on());

}

}

Full Errors:

Exception in thread "main" io.github.zeroone3010.yahueapi.HueApiException: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of io.github.zeroone3010.yahueapi.domain.Root out of START_ARRAY token
at [Source: (URL); line: 1, column: 1]
at io.github.zeroone3010.yahueapi.Hue.refresh(Hue.java:134)
at io.github.zeroone3010.yahueapi.Hue.doInitialDataLoadIfRequired(Hue.java:116)
at io.github.zeroone3010.yahueapi.Hue.getRoomByName(Hue.java:222)
at com.company.Main.main(Main.java:17)
Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of io.github.zeroone3010.yahueapi.domain.Root out of START_ARRAY token
at [Source: (URL); line: 1, column: 1]
at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:59)
at com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1468)
at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1242)
at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1190)
at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeFromArray(BeanDeserializer.java:604)
at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeOther(BeanDeserializer.java:190)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:166)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4526)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3399)
at io.github.zeroone3010.yahueapi.Hue.refresh(Hue.java:132)
... 3 more

  • Sorry if I'm just being ignorant.

from yetanotherhueapi.

ZeroOne3010 avatar ZeroOne3010 commented on July 24, 2024

Hey, no problem! Are you using Bridge v1 (round) or Bridge v2 (square)? The error message is basically saying that the Bridge is responding with a message that the library cannot decode -- it's not of the expected format. This is why I suspect you might be using v1, as I've never actually tried this library with it, and unfortunately do not intend to support it either.

But let's see: can you access the API debug tool? In your browser, try navigating to http://<IP_ADDRESS_OF_YOUR_BRIDE>/debug/clip.html You should be greeted with a form with the path "/api/1234/" filled in. Replace "1234" with your API key, then GET "/api/<YOUR_API_KEY>/groups". The response should be something to this effect:

{
	"1": {
		"name": "Bedroom",
		"lights": [
			"1",
			"3",
			"4",
			"2"
		],
		"sensors": [],
		"type": "Room",
		"state": {
			"all_on": false,
			"any_on": false
		},
		"recycle": false,
		"class": "Bedroom",
		"action": {
			"on": false,
			"bri": 1,
			"hue": 10778,
			"sat": 251,
			"effect": "none",
			"xy": [
				0.5609,
				0.4042
			],
			"ct": 443,
			"alert": "select",
			"colormode": "ct"
		}
	},
	"2": {
		"name": "Dining room",
		"lights": [
			"5"
		],
		"sensors": [],
		"type": "Room",
		"state": {
			"all_on": true,
			"any_on": true
		},
		"recycle": false,
		"class": "Dining",
		"action": {
			"on": true,
			"bri": 254,
			"ct": 343,
			"alert": "none",
			"colormode": "ct"
		}
	}
}

i.e. the response begins with a curly bracket, {. The error message you are getting indicates it would begin with a square bracket, [. If it's not that, then please try what happens when you add /1 into the end of the path and GET again. You should now get just the first room object, starting with the curly bracket.

from yetanotherhueapi.

Rabbitminers avatar Rabbitminers commented on July 24, 2024

Hi, thanks for the response I've accessed the API debugger:
{
"1": {
"name": "Lounge",
"lights": [
"3",
"7",
"22",
"21",
"2",
"4"
],
"sensors": [],
"type": "Room",
"state": {
"all_on": false,
"any_on": false
},
"recycle": false,
"class": "Living room",
"action": {
"on": false,
"bri": 144,
"hue": 7676,
"sat": 199,
"effect": "none",
"xy": [
0.5016,
0.4151
],
"ct": 443,
"alert": "lselect",
"colormode": "xy"
}
},

(Response for the first light only)
It seems to start with a brace as you implied

from yetanotherhueapi.

Rabbitminers avatar Rabbitminers commented on July 24, 2024

Also The Bridge I used is square with rounded edges, in-case that helps

from yetanotherhueapi.

ZeroOne3010 avatar ZeroOne3010 commented on July 24, 2024

Ahh you know what, I managed to replicate your issue. It happens when your API key is wrong, the response from the API is like this:

[
	{
		"error": {
			"type": 1,
			"address": "/",
			"description": "unauthorized user"
		}
	}
]

so it starts with a [ and cannot be deserialized. Could you please double-check your code so that you haven't made any copy-paste errors, like including a leading or trailing space, or leaving one letter out from one end or the other?

from yetanotherhueapi.

Rabbitminers avatar Rabbitminers commented on July 24, 2024

I have just checked both the IP and APIkey are working, the IP I have checked through the app and the API key works when pasted into the URL: on the debugger; im not terribly sure what is happening.

from yetanotherhueapi.

Rabbitminers avatar Rabbitminers commented on July 24, 2024

Oh my goodness, I am so stupid. So there are two bridges on the network and I was using the wrong bridge which had no such name. So It works, thank you so much for time; I wish you the best of luck with your further endeavours :)

from yetanotherhueapi.

ZeroOne3010 avatar ZeroOne3010 commented on July 24, 2024

OK, good that you figured it out! 😄 I'll definitely have to think about making the error messages more informative in this case, so thank you for bringing this issue to my attention! 👍

from yetanotherhueapi.

ZeroOne3010 avatar ZeroOne3010 commented on July 24, 2024

This error handling improvement has now been released in version 2.2.0. ✅

from yetanotherhueapi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.