diff --git a/plugins/hal-assistant-google/src/se/hal/plugin/assistant/google/trait/DeviceTraitFactory.java b/plugins/hal-assistant-google/src/se/hal/plugin/assistant/google/trait/DeviceTraitFactory.java index 5d13fb7a..5f1a9b8d 100644 --- a/plugins/hal-assistant-google/src/se/hal/plugin/assistant/google/trait/DeviceTraitFactory.java +++ b/plugins/hal-assistant-google/src/se/hal/plugin/assistant/google/trait/DeviceTraitFactory.java @@ -26,19 +26,26 @@ package se.hal.plugin.assistant.google.trait; import se.hal.intf.HalAbstractDevice; import se.hal.struct.Sensor; +import zutil.log.LogUtil; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.logging.Logger; /** * A factory class that will associate traits to Hal devices */ public class DeviceTraitFactory { + private static final Logger logger = LogUtil.getLogger(); 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) { if (device == null || device.getDeviceConfig() == null) return new DeviceTrait[0]; @@ -62,10 +69,15 @@ public class DeviceTraitFactory { return new DeviceTrait[]{new SensorStateTrait(), new TemperatureControlTrait()}; 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 getTraitIds(DeviceTrait[] traits) { List list = new ArrayList<>(traits.length); diff --git a/plugins/hal-assistant-google/src/se/hal/plugin/assistant/google/type/DeviceType.java b/plugins/hal-assistant-google/src/se/hal/plugin/assistant/google/type/DeviceType.java index f0cc2317..3bf14901 100644 --- a/plugins/hal-assistant-google/src/se/hal/plugin/assistant/google/type/DeviceType.java +++ b/plugins/hal-assistant-google/src/se/hal/plugin/assistant/google/type/DeviceType.java @@ -50,6 +50,9 @@ package se.hal.plugin.assistant.google.type; import se.hal.intf.HalAbstractDevice; import se.hal.struct.Sensor; +import zutil.log.LogUtil; + +import java.util.logging.Logger; /** * Enum for https://developers.google.com/assistant/smarthome/types @@ -134,6 +137,8 @@ public enum DeviceType { YOGURTMAKER("action.devices.types.YOGURTMAKER"); + private static final Logger logger = LogUtil.getLogger(); + 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) { if (device == null || device.getDeviceConfig() == null) return null; @@ -163,7 +172,8 @@ public enum DeviceType { return SENSOR; 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; } } }