]> git.basschouten.com Git - openhab-addons.git/blob
8c833e5dd54acf00e7e388e4fa8e08b9640c61c6
[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.util.Map;
16 import java.util.concurrent.TimeUnit;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.openhab.core.thing.ChannelUID;
20 import org.openhab.core.thing.Thing;
21 import org.openhab.core.thing.ThingStatus;
22 import org.openhab.core.thing.ThingStatusDetail;
23
24 /**
25  * The {@link FreeDeviceIntf} defines some common methods for various devices (server, player, repeater) not belonging
26  * to the same class hierarchy
27  *
28  * @author GaĆ«l L'hopital - Initial contribution
29  */
30 @NonNullByDefault
31 public interface FreeDeviceIntf extends ApiConsumerIntf {
32     public ChannelUID getEventChannelUID();
33
34     public void triggerChannel(ChannelUID channelUID, String event);
35
36     default long checkUptimeAndFirmware(long newUptime, long oldUptime, String firmwareVersion) {
37         if (newUptime < oldUptime) {
38             triggerChannel(getEventChannelUID(), "restarted");
39             Map<String, String> properties = editProperties();
40             if (!firmwareVersion.equals(properties.get(Thing.PROPERTY_FIRMWARE_VERSION))) {
41                 properties.put(Thing.PROPERTY_FIRMWARE_VERSION, firmwareVersion);
42                 updateProperties(properties);
43                 triggerChannel(getEventChannelUID(), "firmware_updated");
44             }
45         }
46         return newUptime;
47     }
48
49     default void processReboot(Runnable actualReboot) {
50         triggerChannel(getEventChannelUID(), "reboot_requested");
51         actualReboot.run();
52         updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.DUTY_CYCLE, "System rebooting...");
53         stopJobs();
54         addJob("Initialize", this::initialize, 30, TimeUnit.SECONDS);
55     }
56 }