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.mybmw.internal.utils;
15 import java.util.List;
17 import java.util.Optional;
18 import java.util.stream.Collectors;
19 import java.util.stream.Stream;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.openhab.binding.mybmw.internal.handler.enums.RemoteService;
23 import org.openhab.core.types.CommandOption;
26 * Helper class for Remote Service Commands
28 * @author Norbert Truchsess - Initial contribution
29 * @author Martin Grassl - small refactoring
32 public class RemoteServiceUtils {
34 private static final Map<String, RemoteService> COMMAND_SERVICES = Stream.of(RemoteService.values())
35 .collect(Collectors.toUnmodifiableMap(RemoteService::getId, service -> service));
37 public static Optional<RemoteService> getRemoteServiceFromCommand(final String command) {
38 return Optional.ofNullable(COMMAND_SERVICES.get(command));
41 public static List<CommandOption> getOptions(final boolean isElectric) {
42 return Stream.of(RemoteService.values()).map(service -> new CommandOption(service.getId(), service.getLabel()))
43 .collect(Collectors.toUnmodifiableList());