This repository has been archived by the owner on May 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 789
/
NtpDiscovery.java
98 lines (83 loc) · 3.2 KB
/
NtpDiscovery.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/**
* Copyright (c) 2014,2018 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.smarthome.binding.ntp.internal.discovery;
import static org.eclipse.smarthome.binding.ntp.NtpBindingConstants.*;
import java.util.HashMap;
import java.util.Map;
import java.util.TimeZone;
import java.util.concurrent.TimeUnit;
import org.eclipse.smarthome.config.discovery.AbstractDiscoveryService;
import org.eclipse.smarthome.config.discovery.DiscoveryResult;
import org.eclipse.smarthome.config.discovery.DiscoveryResultBuilder;
import org.eclipse.smarthome.config.discovery.DiscoveryService;
import org.eclipse.smarthome.core.i18n.LocaleProvider;
import org.eclipse.smarthome.core.i18n.TranslationProvider;
import org.eclipse.smarthome.core.thing.ThingUID;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
/**
*
* The {@link NtpDiscovery} is used to add a ntp Thing for the local time in the discovery inbox
* *
*
* @author Marcel Verpaalen - Initial contribution
*/
@Component(service = DiscoveryService.class, immediate = true, configurationPid = "discovery.ntp")
public class NtpDiscovery extends AbstractDiscoveryService {
public NtpDiscovery() throws IllegalArgumentException {
super(SUPPORTED_THING_TYPES_UIDS, 2);
}
@Override
protected void activate(Map<String, Object> configProperties) {
super.activate(configProperties);
}
@Override
protected void modified(Map<String, Object> configProperties) {
super.modified(configProperties);
}
@Override
protected void startBackgroundDiscovery() {
scheduler.schedule(() -> {
discoverNtp();
}, 1, TimeUnit.SECONDS);
}
@Override
protected void startScan() {
discoverNtp();
}
/**
* Add a ntp Thing for the local time in the discovery inbox
*/
private void discoverNtp() {
Map<String, Object> properties = new HashMap<>(4);
properties.put(PROPERTY_TIMEZONE, TimeZone.getDefault().getID());
ThingUID uid = new ThingUID(THING_TYPE_NTP, "local");
DiscoveryResult result = DiscoveryResultBuilder.create(uid).withProperties(properties).withLabel("Local Time")
.build();
thingDiscovered(result);
}
@Reference
protected void setLocaleProvider(final LocaleProvider localeProvider) {
this.localeProvider = localeProvider;
}
protected void unsetLocaleProvider(final LocaleProvider localeProvider) {
this.localeProvider = null;
}
@Reference
protected void setTranslationProvider(TranslationProvider i18nProvider) {
this.i18nProvider = i18nProvider;
}
protected void unsetTranslationProvider(TranslationProvider i18nProvider) {
this.i18nProvider = null;
}
}