-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Support for the Presence camera added * Files and thing types renamed because it handles now various camera types (not only the Welcome camera) * README updated to clarify the Welcome and Presence product names * Permission configurations renamed because it handles now various camera types (not only the Welcome camera) ; Reverted. Now it is separated, so the user has explicitly to decide if he wants to grant the access to outdoor cameras. * Camera channels separated to remove "welcome" from the (Presence) channel names. The channels of the Welcome camera were not renamed to be downward compatible. * welcomeHomeEvent channel removed for the Presence camera, event handling for the Presence will get realized later Signed-off-by: Sven Strohschein <[email protected]>
- Loading branch information
Showing
14 changed files
with
267 additions
and
97 deletions.
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
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
159 changes: 159 additions & 0 deletions
159
...ding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/camera/CameraHandler.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,159 @@ | ||
/** | ||
* Copyright (c) 2010-2020 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.binding.netatmo.internal.camera; | ||
|
||
import io.swagger.client.model.NAWelcomeCamera; | ||
import org.eclipse.jdt.annotation.NonNull; | ||
import org.eclipse.smarthome.core.library.types.StringType; | ||
import org.eclipse.smarthome.core.thing.Thing; | ||
import org.eclipse.smarthome.core.types.State; | ||
import org.eclipse.smarthome.core.types.UnDefType; | ||
import org.eclipse.smarthome.io.net.http.HttpUtil; | ||
import org.openhab.binding.netatmo.internal.handler.NetatmoModuleHandler; | ||
|
||
import static org.openhab.binding.netatmo.internal.ChannelTypeUtils.toOnOffType; | ||
import static org.openhab.binding.netatmo.internal.ChannelTypeUtils.toStringType; | ||
import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*; | ||
|
||
/** | ||
* {@link CameraHandler} is the class used to handle Camera Data | ||
* | ||
* @author Sven Strohschein (partly moved code from NAWelcomeCameraHandler to introduce inheritance, see NAWelcomeCameraHandler) | ||
* | ||
*/ | ||
public class CameraHandler extends NetatmoModuleHandler<NAWelcomeCamera> { | ||
|
||
private static final String LIVE_PICTURE = "/live/snapshot_720.jpg"; | ||
|
||
public CameraHandler(@NonNull Thing thing) { | ||
super(thing); | ||
} | ||
|
||
@Override | ||
protected void updateProperties(NAWelcomeCamera moduleData) { | ||
updateProperties(null, moduleData.getType()); | ||
} | ||
|
||
@SuppressWarnings("null") | ||
@Override | ||
protected State getNAThingProperty(String channelId) { | ||
switch (channelId) { | ||
case CHANNEL_CAMERA_STATUS: | ||
return getStatusState(); | ||
case CHANNEL_CAMERA_SDSTATUS: | ||
return getSdStatusState(); | ||
case CHANNEL_CAMERA_ALIMSTATUS: | ||
return getAlimStatusState(); | ||
case CHANNEL_CAMERA_ISLOCAL: | ||
return getIsLocalState(); | ||
case CHANNEL_CAMERA_LIVEPICTURE_URL: | ||
return getLivePictureURLState(); | ||
case CHANNEL_CAMERA_LIVEPICTURE: | ||
return getLivePictureState(); | ||
case CHANNEL_CAMERA_LIVESTREAM_URL: | ||
return getLiveStreamState(); | ||
} | ||
return super.getNAThingProperty(channelId); | ||
} | ||
|
||
protected State getStatusState() { | ||
return module != null ? toOnOffType(module.getStatus()) : UnDefType.UNDEF; | ||
} | ||
|
||
protected State getSdStatusState() { | ||
return module != null ? toOnOffType(module.getSdStatus()) : UnDefType.UNDEF; | ||
} | ||
|
||
protected State getAlimStatusState() { | ||
return module != null ? toOnOffType(module.getAlimStatus()) : UnDefType.UNDEF; | ||
} | ||
|
||
protected State getIsLocalState() { | ||
return module != null ? toOnOffType(module.getIsLocal()) : UnDefType.UNDEF; | ||
} | ||
|
||
protected State getLivePictureURLState() { | ||
String livePictureURL = getLivePictureURL(); | ||
return livePictureURL == null ? UnDefType.UNDEF : toStringType(livePictureURL); | ||
} | ||
|
||
protected State getLivePictureState() { | ||
String livePictureURL = getLivePictureURL(); | ||
return livePictureURL == null ? UnDefType.UNDEF : HttpUtil.downloadImage(livePictureURL); | ||
} | ||
|
||
protected State getLiveStreamState() { | ||
String liveStreamURL = getLiveStreamURL(); | ||
return liveStreamURL == null ? UnDefType.UNDEF : new StringType(liveStreamURL); | ||
} | ||
|
||
/** | ||
* Get the url for the live snapshot | ||
* | ||
* @return Url of the live snapshot | ||
*/ | ||
private String getLivePictureURL() { | ||
String result = getVpnUrl(); | ||
if (result != null) { | ||
result += LIVE_PICTURE; | ||
} | ||
return result; | ||
} | ||
|
||
/** | ||
* Get the url for the live stream depending wether local or not | ||
* | ||
* @return Url of the live stream | ||
*/ | ||
private String getLiveStreamURL() { | ||
String result = getVpnUrl(); | ||
if (result == null) { | ||
return null; | ||
} | ||
|
||
StringBuilder resultStringBuilder = new StringBuilder(result); | ||
resultStringBuilder.append("/live/index"); | ||
if(isLocal()) { | ||
resultStringBuilder.append("_local"); | ||
} | ||
resultStringBuilder.append(".m3u8"); | ||
return resultStringBuilder.toString(); | ||
} | ||
|
||
@SuppressWarnings("null") | ||
private String getVpnUrl() { | ||
return (module == null) ? null : module.getVpnUrl(); | ||
} | ||
|
||
public String getStreamURL(String videoId) { | ||
String result = getVpnUrl(); | ||
if(result == null) { | ||
return null; | ||
} | ||
|
||
StringBuilder resultStringBuilder = new StringBuilder(result); | ||
resultStringBuilder.append("/vod/"); | ||
resultStringBuilder.append(videoId); | ||
resultStringBuilder.append("/index"); | ||
if(isLocal()) { | ||
resultStringBuilder.append("_local"); | ||
} | ||
resultStringBuilder.append(".m3u8"); | ||
return resultStringBuilder.toString(); | ||
} | ||
|
||
@SuppressWarnings("null") | ||
private boolean isLocal() { | ||
return (module == null || module.getIsLocal() == null) ? false : module.getIsLocal(); | ||
} | ||
} |
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
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
Oops, something went wrong.