Skip to content
This repository has been archived by the owner on Nov 27, 2024. It is now read-only.

Commit

Permalink
[TapoCamera] added reconnect when encryption key is incorrect, added …
Browse files Browse the repository at this point in the history
…thing label for logging

Signed-off-by: Dmitry P. (d51x) <[email protected]>
  • Loading branch information
d51x committed Dec 24, 2023
1 parent 2be2c24 commit 62b2d8c
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ private void getSupportedFeatures(ModuleSpec moduleSpec) {
}

private Future<?> connectCamera(int wait) {
logger.warn("Try connect after: {} sec", wait);
logger.warn("{}: Try connect after: {} sec", thing.getLabel(), wait);
return scheduler.schedule(() -> {
updateStatus(ThingStatus.OFFLINE);
boolean thingReachable = deviceAuth();
Expand All @@ -319,10 +319,14 @@ private Future<?> connectCamera(int wait) {
}

private void reconnect() {
logger.debug("Try to reconnect");
reconnect("");
}

private void reconnect(@Nullable String message) {
logger.debug("{}: Try to reconnect", thing.getLabel());
cancelInitJob();
cancelPollingJob();
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR);
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, message);
initJob = connectCamera(config.reconnectInterval);
}

Expand All @@ -332,7 +336,7 @@ private Boolean deviceAuth() {
return api.auth(config.username, pass);
} catch (ApiException e) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
reconnect();
reconnect(e.getMessage());
throw new RuntimeException(e);
}
}
Expand Down Expand Up @@ -368,7 +372,7 @@ private Future<?> getCameraParameters(Integer interval) {
}

private void pollingCamera() {
logger.debug("get camera parameters");
logger.debug("{}: get camera parameters", thing.getLabel());
try {
if (!api.isAuth()) {
reconnect();
Expand All @@ -381,7 +385,9 @@ private void pollingCamera() {
}

} catch (Exception e) {
logger.error("Tapo Camera Exception: {}", e.getMessage());
logger.error("{}: Tapo Camera Exception: {}", thing.getLabel(), e.getMessage());
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
reconnect();
}
}

Expand Down Expand Up @@ -560,7 +566,7 @@ else if (data instanceof LastAlarmInfo) {
public @Nullable StateDescription getStateDescription(Channel channel, @Nullable StateDescription stateDescription,
@Nullable Locale locale) {
if (this.getThing().getChannel(CHANNEL_GOTO_PRESETS.getName()).equals(channel)) {
logger.debug("requested state for {}", channel.getUID());
logger.debug("{}: requested state for {}", thing.getLabel(), channel.getUID());
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public boolean supportsThingType(ThingTypeUID thingTypeUID) {
protected @Nullable ThingHandler createHandler(Thing thing) {
ThingTypeUID thingTypeUID = thing.getThingTypeUID();

TapoCameraApi api = apiFactory.getApi();
TapoCameraApi api = apiFactory.getApi(thing.getLabel());
if (THING_TYPE_CAMERA.equals(thingTypeUID)) {
return new TapoCameraHandler(thing, api);
} else if (THING_TYPE_BRIDGE.equals(thingTypeUID)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ public TapoCameraApiFactory() {
*
* @return the api
*/
public TapoCameraApi getApi() {
return new TapoCameraApiImpl(httpClient);
public TapoCameraApi getApi(String tag) {
return new TapoCameraApiImpl(httpClient, tag);
}

public TapoCameraCloudApi getCloudApi() {
Expand Down
Loading

0 comments on commit 62b2d8c

Please sign in to comment.