2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.lametrictime.internal.handler;
15 import static org.openhab.binding.lametrictime.internal.LaMetricTimeBindingConstants.*;
17 import java.time.LocalTime;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.binding.lametrictime.internal.api.dto.CoreApps;
22 import org.openhab.binding.lametrictime.internal.api.local.ApplicationActionException;
23 import org.openhab.binding.lametrictime.internal.config.LaMetricTimeAppConfiguration;
24 import org.openhab.core.library.types.DateTimeType;
25 import org.openhab.core.library.types.StringType;
26 import org.openhab.core.thing.ChannelUID;
27 import org.openhab.core.thing.Thing;
28 import org.openhab.core.thing.ThingStatus;
29 import org.openhab.core.thing.ThingStatusDetail;
30 import org.openhab.core.types.Command;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
35 * The {@link ClockAppHandler} represents an instance of the built-in clock app.
37 * @author Gregory Moyer - Initial contribution
40 public class ClockAppHandler extends AbstractLaMetricTimeAppHandler {
41 private static final String PACKAGE_NAME = "com.lametric.clock";
43 public static final String COMMAND_DISABLE_ALARM = "disableAlarm";
45 private final Logger logger = LoggerFactory.getLogger(ClockAppHandler.class);
47 public ClockAppHandler(Thing thing) {
52 public void handleAppCommand(ChannelUID channelUID, Command command) {
54 switch (channelUID.getId()) {
55 case CHANNEL_APP_SET_ALARM: {
56 LocalTime time = ((DateTimeType) command).getZonedDateTime().toLocalTime();
57 getDevice().doAction(getWidget(), CoreApps.clock().setAlarm(true, time, null));
58 updateActiveAppOnDevice();
61 case CHANNEL_APP_COMMAND:
62 handleCommandChannel(command);
63 updateState(channelUID, new StringType()); // clear state
64 updateActiveAppOnDevice();
67 logger.debug("Channel '{}' not supported", channelUID);
70 updateStatus(ThingStatus.ONLINE);
71 } catch (Exception e) {
72 logger.debug("Failed to perform action - taking app offline", e);
73 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
78 protected @Nullable String getPackageName(LaMetricTimeAppConfiguration config) {
82 private void handleCommandChannel(Command command) throws ApplicationActionException {
83 String commandStr = command.toFullString();
85 case COMMAND_DISABLE_ALARM:
86 getDevice().doAction(getWidget(), CoreApps.clock().stopAlarm());
89 logger.debug("Clock app command '{}' not supported", commandStr);