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.openhab.binding.lametrictime.api.local.ApplicationActionException;
18 import org.openhab.binding.lametrictime.api.model.CoreApps;
19 import org.openhab.binding.lametrictime.internal.config.LaMetricTimeAppConfiguration;
20 import org.openhab.core.library.types.NextPreviousType;
21 import org.openhab.core.library.types.PlayPauseType;
22 import org.openhab.core.thing.ChannelUID;
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.types.Command;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
31 * The {@link RadioAppHandler} represents an instance of the built-in radio app.
33 * @author Gregory Moyer - Initial contribution
35 public class RadioAppHandler extends AbstractLaMetricTimeAppHandler {
36 private static final String PACKAGE_NAME = "com.lametric.radio";
38 private final Logger logger = LoggerFactory.getLogger(RadioAppHandler.class);
40 public RadioAppHandler(Thing thing) {
45 public void handleAppCommand(ChannelUID channelUID, Command command) {
47 switch (channelUID.getId()) {
48 case CHANNEL_APP_CONTROL:
49 handleControl(command);
50 updateActiveAppOnDevice();
53 logger.debug("Channel '{}' not supported", channelUID);
56 updateStatus(ThingStatus.ONLINE);
57 } catch (Exception e) {
58 logger.debug("Failed to perform action - taking app offline", e);
59 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
63 private void handleControl(final Command command) throws ApplicationActionException {
64 if (command instanceof PlayPauseType) {
65 switch ((PlayPauseType) command) {
73 logger.debug("{} command not supported by LaMetric Time Radio App", command);
78 if (command instanceof NextPreviousType) {
79 switch ((NextPreviousType) command) {
87 logger.debug("{} command not supported by LaMetric Time Radio App", command);
93 private void next() throws ApplicationActionException {
94 getDevice().doAction(getWidget(), CoreApps.radio().next());
97 private void play() throws ApplicationActionException {
98 getDevice().doAction(getWidget(), CoreApps.radio().play());
101 private void previous() throws ApplicationActionException {
102 getDevice().doAction(getWidget(), CoreApps.radio().previous());
105 private void stop() throws ApplicationActionException {
106 getDevice().doAction(getWidget(), CoreApps.radio().stop());
110 protected String getPackageName(LaMetricTimeAppConfiguration config) {