]> git.basschouten.com Git - openhab-addons.git/blob
1969d53ef88f135cbe7560aed9f2539e7e2c7932
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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.bmwconnecteddrive.internal.utils;
14
15 import java.util.EnumSet;
16 import java.util.List;
17 import java.util.Map;
18 import java.util.Optional;
19 import java.util.Set;
20 import java.util.stream.Collectors;
21 import java.util.stream.Stream;
22
23 import org.eclipse.jdt.annotation.NonNullByDefault;
24 import org.openhab.binding.bmwconnecteddrive.internal.handler.RemoteServiceHandler.RemoteService;
25 import org.openhab.core.types.StateOption;
26
27 /**
28  * Helper class for Remote Service Commands
29  *
30  * @author Norbert Truchsess - Initial contribution
31  */
32 @NonNullByDefault
33 public class RemoteServiceUtils {
34
35     private static final Map<String, RemoteService> COMMAND_SERVICES = Stream.of(RemoteService.values())
36             .collect(Collectors.toUnmodifiableMap(RemoteService::getCommand, service -> service));
37
38     private static final Set<RemoteService> ELECTRIC_SERVICES = EnumSet.of(RemoteService.CHARGE_NOW,
39             RemoteService.CHARGING_CONTROL);
40
41     public static Optional<RemoteService> getRemoteService(final String command) {
42         return Optional.ofNullable(COMMAND_SERVICES.get(command));
43     }
44
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());
50     }
51 }