]> git.basschouten.com Git - openhab-addons.git/blob
29cc02a72464bbaf01049a14b2afd4f2bc138db3
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.mybmw.internal.utils;
14
15 import java.util.List;
16 import java.util.Map;
17 import java.util.Optional;
18 import java.util.stream.Collectors;
19 import java.util.stream.Stream;
20
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.openhab.binding.mybmw.internal.handler.enums.RemoteService;
23 import org.openhab.core.types.CommandOption;
24
25 /**
26  * Helper class for Remote Service Commands
27  *
28  * @author Norbert Truchsess - Initial contribution
29  * @author Martin Grassl - small refactoring
30  */
31 @NonNullByDefault
32 public class RemoteServiceUtils {
33
34     private static final Map<String, RemoteService> COMMAND_SERVICES = Stream.of(RemoteService.values())
35             .collect(Collectors.toUnmodifiableMap(RemoteService::getId, service -> service));
36
37     public static Optional<RemoteService> getRemoteServiceFromCommand(final String command) {
38         return Optional.ofNullable(COMMAND_SERVICES.get(command));
39     }
40
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());
44     }
45 }