Skip to content

Commit

Permalink
Added Device list request
Browse files Browse the repository at this point in the history
  • Loading branch information
hubaksis committed Sep 23, 2021
1 parent eb2a798 commit 9a1bf04
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ public enum MiIoCommand {
GET_NIGHTLIGHT_RGB("get_night_light_rgb"),
GET_LUMI_BIND("get_lumi_bind"),

TELNET_ENABLE("enable_telnet_service"),

GET_DEVICE_LIST("get_device_list"),

UNKNOWN("");

private final String command;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
import org.openhab.binding.miio.internal.basic.MiIoDatabaseWatchService;
import org.openhab.binding.miio.internal.cloud.CloudConnector;
import org.openhab.binding.miio.internal.transport.MiIoAsyncCommunication;

import org.openhab.binding.miio.internal.json.GatewayDevicesList;

import org.openhab.core.cache.ExpiringCache;
import org.openhab.core.common.NamedThreadFactory;
import org.openhab.core.config.core.Configuration;
Expand Down Expand Up @@ -467,6 +470,11 @@ private void updateDeviceIdConfig(String deviceId) {

protected boolean initializeData() {
this.miioCom = getConnection();

if (this.miioCom != null && this instanceof MiIoGatewayHandler) {
sendCommand(MiIoCommand.GET_DEVICE_LIST);
}

return true;
}

Expand Down Expand Up @@ -649,6 +657,9 @@ public void onMessageReceived(MiIoSendCommand response) {
}
updateNetwork(response.getResult().getAsJsonObject());
break;
case GET_DEVICE_LIST:
parseDeviceList(response.getResponse().toString());
break;
default:
break;
}
Expand All @@ -663,4 +674,12 @@ public void onMessageReceived(MiIoSendCommand response) {
logger.debug("Error while handing message {}", response.getResponse(), e);
}
}

private void parseDeviceList(String str){
GatewayDevicesList message = new Gson().fromJson(str, GatewayDevicesList.class);
logger.info("Found devices count: {}", message.result.size());
//if(bridge != null)
// bridge.getDevicesListRequestCompleted(message);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.openhab.binding.miio.internal.json;

import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jdt.annotation.NonNull;

import com.google.gson.annotations.SerializedName;

public class GatewayDeviceItem {
@SerializedName("did")
@NonNull
public String did = "";

@SerializedName("model")
@NonNull
public String model = "";

@SerializedName("num")
@Nullable
public Integer num;

@SerializedName("total")
@Nullable
public Integer total;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.openhab.binding.miio.internal.json;

import org.eclipse.jdt.annotation.Nullable;

import com.google.gson.annotations.SerializedName;

import org.eclipse.jdt.annotation.NonNullByDefault;
import java.util.List;


@NonNullByDefault
public class GatewayDevicesList {
@SerializedName("code")
@Nullable
public Integer code;

@SerializedName("result")
@Nullable
public List<GatewayDeviceItem> result;
}

0 comments on commit 9a1bf04

Please sign in to comment.