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.CHANNEL_APP_CONTROL;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.lametrictime.internal.api.dto.CoreApps;
20 import org.openhab.binding.lametrictime.internal.api.local.ApplicationActionException;
21 import org.openhab.binding.lametrictime.internal.config.LaMetricTimeAppConfiguration;
22 import org.openhab.core.library.types.NextPreviousType;
23 import org.openhab.core.library.types.PlayPauseType;
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 RadioAppHandler} represents an instance of the built-in radio app.
35 * @author Gregory Moyer - Initial contribution
38 public class RadioAppHandler extends AbstractLaMetricTimeAppHandler {
39 private static final String PACKAGE_NAME = "com.lametric.radio";
41 private final Logger logger = LoggerFactory.getLogger(RadioAppHandler.class);
43 public RadioAppHandler(Thing thing) {
48 public void handleAppCommand(ChannelUID channelUID, Command command) {
50 switch (channelUID.getId()) {
51 case CHANNEL_APP_CONTROL:
52 handleControl(command);
53 updateActiveAppOnDevice();
56 logger.debug("Channel '{}' not supported", channelUID);
59 updateStatus(ThingStatus.ONLINE);
60 } catch (Exception e) {
61 logger.debug("Failed to perform action - taking app offline", e);
62 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
66 private void handleControl(final Command command) throws ApplicationActionException {
67 if (command instanceof PlayPauseType) {
68 switch ((PlayPauseType) command) {
76 logger.debug("{} command not supported by LaMetric Time Radio App", command);
81 if (command instanceof NextPreviousType) {
82 switch ((NextPreviousType) command) {
90 logger.debug("{} command not supported by LaMetric Time Radio App", command);
96 private void next() throws ApplicationActionException {
97 getDevice().doAction(getWidget(), CoreApps.radio().next());
100 private void play() throws ApplicationActionException {
101 getDevice().doAction(getWidget(), CoreApps.radio().play());
104 private void previous() throws ApplicationActionException {
105 getDevice().doAction(getWidget(), CoreApps.radio().previous());
108 private void stop() throws ApplicationActionException {
109 getDevice().doAction(getWidget(), CoreApps.radio().stop());
113 protected @Nullable String getPackageName(LaMetricTimeAppConfiguration config) {