@marko2276 ,
After using your implementation for more than 2 years without flaw, both of my Unipi V1.1 systems (one with my whole Homeassistant installation) "died" from repeating powerfailures, due to grid loss and active but non functional emergency power. Both USB-sticks were damaged with backups on the same stick. Really bad luck, I should have known better.
This forced me to a new installation using your altered code with unique_ids.
Unfortunately, this code does not work properly having more than one Unipi-device with the same configuration(s).
In this case the "unique_ids" will be identical for e.g. lights or switches on Unipi unit 1 and Unipi unit 2!
Thus, Homeassistant isn't able to determine the targets anymore and will disable them.
It took me some time effort to find this issue.
As I'm using UniPi V1.1 devices, this migth only appear within my setup, but I'm pretty sure, this error will also occure on other unipi devices.
I managed to get around this issue by extending the unique_id property definition(s) like this:
code_text
@property
def unique_id(self):
"""Return the unique ID of this light entity."""
return f"{self._device}_{self._port}_at_{self._unipi_hub._name}"
Hope, this will help others with the same issue.
Cheers, Joerg