2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.volvooncall.internal.api;
15 import java.util.concurrent.ScheduledExecutorService;
16 import java.util.concurrent.TimeUnit;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.openhab.binding.volvooncall.internal.VolvoOnCallException;
20 import org.openhab.binding.volvooncall.internal.VolvoOnCallException.ErrorType;
21 import org.openhab.binding.volvooncall.internal.dto.PostResponse;
22 import org.openhab.core.thing.binding.ThingHandler;
23 import org.openhab.core.types.RefreshType;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
28 * The {@link ActionResultController} is responsible for triggering information
29 * update after a post has been submitted to the webservice.
31 * @author Gaƫl L'hopital - Initial contribution
34 public class ActionResultController implements Runnable {
35 private final Logger logger = LoggerFactory.getLogger(ActionResultController.class);
37 private final VocHttpApi service;
38 private final ScheduledExecutorService scheduler;
39 private final PostResponse postResponse;
40 private final ThingHandler vehicle;
42 public ActionResultController(VocHttpApi service, PostResponse postResponse, ScheduledExecutorService scheduler,
43 ThingHandler vehicle) {
44 this.postResponse = postResponse;
45 this.service = service;
46 this.scheduler = scheduler;
47 this.vehicle = vehicle;
52 switch (postResponse.status) {
55 logger.debug("Action {} for vehicle {} resulted : {}.", postResponse.serviceType,
56 postResponse.vehicleId, postResponse.status);
57 vehicle.handleCommand(vehicle.getThing().getChannels().get(0).getUID(), RefreshType.REFRESH);
62 new ActionResultController(service,
63 service.getURL(postResponse.serviceURL, PostResponse.class), scheduler, vehicle),
64 10000, TimeUnit.MILLISECONDS);
65 } catch (VolvoOnCallException e) {
66 if (e.getType() == ErrorType.SERVICE_UNAVAILABLE) {
67 scheduler.schedule(this, 10000, TimeUnit.MILLISECONDS);