[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:
parent
49580b59bb
commit
8606f57b56
@ -14,7 +14,7 @@
|
|||||||
package org.openhab.binding.miio.internal.basic;
|
package org.openhab.binding.miio.internal.basic;
|
||||||
|
|
||||||
import static java.nio.file.StandardWatchEventKinds.*;
|
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.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -33,7 +33,6 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
|
|||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
import org.openhab.binding.miio.internal.MiIoBindingConstants;
|
import org.openhab.binding.miio.internal.MiIoBindingConstants;
|
||||||
import org.openhab.binding.miio.internal.Utils;
|
import org.openhab.binding.miio.internal.Utils;
|
||||||
import org.openhab.core.OpenHAB;
|
|
||||||
import org.openhab.core.service.AbstractWatchService;
|
import org.openhab.core.service.AbstractWatchService;
|
||||||
import org.osgi.framework.Bundle;
|
import org.osgi.framework.Bundle;
|
||||||
import org.osgi.framework.FrameworkUtil;
|
import org.osgi.framework.FrameworkUtil;
|
||||||
@ -56,8 +55,6 @@ import com.google.gson.JsonSyntaxException;
|
|||||||
@Component(service = MiIoDatabaseWatchService.class)
|
@Component(service = MiIoDatabaseWatchService.class)
|
||||||
@NonNullByDefault
|
@NonNullByDefault
|
||||||
public class MiIoDatabaseWatchService extends AbstractWatchService {
|
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 String DATABASE_FILES = ".json";
|
||||||
private static final Gson GSON = new GsonBuilder().serializeNulls().create();
|
private static final Gson GSON = new GsonBuilder().serializeNulls().create();
|
||||||
|
|
||||||
@ -66,11 +63,11 @@ public class MiIoDatabaseWatchService extends AbstractWatchService {
|
|||||||
|
|
||||||
@Activate
|
@Activate
|
||||||
public MiIoDatabaseWatchService() {
|
public MiIoDatabaseWatchService() {
|
||||||
super(LOCAL_DATABASE_PATH);
|
super(BINDING_DATABASE_PATH);
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"Started miio basic devices local databases watch service. Watching for database files at path: {}",
|
"Started miio basic devices local databases watch service. Watching for database files at path: {}",
|
||||||
LOCAL_DATABASE_PATH);
|
BINDING_DATABASE_PATH);
|
||||||
processWatchEvent(null, null, Paths.get(LOCAL_DATABASE_PATH));
|
processWatchEvent(null, null, Paths.get(BINDING_DATABASE_PATH));
|
||||||
populateDatabase();
|
populateDatabase();
|
||||||
if (logger.isTraceEnabled()) {
|
if (logger.isTraceEnabled()) {
|
||||||
for (String device : databaseList.keySet()) {
|
for (String device : databaseList.keySet()) {
|
||||||
@ -132,9 +129,8 @@ public class MiIoDatabaseWatchService extends AbstractWatchService {
|
|||||||
List<URL> urlEntries = new ArrayList<>();
|
List<URL> urlEntries = new ArrayList<>();
|
||||||
Bundle bundle = FrameworkUtil.getBundle(getClass());
|
Bundle bundle = FrameworkUtil.getBundle(getClass());
|
||||||
urlEntries.addAll(Collections.list(bundle.findEntries(MiIoBindingConstants.DATABASE_PATH, "*.json", false)));
|
urlEntries.addAll(Collections.list(bundle.findEntries(MiIoBindingConstants.DATABASE_PATH, "*.json", false)));
|
||||||
String userDbFolder = OpenHAB.getConfigFolder() + File.separator + "misc" + File.separator + BINDING_ID;
|
|
||||||
try {
|
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) {
|
if (userDbFiles != null) {
|
||||||
for (File f : userDbFiles) {
|
for (File f : userDbFiles) {
|
||||||
urlEntries.add(f.toURI().toURL());
|
urlEntries.add(f.toURI().toURL());
|
||||||
|
|||||||
@ -12,6 +12,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.openhab.binding.miio.internal.cloud;
|
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.ByteArrayOutputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -32,9 +34,7 @@ import java.util.TreeMap;
|
|||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
import org.openhab.binding.miio.internal.MiIoBindingConstants;
|
|
||||||
import org.openhab.binding.miio.internal.MiIoCryptoException;
|
import org.openhab.binding.miio.internal.MiIoCryptoException;
|
||||||
import org.openhab.core.OpenHAB;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -46,8 +46,6 @@ import org.slf4j.Logger;
|
|||||||
public class CloudUtil {
|
public class CloudUtil {
|
||||||
|
|
||||||
private static final Random RANDOM = new Random();
|
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
|
* Saves the Xiaomi cloud device info with tokens to file
|
||||||
@ -57,7 +55,7 @@ public class CloudUtil {
|
|||||||
* @param logger
|
* @param logger
|
||||||
*/
|
*/
|
||||||
public static void saveDeviceInfoFile(String data, String country, Logger 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()) {
|
if (!folder.exists()) {
|
||||||
folder.mkdirs();
|
folder.mkdirs();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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.StatusType;
|
||||||
import org.openhab.binding.miio.internal.robot.VacuumErrorType;
|
import org.openhab.binding.miio.internal.robot.VacuumErrorType;
|
||||||
import org.openhab.binding.miio.internal.transport.MiIoAsyncCommunication;
|
import org.openhab.binding.miio.internal.transport.MiIoAsyncCommunication;
|
||||||
import org.openhab.core.OpenHAB;
|
|
||||||
import org.openhab.core.cache.ExpiringCache;
|
import org.openhab.core.cache.ExpiringCache;
|
||||||
import org.openhab.core.library.types.DateTimeType;
|
import org.openhab.core.library.types.DateTimeType;
|
||||||
import org.openhab.core.library.types.DecimalType;
|
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 final Logger logger = LoggerFactory.getLogger(MiIoVacuumHandler.class);
|
||||||
private static final float MAP_SCALE = 2.0f;
|
private static final float MAP_SCALE = 2.0f;
|
||||||
private static final SimpleDateFormat DATEFORMATTER = new SimpleDateFormat("yyyyMMdd-HHmmss");
|
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 static final Gson GSON = new GsonBuilder().serializeNulls().create();
|
||||||
private final ChannelUID mapChannelUid;
|
private final ChannelUID mapChannelUid;
|
||||||
|
|
||||||
@ -588,7 +586,8 @@ public class MiIoVacuumHandler extends MiIoAbstractHandler {
|
|||||||
RRMapDraw rrMap = RRMapDraw.loadImage(new ByteArrayInputStream(mapData));
|
RRMapDraw rrMap = RRMapDraw.loadImage(new ByteArrayInputStream(mapData));
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
if (logger.isDebugEnabled()) {
|
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);
|
CloudUtil.writeBytesToFileNio(mapData, mapPath);
|
||||||
logger.debug("Mapdata saved to {}", mapPath);
|
logger.debug("Mapdata saved to {}", mapPath);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user