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.openhab.binding.lametrictime.api.local.ApplicationActionException;
20 import org.openhab.binding.lametrictime.api.model.CoreApps;
21 import org.openhab.binding.lametrictime.internal.config.LaMetricTimeAppConfiguration;
22 import org.openhab.core.library.types.DateTimeType;
23 import org.openhab.core.library.types.StringType;
24 import org.openhab.core.thing.ChannelUID;
25 import org.openhab.core.thing.Thing;
26 import org.openhab.core.thing.ThingStatus;
27 import org.openhab.core.thing.ThingStatusDetail;
28 import org.openhab.core.types.Command;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
33 * The {@link ClockAppHandler} represents an instance of the built-in clock app.
35 * @author Gregory Moyer - Initial contribution
37 public class ClockAppHandler extends AbstractLaMetricTimeAppHandler {
38 private static final String PACKAGE_NAME = "com.lametric.clock";
40 public static final String COMMAND_DISABLE_ALARM = "disableAlarm";
42 private final Logger logger = LoggerFactory.getLogger(ClockAppHandler.class);
44 public ClockAppHandler(Thing thing) {
49 public void handleAppCommand(ChannelUID channelUID, Command command) {
51 switch (channelUID.getId()) {
52 case CHANNEL_APP_SET_ALARM: {
53 LocalTime time = ((DateTimeType) command).getZonedDateTime().toLocalTime();
54 getDevice().doAction(getWidget(), CoreApps.clock().setAlarm(true, time, null));
55 updateActiveAppOnDevice();
58 case CHANNEL_APP_COMMAND:
59 handleCommandChannel(command);
60 updateState(channelUID, new StringType()); // clear state
61 updateActiveAppOnDevice();
64 logger.debug("Channel '{}' not supported", channelUID);
67 updateStatus(ThingStatus.ONLINE);
68 } catch (Exception e) {
69 logger.debug("Failed to perform action - taking app offline", e);
70 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
75 protected String getPackageName(LaMetricTimeAppConfiguration config) {
79 private void handleCommandChannel(Command command) throws ApplicationActionException {
80 String commandStr = command.toFullString();
82 case COMMAND_DISABLE_ALARM:
83 getDevice().doAction(getWidget(), CoreApps.clock().stopAlarm());
86 logger.debug("Clock app command '{}' not supported", commandStr);