[homeconnect] Retrieve list of programs when an appliance becomes available (#10773)
Cache the list of programs for an appliance Fix #10771 Signed-off-by: Laurent Garnier <lg.hc@free.fr>
This commit is contained in:
parent
4ad6eda961
commit
f99f4b6361
@ -80,6 +80,7 @@ public class HomeConnectApiClient {
|
|||||||
private final HttpClient client;
|
private final HttpClient client;
|
||||||
private final String apiUrl;
|
private final String apiUrl;
|
||||||
private final Map<String, List<AvailableProgramOption>> availableProgramOptionsCache;
|
private final Map<String, List<AvailableProgramOption>> availableProgramOptionsCache;
|
||||||
|
private final Map<String, List<AvailableProgram>> programsCache;
|
||||||
private final OAuthClientService oAuthClientService;
|
private final OAuthClientService oAuthClientService;
|
||||||
private final CircularQueue<ApiRequest> communicationQueue;
|
private final CircularQueue<ApiRequest> communicationQueue;
|
||||||
private final ApiBridgeConfiguration apiBridgeConfiguration;
|
private final ApiBridgeConfiguration apiBridgeConfiguration;
|
||||||
@ -91,6 +92,7 @@ public class HomeConnectApiClient {
|
|||||||
this.apiBridgeConfiguration = apiBridgeConfiguration;
|
this.apiBridgeConfiguration = apiBridgeConfiguration;
|
||||||
|
|
||||||
availableProgramOptionsCache = new ConcurrentHashMap<>();
|
availableProgramOptionsCache = new ConcurrentHashMap<>();
|
||||||
|
programsCache = new ConcurrentHashMap<>();
|
||||||
apiUrl = simulated ? API_SIMULATOR_BASE_URL : API_BASE_URL;
|
apiUrl = simulated ? API_SIMULATOR_BASE_URL : API_BASE_URL;
|
||||||
communicationQueue = new CircularQueue<>(COMMUNICATION_QUEUE_SIZE);
|
communicationQueue = new CircularQueue<>(COMMUNICATION_QUEUE_SIZE);
|
||||||
if (apiRequestHistory != null) {
|
if (apiRequestHistory != null) {
|
||||||
@ -610,7 +612,16 @@ public class HomeConnectApiClient {
|
|||||||
|
|
||||||
public List<AvailableProgram> getPrograms(String haId)
|
public List<AvailableProgram> getPrograms(String haId)
|
||||||
throws CommunicationException, AuthorizationException, ApplianceOfflineException {
|
throws CommunicationException, AuthorizationException, ApplianceOfflineException {
|
||||||
return getAvailablePrograms(haId, BASE_PATH + haId + "/programs");
|
List<AvailableProgram> programs;
|
||||||
|
if (programsCache.containsKey(haId)) {
|
||||||
|
logger.debug("Returning cached programs for '{}'.", haId);
|
||||||
|
programs = programsCache.get(haId);
|
||||||
|
programs = programs != null ? programs : Collections.emptyList();
|
||||||
|
} else {
|
||||||
|
programs = getAvailablePrograms(haId, BASE_PATH + haId + "/programs");
|
||||||
|
programsCache.put(haId, programs);
|
||||||
|
}
|
||||||
|
return programs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<AvailableProgram> getAvailablePrograms(String haId)
|
public List<AvailableProgram> getAvailablePrograms(String haId)
|
||||||
|
|||||||
@ -248,6 +248,7 @@ public abstract class AbstractHomeConnectThingHandler extends BaseThingHandler i
|
|||||||
} else if (isThingOffline() && !KEEP_ALIVE.equals(event.getType())) {
|
} else if (isThingOffline() && !KEEP_ALIVE.equals(event.getType())) {
|
||||||
updateStatus(ONLINE);
|
updateStatus(ONLINE);
|
||||||
logger.debug("Set {} to ONLINE and update channels. haId={}", getThing().getLabel(), getThingHaId());
|
logger.debug("Set {} to ONLINE and update channels. haId={}", getThing().getLabel(), getThingHaId());
|
||||||
|
updateSelectedProgramStateDescription();
|
||||||
updateChannels();
|
updateChannels();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user