]> git.basschouten.com Git - openhab-addons.git/blob
0d919cb18e23d4f78667500f3bf983f13e6d8db2
[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.wundergroundupdatereceiver.internal;
14
15 import static org.openhab.binding.wundergroundupdatereceiver.internal.WundergroundUpdateReceiverBindingConstants.*;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.core.thing.Channel;
20 import org.openhab.core.thing.profiles.ProfileAdvisor;
21 import org.openhab.core.thing.profiles.ProfileTypeUID;
22 import org.openhab.core.thing.profiles.SystemProfiles;
23 import org.openhab.core.thing.type.ChannelType;
24 import org.openhab.core.thing.type.ChannelTypeUID;
25 import org.osgi.service.component.annotations.Component;
26
27 /**
28  * The {@link WundergroundUpdateReceiverProfileAdvisor} suggests the default profile for
29  * all channels except last updated.
30  *
31  * @author Daniel Demus - Initial contribution
32  */
33 @Component
34 @NonNullByDefault
35 public class WundergroundUpdateReceiverProfileAdvisor implements ProfileAdvisor {
36
37     @Override
38     public @Nullable ProfileTypeUID getSuggestedProfileTypeUID(Channel channel, @Nullable String itemType) {
39         return getSuggestedProfileTypeUID(channel.getChannelTypeUID());
40     }
41
42     @Override
43     public @Nullable ProfileTypeUID getSuggestedProfileTypeUID(ChannelType channelType, @Nullable String itemType) {
44         return getSuggestedProfileTypeUID(channelType.getUID());
45     }
46
47     private @Nullable ProfileTypeUID getSuggestedProfileTypeUID(@Nullable ChannelTypeUID channelTypeUID) {
48         if (channelTypeUID == null || !channelTypeUID.getBindingId().equals(BINDING_ID)) {
49             return null;
50         }
51         if (LAST_RECEIVED_DATETIME_CHANNELTYPEUID.equals(channelTypeUID)) {
52             return SystemProfiles.TIMESTAMP_UPDATE;
53         }
54         return SystemProfiles.DEFAULT;
55     }
56 }