]> git.basschouten.com Git - openhab-addons.git/blob
f291199679a71da4e566752c9f361af9c583e654
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.freeboxos.internal.handler;
14
15 import java.math.BigDecimal;
16 import java.util.Map;
17 import java.util.concurrent.TimeUnit;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.binding.freeboxos.internal.config.ClientConfiguration;
22 import org.openhab.core.config.core.Configuration;
23 import org.openhab.core.thing.Thing;
24 import org.openhab.core.thing.ThingStatus;
25 import org.openhab.core.thing.ThingStatusDetail;
26 import org.openhab.core.thing.binding.ThingHandler;
27
28 import inet.ipaddr.MACAddressString;
29 import inet.ipaddr.mac.MACAddress;
30
31 /**
32  * The {@link ApiConsumerIntf} defines some common methods for various devices (server, player, repeater) not belonging
33  * to the same class hierarchy
34  *
35  * @author GaĆ«l L'hopital - Initial contribution
36  */
37 @NonNullByDefault
38 public interface ApiConsumerIntf extends ThingHandler {
39
40     Map<String, String> editProperties();
41
42     Configuration getConfig();
43
44     void updateProperties(@Nullable Map<String, String> properties);
45
46     void updateStatus(ThingStatus status, ThingStatusDetail statusDetail, @Nullable String description);
47
48     void stopJobs();
49
50     void addJob(String name, Runnable command, long initialDelay, long delay, TimeUnit unit);
51
52     void addJob(String name, Runnable command, long delay, TimeUnit unit);
53
54     default int getClientId() {
55         return ((BigDecimal) getConfig().get(ClientConfiguration.ID)).intValue();
56     }
57
58     default @Nullable MACAddress getMac() {
59         String mac = (String) getConfig().get(Thing.PROPERTY_MAC_ADDRESS);
60         if (mac == null) {
61             mac = editProperties().get(Thing.PROPERTY_MAC_ADDRESS);
62         }
63         return mac == null ? null : new MACAddressString(mac).getAddress();
64     }
65 }