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

Device ID creation fails #1139

Closed
sub0ne opened this issue Oct 1, 2019 · 6 comments · Fixed by #1266
Closed

Device ID creation fails #1139

sub0ne opened this issue Oct 1, 2019 · 6 comments · Fixed by #1266
Assignees
Milestone

Comments

@sub0ne
Copy link

sub0ne commented Oct 1, 2019

Let's say you have created three devices with the IDs 100, 101 and 102. After restarting ha-bridge the DeviceRepository loads the device list and sets the assigns the highest ID to the variable 'nextID'. Now you add a new device in ha-bridge and the device 102 will be overwritten during save since nextID is first used and then incremented.

_loadResository():

for (int i = 0; i < list.length; i++) {
	if (list[i].getColorUrl() == null || list[i].getColorUrl().isEmpty())
		list[i].setDeviceState(DeviceState.createDeviceState(false));
	else
		list[i].setDeviceState(DeviceState.createDeviceState(true));
	put(list[i].getId(), list[i]);
	if (Integer.decode(list[i].getId()) > nextId) {
		nextId = Integer.decode(list[i].getId());
	}
}

and in save():

descriptors[i].setId(String.valueOf(nextId));
nextId++;

Solution proposal:

_loadResository():

for (int i = 0; i < list.length; i++) {
	if (list[i].getColorUrl() == null || list[i].getColorUrl().isEmpty())
		list[i].setDeviceState(DeviceState.createDeviceState(false));
	else
		list[i].setDeviceState(DeviceState.createDeviceState(true));
	put(list[i].getId(), list[i]);
	if (Integer.decode(list[i].getId()) >= nextId) {
		nextId = Integer.decode(list[i].getId()) + 1;
	}
}

gonna fix this in my branch https://github.com/sub0ne/ha-bridge

@bwssytems
Copy link
Owner

Hmmm, thought I fixed that before as it was an issue prior. Will take a look

@bwssytems
Copy link
Owner

Well, it needs to be updated to do something.... But, I need to make sure it works with a sparse array. The changes I made were to be able to account for gaps in the IDs. Guess it was not enough.

@bwssytems bwssytems added the bug label Oct 1, 2019
@bwssytems bwssytems added this to the 5.3.1 milestone Oct 2, 2019
@bwssytems
Copy link
Owner

bwssytems commented Oct 2, 2019

The solution is:

for (int i = 0; i < list.length; i++) {
	if (list[i].getColorUrl() == null || list[i].getColorUrl().isEmpty())
		list[i].setDeviceState(DeviceState.createDeviceState(false));
	else
		list[i].setDeviceState(DeviceState.createDeviceState(true));
	put(list[i].getId(), list[i]);
	if (Integer.decode(list[i].getId()) >= nextId) {
		nextId = Integer.decode(list[i].getId()) ;
	}
}

nextId = nextId + 1;

Have to wait until all devices are loaded to get the highest value.

@bwssytems bwssytems self-assigned this Oct 2, 2019
@SvenXP
Copy link

SvenXP commented Jan 6, 2020

Hi, not sure if it belongs here but seems related:

If i want to add a new device via "edit/copy" and then "add bridge device" it overwrites my existing device with id=100. so i can not add any new devices cause it just overwrites the last one.

Also i have no idea why i have id 100 cause i do not have that many devices and the one before is 41.

Update: just changed the last entry manually from 100 to 42. Then added a new device and it was set again to 100?!? Any ideas?

@bwssytems
Copy link
Owner

This is a bug that has not been released yet....

@bwssytems
Copy link
Owner

Fixed in RC3

bwssytems added a commit that referenced this issue Dec 14, 2020
Dev branch 5.3.x to create v5.4.0

#1044 Alexa app, error "Device doesn't support requested value" bug question
#1118 Device status update in Alexa App is not working correctly for ha-bridge devices bug duplicate question
#1126 Can't get XY ColorData into URL enhancement question
#1127 Can't get separate hue, saturation and brightness enhancement question
#1128 Wrong color calucation in HS mode bug question
#1131 Changing color temperatur is not working correctly bug question
#1132 Conversion from CIE to RGB incorrect bug question
#1139 Device ID creation fails bug question
#1150 Home Assistant gets null exception during initialization bug question
#1170 Alexa not sending the correct color codes duplicate
#1171 Please add option: If bright request present with on, only send dim enhancement
#1184 Alexa will not discover HABridge question
#1191 When "Use UPNP Address Interface Only" is selected, echo cannot find ha-bridge bug
#1210 [Enahnacement] Have link button timeout be configurable enhancement
#1215 Alexa unable to discover recently added devices to ha-bridge duplicate question
#1227 Feature request: ${intensity.previous} value passing control enhancement
#1239 HA-Bridge has suddenly given up itself - Exception in thread "main" java.lang.NullPointerException bug question
#1243 Alexa device discovery now broke question
#1253 HABridge hue ColorDecode 0 0 0 bug question
#1256 Homeassistant devices not appearing bug question
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants