Configuration of the discovery process

I want to develop my first binding for SMA inverters. To identify the devices during discovery, I need to log in to the inverter using a username and password. Usually these are “user” and “1111”. But if someone changed the password on the inverter, discovery would fail.

To get rid of this problem, I need a way that the user can specify username/password (or a list of this pairs) for the discovery. How can I achieve that?

It’s a bit of a chicken-egg problem. I’ve had a similar situation where a device needs a authentication key. I solved this as follows. While direct access isn’t possible. It is possible to detect the device due to the way it reports back. I assume you can do something similar. The device will probably report back if you make a connection with an error that the username/password is incorrect. In such a case in discovery you simply add the device with either the default username/password or empty values. When the thing is then initialized you handle in this in the initialization phase of the binding by setting the status to configuration error with a clear message the user need to set the username/password.

If there is only one speedwire device in the network, this might work. But the only data I get from this first discovery phase is the IP address of a device which replies to my multicast package with a defined answer. What do I do, if I get multiple answers from different devices? How should the user know, which IP address corresponds to which device?

How do I initialize the ThingUID if I have no serial number? The IP address could change between different scans.

How do you send the username/password? I would guess when you have the ip you connect directly to it? Does it report something back than? Even if the username/password is not correct. During discovery you can connect and use what it reports back, if that is any useful information of course.

The ThingUID is less relevant because there is no direct relation between the device and the ThingUID. It’s free format. Technically any overlap would be coincidental. So you can set it to any string you want.
To avoid rediscovering you need to set some unique id and ip address could be cause or rediscovering the same device if the ip changes. But you can tackle that by setting the serial afterwards in the configuration if the device is authenticated. This will only cause rediscovering of unauthenticated devices that changed ip address.

B.t.w. There is a binding for the SMA energy meter. I don’t know if it uses the same communication protocol, but it might be worth looking at:

The speedwire specification says "“A SMA device address is a 6-byte long worldwide unique identifier for an SMA device”. And I get this device address back even if login fails.

This should work. Thanks a lot.

By the way: energymeter only communicates via multicast. SMA inverters reply on special requests. It’s quiet different.