From ce00a69db7231ec2baf7a036d4897d6aef6ff529 Mon Sep 17 00:00:00 2001 From: rschoene <rene.schoene@tu-dresden.de> Date: Wed, 23 May 2018 15:31:52 +0200 Subject: [PATCH] Separate different smartwatches. --- .../binding/openlicht/BindingConstants.java | 5 ++-- ...er.java => AbstractSmartWatchHandler.java} | 8 +++---- ...er.java => AbstractSmartphoneHandler.java} | 8 +++---- .../openlicht/handler/Moto360Handler.java | 12 ++++++++++ .../openlicht/handler/PolarM600Handler.java | 12 ++++++++++ .../openlicht/handler/SamsungS6Handler.java | 12 ++++++++++ .../internal/OpenLichtHandlerFactory.java | 24 +++++++++---------- 7 files changed, 59 insertions(+), 22 deletions(-) rename src/main/java/org/openhab/binding/openlicht/handler/{PolarHandler.java => AbstractSmartWatchHandler.java} (91%) rename src/main/java/org/openhab/binding/openlicht/handler/{SmartphoneHandler.java => AbstractSmartphoneHandler.java} (87%) create mode 100644 src/main/java/org/openhab/binding/openlicht/handler/Moto360Handler.java create mode 100644 src/main/java/org/openhab/binding/openlicht/handler/PolarM600Handler.java create mode 100644 src/main/java/org/openhab/binding/openlicht/handler/SamsungS6Handler.java diff --git a/src/main/java/org/openhab/binding/openlicht/BindingConstants.java b/src/main/java/org/openhab/binding/openlicht/BindingConstants.java index 974b723..0327eb5 100644 --- a/src/main/java/org/openhab/binding/openlicht/BindingConstants.java +++ b/src/main/java/org/openhab/binding/openlicht/BindingConstants.java @@ -32,8 +32,9 @@ public class BindingConstants { // List of all Thing Type UIDs public static final ThingTypeUID THING_TYPE_SKYWRITER_HAT = new ThingTypeUID(BINDING_ID, "skywriter-hat"); - public static final ThingTypeUID THING_TYPE_POLAR = new ThingTypeUID(BINDING_ID, "polar-m600"); - public static final ThingTypeUID THING_TYPE_SMARTPHONE = new ThingTypeUID(BINDING_ID, "samsung-s6"); + public static final ThingTypeUID THING_TYPE_POLAR_M600 = new ThingTypeUID(BINDING_ID, "polar-m600"); + public static final ThingTypeUID THING_TYPE_MOTO_360 = new ThingTypeUID(BINDING_ID, "moto-360"); + public static final ThingTypeUID THING_TYPE_SAMSUNG_S6 = new ThingTypeUID(BINDING_ID, "samsung-s6"); // List of all Channel ids public static final String CHANNEL_FLICK = "flick"; diff --git a/src/main/java/org/openhab/binding/openlicht/handler/PolarHandler.java b/src/main/java/org/openhab/binding/openlicht/handler/AbstractSmartWatchHandler.java similarity index 91% rename from src/main/java/org/openhab/binding/openlicht/handler/PolarHandler.java rename to src/main/java/org/openhab/binding/openlicht/handler/AbstractSmartWatchHandler.java index e7cd7ad..69c1724 100644 --- a/src/main/java/org/openhab/binding/openlicht/handler/PolarHandler.java +++ b/src/main/java/org/openhab/binding/openlicht/handler/AbstractSmartWatchHandler.java @@ -27,18 +27,18 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * The {@link PolarHandler} is responsible for handling commands, which are + * The {@link AbstractSmartWatchHandler} is responsible for handling commands, which are * sent to one of the channels. * * @author René Schöne - Initial contribution */ -public class PolarHandler extends AbstractMqttHandler { +public abstract class AbstractSmartWatchHandler extends AbstractMqttHandler { - private final Logger logger = LoggerFactory.getLogger(PolarHandler.class); + private final Logger logger = LoggerFactory.getLogger(AbstractSmartWatchHandler.class); private Set<String> seenUnsupportedCategories; - public PolarHandler(Thing thing, MqttService mqttService) { + public AbstractSmartWatchHandler(Thing thing, MqttService mqttService) { super(thing, mqttService); seenUnsupportedCategories = new HashSet<>(); } diff --git a/src/main/java/org/openhab/binding/openlicht/handler/SmartphoneHandler.java b/src/main/java/org/openhab/binding/openlicht/handler/AbstractSmartphoneHandler.java similarity index 87% rename from src/main/java/org/openhab/binding/openlicht/handler/SmartphoneHandler.java rename to src/main/java/org/openhab/binding/openlicht/handler/AbstractSmartphoneHandler.java index e5b3155..8f92840 100644 --- a/src/main/java/org/openhab/binding/openlicht/handler/SmartphoneHandler.java +++ b/src/main/java/org/openhab/binding/openlicht/handler/AbstractSmartphoneHandler.java @@ -26,18 +26,18 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * The {@link SmartphoneHandler} is responsible for handling commands, which are + * The {@link AbstractSmartphoneHandler} is responsible for handling commands, which are * sent to one of the channels. * * @author René Schöne - Initial contribution */ -public class SmartphoneHandler extends AbstractMqttHandler { +public abstract class AbstractSmartphoneHandler extends AbstractMqttHandler { - private final Logger logger = LoggerFactory.getLogger(SmartphoneHandler.class); + private final Logger logger = LoggerFactory.getLogger(AbstractSmartphoneHandler.class); private Set<String> seenUnsupportedCategories; - public SmartphoneHandler(Thing thing, MqttService mqttService) { + public AbstractSmartphoneHandler(Thing thing, MqttService mqttService) { super(thing, mqttService); seenUnsupportedCategories = new HashSet<>(); } diff --git a/src/main/java/org/openhab/binding/openlicht/handler/Moto360Handler.java b/src/main/java/org/openhab/binding/openlicht/handler/Moto360Handler.java new file mode 100644 index 0000000..4d5a57c --- /dev/null +++ b/src/main/java/org/openhab/binding/openlicht/handler/Moto360Handler.java @@ -0,0 +1,12 @@ +package org.openhab.binding.openlicht.handler; + +import org.eclipse.smarthome.core.thing.Thing; +import org.eclipse.smarthome.io.transport.mqtt.MqttService; + +public class Moto360Handler extends AbstractSmartWatchHandler { + + public Moto360Handler(Thing thing, MqttService mqttService) { + super(thing, mqttService); + } + +} diff --git a/src/main/java/org/openhab/binding/openlicht/handler/PolarM600Handler.java b/src/main/java/org/openhab/binding/openlicht/handler/PolarM600Handler.java new file mode 100644 index 0000000..934d399 --- /dev/null +++ b/src/main/java/org/openhab/binding/openlicht/handler/PolarM600Handler.java @@ -0,0 +1,12 @@ +package org.openhab.binding.openlicht.handler; + +import org.eclipse.smarthome.core.thing.Thing; +import org.eclipse.smarthome.io.transport.mqtt.MqttService; + +public class PolarM600Handler extends AbstractSmartWatchHandler { + + public PolarM600Handler(Thing thing, MqttService mqttService) { + super(thing, mqttService); + } + +} diff --git a/src/main/java/org/openhab/binding/openlicht/handler/SamsungS6Handler.java b/src/main/java/org/openhab/binding/openlicht/handler/SamsungS6Handler.java new file mode 100644 index 0000000..6a8eb3a --- /dev/null +++ b/src/main/java/org/openhab/binding/openlicht/handler/SamsungS6Handler.java @@ -0,0 +1,12 @@ +package org.openhab.binding.openlicht.handler; + +import org.eclipse.smarthome.core.thing.Thing; +import org.eclipse.smarthome.io.transport.mqtt.MqttService; + +public class SamsungS6Handler extends AbstractSmartphoneHandler { + + public SamsungS6Handler(Thing thing, MqttService mqttService) { + super(thing, mqttService); + } + +} diff --git a/src/main/java/org/openhab/binding/openlicht/internal/OpenLichtHandlerFactory.java b/src/main/java/org/openhab/binding/openlicht/internal/OpenLichtHandlerFactory.java index 315b3ec..5ef4ad1 100644 --- a/src/main/java/org/openhab/binding/openlicht/internal/OpenLichtHandlerFactory.java +++ b/src/main/java/org/openhab/binding/openlicht/internal/OpenLichtHandlerFactory.java @@ -27,9 +27,10 @@ import org.eclipse.smarthome.core.thing.binding.BaseThingHandlerFactory; import org.eclipse.smarthome.core.thing.binding.ThingHandler; import org.eclipse.smarthome.core.thing.binding.ThingHandlerFactory; import org.eclipse.smarthome.io.transport.mqtt.MqttService; -import org.openhab.binding.openlicht.handler.PolarHandler; +import org.openhab.binding.openlicht.handler.Moto360Handler; +import org.openhab.binding.openlicht.handler.PolarM600Handler; +import org.openhab.binding.openlicht.handler.SamsungS6Handler; import org.openhab.binding.openlicht.handler.SkyWriterHATHandler; -import org.openhab.binding.openlicht.handler.SmartphoneHandler; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; import org.osgi.service.component.annotations.ReferenceCardinality; @@ -47,7 +48,8 @@ import org.slf4j.LoggerFactory; public class OpenLichtHandlerFactory extends BaseThingHandlerFactory { private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.unmodifiableSet( - Stream.of(THING_TYPE_SKYWRITER_HAT, THING_TYPE_POLAR, THING_TYPE_SMARTPHONE).collect(Collectors.toSet())); + Stream.of(THING_TYPE_SKYWRITER_HAT, THING_TYPE_POLAR_M600, THING_TYPE_MOTO_360, THING_TYPE_SAMSUNG_S6) + .collect(Collectors.toSet())); private @Nullable MqttService service; @Override @@ -55,11 +57,6 @@ public class OpenLichtHandlerFactory extends BaseThingHandlerFactory { return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID); } - // @Override - // protected void activate(ComponentContext componentContext) { - // super.activate(componentContext); - // }; - @Override protected @Nullable ThingHandler createHandler(Thing thing) { ThingTypeUID thingTypeUID = thing.getThingTypeUID(); @@ -67,11 +64,14 @@ public class OpenLichtHandlerFactory extends BaseThingHandlerFactory { if (THING_TYPE_SKYWRITER_HAT.equals(thingTypeUID)) { return new SkyWriterHATHandler(thing, this.service); } - if (THING_TYPE_POLAR.equals(thingTypeUID)) { - return new PolarHandler(thing, this.service); + if (THING_TYPE_POLAR_M600.equals(thingTypeUID)) { + return new PolarM600Handler(thing, this.service); + } + if (THING_TYPE_MOTO_360.equals(thingTypeUID)) { + return new Moto360Handler(thing, this.service); } - if (THING_TYPE_SMARTPHONE.equals(thingTypeUID)) { - return new SmartphoneHandler(thing, this.service); + if (THING_TYPE_SAMSUNG_S6.equals(thingTypeUID)) { + return new SamsungS6Handler(thing, this.service); } return null; -- GitLab