2 * Copyright (c) 2010-2022 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.lgwebos.internal;
15 import java.util.Optional;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.lgwebos.internal.handler.LGWebOSHandler;
20 import org.openhab.binding.lgwebos.internal.handler.command.ServiceSubscription;
21 import org.openhab.binding.lgwebos.internal.handler.core.CommandConfirmation;
22 import org.openhab.binding.lgwebos.internal.handler.core.ResponseListener;
23 import org.openhab.core.library.types.OnOffType;
24 import org.openhab.core.types.Command;
25 import org.openhab.core.types.RefreshType;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
30 * Handles TV Control Mute Command.
32 * @author Sebastian Prehn - initial contribution
35 public class VolumeControlMute extends BaseChannelHandler<Boolean> {
36 private final Logger logger = LoggerFactory.getLogger(VolumeControlMute.class);
38 private final ResponseListener<CommandConfirmation> objResponseListener = createResponseListener();
41 public void onReceiveCommand(String channelId, LGWebOSHandler handler, Command command) {
42 if (RefreshType.REFRESH == command) {
43 handler.getSocket().getMute(createResponseListener(channelId, handler));
44 } else if (OnOffType.ON == command || OnOffType.OFF == command) {
45 handler.getSocket().setMute(OnOffType.ON == command, objResponseListener);
47 logger.info("Only accept OnOffType, RefreshType. Type was {}.", command.getClass());
52 protected Optional<ServiceSubscription<Boolean>> getSubscription(String channelId, LGWebOSHandler handler) {
53 return Optional.of(handler.getSocket().subscribeMute(createResponseListener(channelId, handler)));
56 private ResponseListener<Boolean> createResponseListener(String channelId, LGWebOSHandler handler) {
57 return new ResponseListener<Boolean>() {
60 public void onError(@Nullable String error) {
61 logger.debug("Error in retrieving mute: {}.", error);
65 public void onSuccess(@Nullable Boolean value) {
69 handler.postUpdate(channelId, OnOffType.from(value));