]> git.basschouten.com Git - openhab-addons.git/blob
2b9ff0807499162effdf6945b97445daf4652820
[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.RemoteServiceHandler.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  */
30 @NonNullByDefault
31 public class RemoteServiceUtils {
32
33     private static final Map<String, RemoteService> COMMAND_SERVICES = Stream.of(RemoteService.values())
34             .collect(Collectors.toUnmodifiableMap(RemoteService::getId, service -> service));
35
36     public static Optional<RemoteService> getRemoteService(final String command) {
37         return Optional.ofNullable(COMMAND_SERVICES.get(command));
38     }
39
40     public static List<CommandOption> getOptions(final boolean isElectric) {
41         return Stream.of(RemoteService.values()).map(service -> new CommandOption(service.getId(), service.getLabel()))
42                 .collect(Collectors.toUnmodifiableList());
43     }
44 }