[tr064] fix fritz.box lookup (#9454)

Signed-off-by: Jan N. Klug <jan.n.klug@rub.de>
This commit is contained in:
J-N-K
2020-12-23 04:19:37 +01:00
committed by GitHub
parent f29d405837
commit 22ac639233
2 changed files with 10 additions and 3 deletions

View File

@@ -65,7 +65,7 @@ public class Tr064HandlerFactory extends BaseThingHandlerFactory {
this.channelTypeProvider = channelTypeProvider; this.channelTypeProvider = channelTypeProvider;
this.phonebookProfileFactory = phonebookProfileFactory; this.phonebookProfileFactory = phonebookProfileFactory;
// use an insecure client (i.e. without verifying the certificate) // use an insecure client (i.e. without verifying the certificate)
this.httpClient = new HttpClient(new SslContextFactory(true)); this.httpClient = new HttpClient(new SslContextFactory.Client(true));
try { try {
this.httpClient.start(); this.httpClient.start();
} catch (Exception e) { } catch (Exception e) {

View File

@@ -76,7 +76,7 @@ public class Tr064RootHandler extends BaseBridgeHandler implements PhonebookProv
private @Nullable SCPDUtil scpdUtil; private @Nullable SCPDUtil scpdUtil;
private SOAPConnector soapConnector; private SOAPConnector soapConnector;
private String endpointBaseURL = "http://fritz.box:49000"; private String endpointBaseURL = "";
private final Map<ChannelUID, Tr064ChannelConfig> channels = new HashMap<>(); private final Map<ChannelUID, Tr064ChannelConfig> channels = new HashMap<>();
// caching is used to prevent excessive calls to the same action // caching is used to prevent excessive calls to the same action
@@ -87,14 +87,19 @@ public class Tr064RootHandler extends BaseBridgeHandler implements PhonebookProv
private @Nullable ScheduledFuture<?> pollFuture; private @Nullable ScheduledFuture<?> pollFuture;
private @Nullable ScheduledFuture<?> phonebookFuture; private @Nullable ScheduledFuture<?> phonebookFuture;
private boolean communicationEstablished = false;
Tr064RootHandler(Bridge bridge, HttpClient httpClient) { Tr064RootHandler(Bridge bridge, HttpClient httpClient) {
super(bridge); super(bridge);
this.httpClient = httpClient; this.httpClient = httpClient;
soapConnector = new SOAPConnector(httpClient, endpointBaseURL); this.soapConnector = new SOAPConnector(httpClient, endpointBaseURL);
} }
@Override @Override
public void handleCommand(ChannelUID channelUID, Command command) { public void handleCommand(ChannelUID channelUID, Command command) {
if (!communicationEstablished) {
logger.debug("Tried to process command, but thing is not yet ready: {} to {}", channelUID, command);
}
Tr064ChannelConfig channelConfig = channels.get(channelUID); Tr064ChannelConfig channelConfig = channels.get(channelUID);
if (channelConfig == null) { if (channelConfig == null) {
logger.trace("Channel {} not supported.", channelUID); logger.trace("Channel {} not supported.", channelUID);
@@ -157,6 +162,7 @@ public class Tr064RootHandler extends BaseBridgeHandler implements PhonebookProv
updateThing(thingBuilder.build()); updateThing(thingBuilder.build());
} }
communicationEstablished = true;
installPolling(); installPolling();
updateStatus(ThingStatus.ONLINE, ThingStatusDetail.NONE); updateStatus(ThingStatus.ONLINE, ThingStatusDetail.NONE);
} }
@@ -172,6 +178,7 @@ public class Tr064RootHandler extends BaseBridgeHandler implements PhonebookProv
@Override @Override
public void dispose() { public void dispose() {
communicationEstablished = false;
removeConnectScheduler(); removeConnectScheduler();
uninstallPolling(); uninstallPolling();
stateCache.clear(); stateCache.clear();