Skip to content

Commit

Permalink
[miio] replace depreciated bundle reference
Browse files Browse the repository at this point in the history
* Removed depreciated bundle ref
* Fixed typo for vacuum v2
* Add conversion for scene

Signed-off-by: Marcel Verpaalen <marcel@verpaalen.com>
  • Loading branch information
marcelrv committed May 27, 2018
1 parent 0bcefe5 commit 2f4d8c3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.openhab.binding.miio.internal.basic.MiIoDeviceAction;
import org.openhab.binding.miio.internal.transport.MiIoAsyncCommunication;
import org.osgi.framework.Bundle;
import org.osgi.framework.FrameworkUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -64,7 +65,6 @@ public class MiIoBasicHandler extends MiIoAbstractHandler {
private static final int MAX_PROPERTIES = 5;
private final Logger logger = LoggerFactory.getLogger(MiIoBasicHandler.class);
private boolean hasChannelStructure;
// private BundleContext bundleContext;

List<MiIoBasicChannel> refreshList = new ArrayList<MiIoBasicChannel>();

Expand All @@ -76,11 +76,6 @@ public MiIoBasicHandler(Thing thing) {
super(thing);
}

// @Activate
// protected void activate(BundleContext bundleContext) {
// this.bundleContext = bundleContext;
// }

@Override
public void initialize() {
super.initialize();
Expand Down Expand Up @@ -238,7 +233,7 @@ private void checkChannelStructure() {
private URL findDatabaseEntry(String deviceName) {
URL fn;
try {
Bundle bundle = bundleContext.getBundle();
Bundle bundle = FrameworkUtil.getBundle(getClass());
fn = bundle.getEntry(MiIoBindingConstants.DATABASE_PATH + deviceName + ".json");
if (fn != null) {
logger.trace("bundle: {}, {}, {}", bundle, fn.getFile());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public enum MiIoDevices {
POWERSTRIP2("zimi.powerstrip.v2", "Mi Power-strip v2", MiIoBindingConstants.THING_TYPE_BASIC),
TOOTHBRUSH("soocare.toothbrush.x3", "Mi Toothbrush", MiIoBindingConstants.THING_TYPE_UNSUPPORTED),
VACUUM("rockrobo.vacuum.v1", "Mi Robot Vacuum", MiIoBindingConstants.THING_TYPE_VACUUM),
VACUUM2("roborock-vacuum-s5", "Mi Robot Vacuum v2", MiIoBindingConstants.THING_TYPE_VACUUM),
VACUUM2("roborock.vacuum.s5", "Mi Robot Vacuum v2", MiIoBindingConstants.THING_TYPE_VACUUM),
WATER_PURIFIER2("yunmi.waterpuri.v2", "Mi Water Purifier v2", MiIoBindingConstants.THING_TYPE_UNSUPPORTED),
WIFI2("xiaomi.repeater.v2", "Xiaomi Wifi Extender", MiIoBindingConstants.THING_TYPE_UNSUPPORTED),
WIFISPEAKER("xiaomi.wifispeaker.v1", "Mi Internet Speaker", MiIoBindingConstants.THING_TYPE_UNSUPPORTED),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,34 @@ public static JsonElement secondsToHours(JsonElement seconds) {
return new JsonPrimitive(hours);
}

public static JsonElement yeelightSceneConversion(JsonElement intValue) {
switch (intValue.getAsInt()) {
case 1:
return new JsonPrimitive("color");
case 2:
return new JsonPrimitive("hsv");
case 3:
return new JsonPrimitive("ct");
case 4:
return new JsonPrimitive("nightlight");
case 5: // don't know the number for colorflow...
return new JsonPrimitive("cf");
case 6: // don't know the number for auto_delay_off, or if it is even in the properties visible...
return new JsonPrimitive("auto_delay_off");
default:
return new JsonPrimitive("unknown");
}
}

public static JsonElement divideTen(JsonElement value10) {
double value = value10.getAsDouble() / 10;
return new JsonPrimitive(value);
}

public static JsonElement execute(String transfortmation, JsonElement value) {
switch (transfortmation.toUpperCase()) {
case "YEELIGHTSCENEID":
return yeelightSceneConversion(value);
case "SECONDSTOHOURS":
return secondsToHours(value);
case "/10":
Expand Down

0 comments on commit 2f4d8c3

Please sign in to comment.