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

[miio] Change deviceID to Xiaomi used string #10951

Merged
merged 2 commits into from
Jul 6, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions bundles/org.openhab.binding.miio/README.base.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ However, for devices that are unsupported, you may override the value and try to
|-----------------|---------|----------|---------------------------------------------------------------------|
| host | text | true | Device IP address |
| token | text | true | Token for communication (in Hex) |
| deviceId | text | true | Device ID number for communication (in Hex) |
| deviceId | text | true | Device Id (typically a number for normal devices) for communication |
| model | text | false | Device model string, used to determine the subtype |
| refreshInterval | integer | false | Refresh interval for refreshing the data in seconds. (0=disabled) |
| timeout | integer | false | Timeout time in milliseconds |
Expand All @@ -86,11 +86,11 @@ Note: Suggest to use the cloud communication only for devices that require it. I

### Example Thing file

`Thing miio:basic:light "My Light" [ host="192.168.x.x", token="put here your token", deviceId="0326xxxx", model="philips.light.bulb", communication="direct" ]`
`Thing miio:basic:light "My Light" [ host="192.168.x.x", token="put here your token", deviceId="326xxxx", model="philips.light.bulb", communication="direct" ]`

or in case of unknown models include the model information of a similar device that is supported:

`Thing miio:vacuum:s50 "vacuum" @ "livingroom" [ host="192.168.15.20", token="xxxxxxx", deviceId=“0470DDAA”, model="roborock.vacuum.s4", communication="cloud"]`
`Thing miio:vacuum:s50 "vacuum" @ "livingroom" [ host="192.168.15.20", token="xxxxxxx", deviceId="326xxxx", model="roborock.vacuum.s4", communication="direct" ]`

# Advanced: Unsupported devices

Expand Down
6 changes: 3 additions & 3 deletions bundles/org.openhab.binding.miio/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ However, for devices that are unsupported, you may override the value and try to
|-----------------|---------|----------|---------------------------------------------------------------------|
| host | text | true | Device IP address |
| token | text | true | Token for communication (in Hex) |
| deviceId | text | true | Device ID number for communication (in Hex) |
| deviceId | text | true | Device Id (typically a number for normal devices) for communication |
| model | text | false | Device model string, used to determine the subtype |
| refreshInterval | integer | false | Refresh interval for refreshing the data in seconds. (0=disabled) |
| timeout | integer | false | Timeout time in milliseconds |
Expand All @@ -86,11 +86,11 @@ Note: Suggest to use the cloud communication only for devices that require it. I

### Example Thing file

`Thing miio:basic:light "My Light" [ host="192.168.x.x", token="put here your token", deviceId="0326xxxx", model="philips.light.bulb", communication="direct" ]`
`Thing miio:basic:light "My Light" [ host="192.168.x.x", token="put here your token", deviceId="326xxxx", model="philips.light.bulb", communication="direct" ]`

or in case of unknown models include the model information of a similar device that is supported:

`Thing miio:vacuum:s50 "vacuum" @ "livingroom" [ host="192.168.15.20", token="xxxxxxx", deviceId=“0470DDAA”, model="roborock.vacuum.s4", communication="cloud"]`
`Thing miio:vacuum:s50 "vacuum" @ "livingroom" [ host="192.168.15.20", token="xxxxxxx", deviceId="326xxxx", model="roborock.vacuum.s4", communication="direct" ]`

# Advanced: Unsupported devices

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,17 @@ public static String fromHEX(String value) {
}
return value;
}

/**
* Formats the deviceId to a hex string if possible. Otherwise returns the id unmodified.
*
* @param did
* @return did
*/
public static String getHexId(String did) {
if (!did.isBlank() && !did.contains(".")) {
return toHEX(did);
}
return did;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,9 @@ public List<CloudDeviceDTO> getDevicesList() {
if (deviceListState != DeviceListState.AVAILABLE) {
return null;
}
String did = Long.toString(Long.parseUnsignedLong(id, 16));
List<CloudDeviceDTO> devicedata = new ArrayList<>();
for (CloudDeviceDTO deviceDetails : deviceList) {
if (deviceDetails.getDid().contentEquals(did)) {
if (deviceDetails.getDid().contentEquals(id)) {
devicedata.add(deviceDetails);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ private void cloudDiscovery() {
if (cloudConnector.isConnected()) {
List<CloudDeviceDTO> dv = cloudConnector.getDevicesList();
for (CloudDeviceDTO device : dv) {
String id = Utils.toHEX(device.getDid());
String id = device.getDid();
if (cloudDiscoveryMode.contentEquals(SUPPORTED)) {
if (MiIoDevices.getType(device.getModel()).getThingType().equals(THING_TYPE_UNSUPPORTED)) {
logger.warn("Discovered from cloud, but ignored because not supported: {} {}", id, device);
Expand All @@ -194,7 +194,7 @@ private void cloudDiscovery() {
logger.debug("Discovered from cloud: {} {}", id, device);
cloudDevices.put(id, device.getLocalip());
String token = device.getToken();
String label = device.getName() + " " + id + " (" + device.getDid() + ")";
String label = device.getName() + " " + id + " (" + Utils.getHexId(id) + ")";
String country = device.getServer();
boolean isOnline = device.getIsOnline();
String ip = device.getLocalip();
Expand All @@ -210,8 +210,9 @@ private void discovered(String ip, byte[] response) {
logger.trace("Discovery responses from : {}:{}", ip, Utils.getSpacedHex(response));
Message msg = new Message(response);
String token = Utils.getHex(msg.getChecksum());
String id = Utils.getHex(msg.getDeviceId());
String label = "Xiaomi Mi Device " + id + " (" + Utils.fromHEX(id) + ")";
String hexId = Utils.getHex(msg.getDeviceId());
String id = Utils.fromHEX(hexId);
String label = "Xiaomi Mi Device " + id + " (" + Utils.getHexId(id) + ")";
String country = "";
boolean isOnline = false;
if (ip.equals(cloudDevices.get(id))) {
Expand All @@ -224,7 +225,7 @@ private void discovered(String ip, byte[] response) {
if (cloudInfo != null) {
logger.debug("Cloud Info: {}", cloudInfo);
token = cloudInfo.getToken();
label = cloudInfo.getName() + " " + id + " (" + Utils.fromHEX(id) + ")";
label = cloudInfo.getName() + " " + id + " (" + Utils.getHexId(id) + ")";
country = cloudInfo.getServer();
isOnline = cloudInfo.getIsOnline();
}
Expand All @@ -233,17 +234,17 @@ private void discovered(String ip, byte[] response) {
}

private void submitDiscovery(String ip, String token, String id, String label, String country, boolean isOnline) {
ThingUID uid = new ThingUID(THING_TYPE_MIIO, id.replace(".", "_"));
ThingUID uid = new ThingUID(THING_TYPE_MIIO, Utils.getHexId(id).replace(".", "_"));
DiscoveryResultBuilder dr = DiscoveryResultBuilder.create(uid).withProperty(PROPERTY_HOST_IP, ip)
.withProperty(PROPERTY_DID, id);
if (IGNORED_TOKENS.contains(token)) {
logger.debug("Discovered Mi Device {} ({}) at {} as {}", id, Utils.fromHEX(id), ip, uid);
logger.debug("Discovered Mi Device {} ({}) at {} as {}", id, Utils.getHexId(id), ip, uid);
logger.debug(
"No token discovered for device {}. For options how to get the token, check the binding readme.",
id);
dr = dr.withRepresentationProperty(PROPERTY_DID).withLabel(label);
} else {
logger.debug("Discovered Mi Device {} ({}) at {} as {} with token {}", id, Utils.fromHEX(id), ip, uid,
logger.debug("Discovered Mi Device {} ({}) at {} as {} with token {}", id, Utils.getHexId(id), ip, uid,
token);
dr = dr.withProperty(PROPERTY_TOKEN, token).withRepresentationProperty(PROPERTY_DID)
.withLabel(label + " with token");
Expand Down

This file was deleted.

Loading