@Override
  public void initialize() {

    logger.trace("Initializing the Tesla handler for {}", getThing().getUID());

    connect();

    if (getThing().getStatus() == ThingStatus.ONLINE) {

      if (eventJob == null || eventJob.isCancelled()) {
        eventJob =
            scheduler.scheduleAtFixedRate(
                eventRunnable, 0, EVENT_REFRESH_INTERVAL, TimeUnit.MILLISECONDS);
      }

      Map<Object, Rate> channels = new HashMap<Object, Rate>();
      channels.put(TESLA_DATA_THROTTLE, new Rate(10, 10, TimeUnit.SECONDS));
      channels.put(TESLA_COMMAND_THROTTLE, new Rate(20, 1, TimeUnit.MINUTES));

      Rate firstRate = new Rate(20, 1, TimeUnit.MINUTES);
      Rate secondRate = new Rate(200, 10, TimeUnit.MINUTES);
      stateThrottler = new QueueChannelThrottler(firstRate, scheduler, channels);
      stateThrottler.addRate(secondRate);

      if (fastStateJob == null || fastStateJob.isCancelled()) {
        fastStateJob =
            scheduler.scheduleWithFixedDelay(
                fastStateRunnable, 0, FAST_STATUS_REFRESH_INTERVAL, TimeUnit.MILLISECONDS);
      }

      if (slowStateJob == null || slowStateJob.isCancelled()) {
        slowStateJob =
            scheduler.scheduleWithFixedDelay(
                slowStateRunnable, 0, SLOW_STATUS_REFRESH_INTERVAL, TimeUnit.MILLISECONDS);
      }
    }
  }
 public void requestData(String command, String payLoad) {
   Request request = new Request(command, payLoad, dataRequestTarget);
   if (stateThrottler != null) {
     stateThrottler.submit(TESLA_DATA_THROTTLE, request);
   }
 }
 public void sendCommand(String command, WebTarget target) {
   Request request = new Request(command, "{}", target);
   if (stateThrottler != null) {
     stateThrottler.submit(TESLA_COMMAND_THROTTLE, request);
   }
 }
 public void sendCommand(String command, String payLoad) {
   Request request = new Request(command, payLoad, commandTarget);
   if (stateThrottler != null) {
     stateThrottler.submit(TESLA_COMMAND_THROTTLE, request);
   }
 }