Improved logging and removed exception in factory.
This commit is contained in:
parent
433b3ee002
commit
b6a0e39ac3
2 changed files with 24 additions and 2 deletions
|
|
@ -26,19 +26,26 @@ package se.hal.plugin.assistant.google.trait;
|
||||||
|
|
||||||
import se.hal.intf.HalAbstractDevice;
|
import se.hal.intf.HalAbstractDevice;
|
||||||
import se.hal.struct.Sensor;
|
import se.hal.struct.Sensor;
|
||||||
|
import zutil.log.LogUtil;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A factory class that will associate traits to Hal devices
|
* A factory class that will associate traits to Hal devices
|
||||||
*/
|
*/
|
||||||
public class DeviceTraitFactory {
|
public class DeviceTraitFactory {
|
||||||
|
private static final Logger logger = LogUtil.getLogger();
|
||||||
|
|
||||||
private DeviceTraitFactory() {}
|
private DeviceTraitFactory() {}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param device the device to get supported DeviceTraits for.
|
||||||
|
* @return an array of DeviceTrait objects that are able to handle the given device type or empty array if there is no supported DeviceTrait available.
|
||||||
|
*/
|
||||||
public static DeviceTrait[] getTraits(HalAbstractDevice device) {
|
public static DeviceTrait[] getTraits(HalAbstractDevice device) {
|
||||||
if (device == null || device.getDeviceConfig() == null)
|
if (device == null || device.getDeviceConfig() == null)
|
||||||
return new DeviceTrait[0];
|
return new DeviceTrait[0];
|
||||||
|
|
@ -62,10 +69,15 @@ public class DeviceTraitFactory {
|
||||||
return new DeviceTrait[]{new SensorStateTrait(), new TemperatureControlTrait()};
|
return new DeviceTrait[]{new SensorStateTrait(), new TemperatureControlTrait()};
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new IllegalArgumentException("Unknown device device class: " + device.getDeviceConfig().getDeviceDataClass());
|
logger.warning("Unknown device data class (" + device.getDeviceConfig().getDeviceDataClass() + ") provided by device config: " + device.getDeviceConfig().getClass());
|
||||||
|
return new DeviceTrait[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param traits
|
||||||
|
* @return a list integers of trait IDs matching the traits given.
|
||||||
|
*/
|
||||||
public static List<String> getTraitIds(DeviceTrait[] traits) {
|
public static List<String> getTraitIds(DeviceTrait[] traits) {
|
||||||
List<String> list = new ArrayList<>(traits.length);
|
List<String> list = new ArrayList<>(traits.length);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,9 @@ package se.hal.plugin.assistant.google.type;
|
||||||
|
|
||||||
import se.hal.intf.HalAbstractDevice;
|
import se.hal.intf.HalAbstractDevice;
|
||||||
import se.hal.struct.Sensor;
|
import se.hal.struct.Sensor;
|
||||||
|
import zutil.log.LogUtil;
|
||||||
|
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enum for https://developers.google.com/assistant/smarthome/types
|
* Enum for https://developers.google.com/assistant/smarthome/types
|
||||||
|
|
@ -134,6 +137,8 @@ public enum DeviceType {
|
||||||
YOGURTMAKER("action.devices.types.YOGURTMAKER");
|
YOGURTMAKER("action.devices.types.YOGURTMAKER");
|
||||||
|
|
||||||
|
|
||||||
|
private static final Logger logger = LogUtil.getLogger();
|
||||||
|
|
||||||
private final String typeId;
|
private final String typeId;
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -147,6 +152,10 @@ public enum DeviceType {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param device
|
||||||
|
* @return a DeviceType ENUM matching the given device or null if given device is not supported.
|
||||||
|
*/
|
||||||
public static DeviceType getType(HalAbstractDevice device) {
|
public static DeviceType getType(HalAbstractDevice device) {
|
||||||
if (device == null || device.getDeviceConfig() == null)
|
if (device == null || device.getDeviceConfig() == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
@ -163,7 +172,8 @@ public enum DeviceType {
|
||||||
return SENSOR;
|
return SENSOR;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new IllegalArgumentException("Unknown device device class: " + device.getDeviceConfig().getDeviceDataClass());
|
logger.warning("Unknown device data class (" + device.getDeviceConfig().getDeviceDataClass() + ") provided by device config: " + device.getDeviceConfig().getClass());
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue