forked from openhab/openhab-addons
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5751aeb
commit 9cbcde4
Showing
5 changed files
with
133 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...nding.boschshc/src/main/java/org/openhab/binding/boschshc/internal/LatestMotionState.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.openhab.binding.boschshc.internal; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
|
||
/** | ||
* { | ||
* "result": [ | ||
* { | ||
* "path": "/devices/hdm:ZigBee:000d6f0004b95a62/services/LatestMotion", | ||
* "@type": "DeviceServiceData", | ||
* "id": "LatestMotion", | ||
* "state": { | ||
* "latestMotionDetected": "2020-04-03T19:02:19.054Z", | ||
* "@type": "latestMotionState" | ||
* }, | ||
* "deviceId": "hdm:ZigBee:000d6f0004b95a62" | ||
* } | ||
* ], | ||
* "jsonrpc": "2.0" | ||
* } | ||
* | ||
*/ | ||
public class LatestMotionState { | ||
|
||
@SerializedName("@type") | ||
String type; | ||
|
||
String latestMotionDetected; | ||
} |
73 changes: 73 additions & 0 deletions
73
...g.boschshc/src/main/java/org/openhab/binding/boschshc/internal/MotionDetectorHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package org.openhab.binding.boschshc.internal; | ||
|
||
import static org.openhab.binding.boschshc.internal.BoschSHCBindingConstants.CHANNEL_LATEST_MOTION; | ||
|
||
import org.eclipse.jdt.annotation.NonNull; | ||
import org.eclipse.smarthome.core.library.types.DateTimeType; | ||
import org.eclipse.smarthome.core.thing.Bridge; | ||
import org.eclipse.smarthome.core.thing.ChannelUID; | ||
import org.eclipse.smarthome.core.thing.Thing; | ||
import org.eclipse.smarthome.core.thing.ThingStatus; | ||
import org.eclipse.smarthome.core.thing.ThingStatusDetail; | ||
import org.eclipse.smarthome.core.types.Command; | ||
import org.eclipse.smarthome.core.types.RefreshType; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonSyntaxException; | ||
|
||
public class MotionDetectorHandler extends BoschSHCHandler { | ||
private final Logger logger = LoggerFactory.getLogger(BoschSHCHandler.class); | ||
|
||
public MotionDetectorHandler(Thing thing) { | ||
super(thing); | ||
logger.warn("Creating motion detector thing: {}", thing.getLabel()); | ||
} | ||
|
||
@Override | ||
public void handleCommand(ChannelUID channelUID, Command command) { | ||
|
||
BoschSHCConfiguration config = super.getBoschConfig(); | ||
Bridge bridge = this.getBridge(); | ||
|
||
if (bridge != null && config != null) { | ||
|
||
logger.info("Handle command for: {} - {}", config.id, command); | ||
BoschSHCBridgeHandler bridgeHandler = (BoschSHCBridgeHandler) bridge.getHandler(); | ||
|
||
if (bridgeHandler != null) { | ||
|
||
if (CHANNEL_LATEST_MOTION.equals(channelUID.getId())) { | ||
if (command instanceof RefreshType) { | ||
|
||
// Refresh the temperature from the Bosch Twinguard device. | ||
// Might not be necessary, can just wait until we get one | ||
logger.warn("Refreshing the temperature is not yet supported."); | ||
} | ||
// Otherwise: not action supported here. | ||
} | ||
} | ||
} else { | ||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Bridge or config is NUL"); | ||
} | ||
} | ||
|
||
@Override | ||
public void processUpdate(String id, @NonNull JsonElement state) { | ||
logger.warn("Motion detector: received update: {} {}", id, state); | ||
Gson gson = new Gson(); | ||
|
||
try { | ||
LatestMotionState parsed = gson.fromJson(state, LatestMotionState.class); | ||
|
||
DateTimeType date = new DateTimeType(parsed.latestMotionDetected); | ||
logger.warn("Parsed date of latest motion to {}: {} as date {}", this.getBoschID(), parsed, date); | ||
updateState(CHANNEL_LATEST_MOTION, date); | ||
|
||
} catch (JsonSyntaxException e) { | ||
logger.warn("Received unknown update in in-wall switch: {}", state); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters