2 * Copyright (c) 2010-2022 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.bmwconnecteddrive.internal.utils;
15 import java.util.EnumSet;
16 import java.util.List;
18 import java.util.Optional;
20 import java.util.stream.Collectors;
21 import java.util.stream.Stream;
23 import org.eclipse.jdt.annotation.NonNullByDefault;
24 import org.openhab.binding.bmwconnecteddrive.internal.handler.RemoteServiceHandler.RemoteService;
25 import org.openhab.core.types.StateOption;
28 * Helper class for Remote Service Commands
30 * @author Norbert Truchsess - Initial contribution
33 public class RemoteServiceUtils {
35 private static final Map<String, RemoteService> COMMAND_SERVICES = Stream.of(RemoteService.values())
36 .collect(Collectors.toUnmodifiableMap(RemoteService::getCommand, service -> service));
38 private static final Set<RemoteService> ELECTRIC_SERVICES = EnumSet.of(RemoteService.CHARGE_NOW,
39 RemoteService.CHARGING_CONTROL);
41 public static Optional<RemoteService> getRemoteService(final String command) {
42 return Optional.ofNullable(COMMAND_SERVICES.get(command));
45 public static List<StateOption> getOptions(final boolean isElectric) {
46 return Stream.of(RemoteService.values())
47 .filter(service -> isElectric ? true : !ELECTRIC_SERVICES.contains(service))
48 .map(service -> new StateOption(service.getCommand(), service.getLabel()))
49 .collect(Collectors.toUnmodifiableList());