[miio] cleanup duplicate paths (#8835)

Use the path defined in the binding constants

Signed-off-by: Marcel Verpaalen <marcel@verpaalen.com>
This commit is contained in:
Marcel 2020-10-22 18:13:08 +02:00 committed by GitHub
parent 49580b59bb
commit 8606f57b56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 17 deletions

View File

@ -14,7 +14,7 @@
package org.openhab.binding.miio.internal.basic;
import static java.nio.file.StandardWatchEventKinds.*;
import static org.openhab.binding.miio.internal.MiIoBindingConstants.BINDING_ID;
import static org.openhab.binding.miio.internal.MiIoBindingConstants.BINDING_DATABASE_PATH;
import java.io.File;
import java.io.IOException;
@ -33,7 +33,6 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.miio.internal.MiIoBindingConstants;
import org.openhab.binding.miio.internal.Utils;
import org.openhab.core.OpenHAB;
import org.openhab.core.service.AbstractWatchService;
import org.osgi.framework.Bundle;
import org.osgi.framework.FrameworkUtil;
@ -56,8 +55,6 @@ import com.google.gson.JsonSyntaxException;
@Component(service = MiIoDatabaseWatchService.class)
@NonNullByDefault
public class MiIoDatabaseWatchService extends AbstractWatchService {
private static final String LOCAL_DATABASE_PATH = OpenHAB.getConfigFolder() + File.separator + "misc"
+ File.separator + BINDING_ID;
private static final String DATABASE_FILES = ".json";
private static final Gson GSON = new GsonBuilder().serializeNulls().create();
@ -66,11 +63,11 @@ public class MiIoDatabaseWatchService extends AbstractWatchService {
@Activate
public MiIoDatabaseWatchService() {
super(LOCAL_DATABASE_PATH);
super(BINDING_DATABASE_PATH);
logger.debug(
"Started miio basic devices local databases watch service. Watching for database files at path: {}",
LOCAL_DATABASE_PATH);
processWatchEvent(null, null, Paths.get(LOCAL_DATABASE_PATH));
BINDING_DATABASE_PATH);
processWatchEvent(null, null, Paths.get(BINDING_DATABASE_PATH));
populateDatabase();
if (logger.isTraceEnabled()) {
for (String device : databaseList.keySet()) {
@ -132,9 +129,8 @@ public class MiIoDatabaseWatchService extends AbstractWatchService {
List<URL> urlEntries = new ArrayList<>();
Bundle bundle = FrameworkUtil.getBundle(getClass());
urlEntries.addAll(Collections.list(bundle.findEntries(MiIoBindingConstants.DATABASE_PATH, "*.json", false)));
String userDbFolder = OpenHAB.getConfigFolder() + File.separator + "misc" + File.separator + BINDING_ID;
try {
File[] userDbFiles = new File(userDbFolder).listFiles((dir, name) -> name.endsWith(".json"));
File[] userDbFiles = new File(BINDING_DATABASE_PATH).listFiles((dir, name) -> name.endsWith(".json"));
if (userDbFiles != null) {
for (File f : userDbFiles) {
urlEntries.add(f.toURI().toURL());

View File

@ -12,6 +12,8 @@
*/
package org.openhab.binding.miio.internal.cloud;
import static org.openhab.binding.miio.internal.MiIoBindingConstants.BINDING_USERDATA_PATH;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.File;
@ -32,9 +34,7 @@ import java.util.TreeMap;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.miio.internal.MiIoBindingConstants;
import org.openhab.binding.miio.internal.MiIoCryptoException;
import org.openhab.core.OpenHAB;
import org.slf4j.Logger;
/**
@ -46,8 +46,6 @@ import org.slf4j.Logger;
public class CloudUtil {
private static final Random RANDOM = new Random();
private static final String DB_FOLDER_NAME = OpenHAB.getUserDataFolder() + File.separator
+ MiIoBindingConstants.BINDING_ID;
/**
* Saves the Xiaomi cloud device info with tokens to file
@ -57,7 +55,7 @@ public class CloudUtil {
* @param logger
*/
public static void saveDeviceInfoFile(String data, String country, Logger logger) {
File folder = new File(DB_FOLDER_NAME);
File folder = new File(BINDING_USERDATA_PATH);
if (!folder.exists()) {
folder.mkdirs();
}

View File

@ -46,7 +46,6 @@ import org.openhab.binding.miio.internal.robot.StatusDTO;
import org.openhab.binding.miio.internal.robot.StatusType;
import org.openhab.binding.miio.internal.robot.VacuumErrorType;
import org.openhab.binding.miio.internal.transport.MiIoAsyncCommunication;
import org.openhab.core.OpenHAB;
import org.openhab.core.cache.ExpiringCache;
import org.openhab.core.library.types.DateTimeType;
import org.openhab.core.library.types.DecimalType;
@ -84,7 +83,6 @@ public class MiIoVacuumHandler extends MiIoAbstractHandler {
private final Logger logger = LoggerFactory.getLogger(MiIoVacuumHandler.class);
private static final float MAP_SCALE = 2.0f;
private static final SimpleDateFormat DATEFORMATTER = new SimpleDateFormat("yyyyMMdd-HHmmss");
private static final String MAP_PATH = OpenHAB.getUserDataFolder() + File.separator + BINDING_ID + File.separator;
private static final Gson GSON = new GsonBuilder().serializeNulls().create();
private final ChannelUID mapChannelUid;
@ -588,7 +586,8 @@ public class MiIoVacuumHandler extends MiIoAbstractHandler {
RRMapDraw rrMap = RRMapDraw.loadImage(new ByteArrayInputStream(mapData));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
if (logger.isDebugEnabled()) {
final String mapPath = MAP_PATH + map + DATEFORMATTER.format(new Date()) + ".rrmap";
final String mapPath = BINDING_USERDATA_PATH + File.separator + map
+ DATEFORMATTER.format(new Date()) + ".rrmap";
CloudUtil.writeBytesToFileNio(mapData, mapPath);
logger.debug("Mapdata saved to {}", mapPath);
}