XaF / qolsysgw

Qolsys IQ Panel 2+ gateway to an Home Assistant Alarm Control Panel
MIT License
131 stars 13 forks source link

Sensors can get mismatched when switching / reinstalling panel #82

Closed XaF closed 1 year ago

XaF commented 1 year ago

At the moment, sensor unique ids are computed using the partition and zone id. This means that the unique id is unique while running the gateway, but if changing panel and keeping the same configuration, zone ids might be reused / mixed / switched, and unique ids get moved around, confusing slightly home assistant.

If we were to use the ids of the sensors, which are unique by themselves, we would make sure that this situation does not happen. Moreover, previous identification of those sensors in home assistant would stay the same as the unique id would be matching.

https://github.com/XaF/qolsysgw/blob/9737a932578bc0d85a716e1b73cbe2e0e3f2ac7e/apps/qolsysgw/mqtt/updater.py#L494-L496

Could thus become something like:

        payload['unique_id'] = f"{self._cfg.panel_unique_id}_{self._sensor.id}"

Maybe with some normalization of the sensor id. The question for this change: would it be a breaking change for qolsysgw? Since HA does not use the unique id as entity id, this should not be the case, but maybe HA would add a number at the end of the sensor name if it sees a new sensor with the same name, but a different unique ID ? This should be investigated before making any change in that sense.

XaF commented 1 year ago

would it be a breaking change for qolsysgw?

Testing #95 locally seems to show no breaking change and no duplication of the sensors, so that can be part of a minor update.