2 * Copyright (c) 2010-2024 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.io.homekit.internal.accessories;
15 import java.util.List;
16 import java.util.concurrent.CompletableFuture;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.openhab.io.homekit.internal.HomekitAccessoryUpdater;
20 import org.openhab.io.homekit.internal.HomekitException;
21 import org.openhab.io.homekit.internal.HomekitSettings;
22 import org.openhab.io.homekit.internal.HomekitTaggedItem;
24 import io.github.hapjava.characteristics.impl.common.ActiveCharacteristic;
25 import io.github.hapjava.characteristics.impl.common.ActiveIdentifierCharacteristic;
26 import io.github.hapjava.characteristics.impl.common.ConfiguredNameCharacteristic;
27 import io.github.hapjava.characteristics.impl.lightbulb.BrightnessCharacteristic;
28 import io.github.hapjava.characteristics.impl.television.ClosedCaptionsCharacteristic;
29 import io.github.hapjava.characteristics.impl.television.CurrentMediaStateCharacteristic;
30 import io.github.hapjava.characteristics.impl.television.PictureModeCharacteristic;
31 import io.github.hapjava.characteristics.impl.television.PowerModeCharacteristic;
32 import io.github.hapjava.characteristics.impl.television.RemoteKeyCharacteristic;
33 import io.github.hapjava.characteristics.impl.television.SleepDiscoveryModeCharacteristic;
34 import io.github.hapjava.characteristics.impl.television.SleepDiscoveryModeEnum;
35 import io.github.hapjava.characteristics.impl.television.TargetMediaStateCharacteristic;
36 import io.github.hapjava.services.impl.TelevisionService;
39 * Implements Television
41 * This is a little different in that we don't implement the accessory interface.
42 * This is because several of the "mandatory" characteristics we don't require,
43 * and wait until all optional attributes are added and if they don't exist
44 * it will create "default" values for them.
46 * @author Cody Cutrer - Initial contribution
49 public class HomekitTelevisionImpl extends AbstractHomekitAccessoryImpl {
51 public HomekitTelevisionImpl(HomekitTaggedItem taggedItem, List<HomekitTaggedItem> mandatoryCharacteristics,
52 HomekitAccessoryUpdater updater, HomekitSettings settings) throws IncompleteAccessoryException {
53 super(taggedItem, mandatoryCharacteristics, updater, settings);
57 public void init() throws HomekitException {
60 // these charactereristics are technically mandatory, but we provide defaults if they're not provided
61 var activeIdentifierCharacteristic = getCharacteristic(ActiveIdentifierCharacteristic.class)
62 .orElseGet(() -> new ActiveIdentifierCharacteristic(() -> CompletableFuture.completedFuture(1), v -> {
66 var configuredNameCharacteristic = getCharacteristic(ConfiguredNameCharacteristic.class)
67 .orElseGet(() -> new ConfiguredNameCharacteristic(() -> getName(), v -> {
71 var remoteKeyCharacteristic = getCharacteristic(RemoteKeyCharacteristic.class)
72 .orElseGet(() -> new RemoteKeyCharacteristic((v) -> {
74 var sleepDiscoveryModeCharacteristic = getCharacteristic(SleepDiscoveryModeCharacteristic.class)
75 .orElseGet(() -> new SleepDiscoveryModeCharacteristic(
76 () -> CompletableFuture.completedFuture(SleepDiscoveryModeEnum.ALWAYS_DISCOVERABLE), v -> {
80 var service = new TelevisionService(getCharacteristic(ActiveCharacteristic.class).get(),
81 activeIdentifierCharacteristic, configuredNameCharacteristic, remoteKeyCharacteristic,
82 sleepDiscoveryModeCharacteristic);
84 getCharacteristic(BrightnessCharacteristic.class).ifPresent(c -> service.addOptionalCharacteristic(c));
85 getCharacteristic(PowerModeCharacteristic.class).ifPresent(c -> service.addOptionalCharacteristic(c));
86 getCharacteristic(ClosedCaptionsCharacteristic.class).ifPresent(c -> service.addOptionalCharacteristic(c));
87 getCharacteristic(CurrentMediaStateCharacteristic.class).ifPresent(c -> service.addOptionalCharacteristic(c));
88 getCharacteristic(TargetMediaStateCharacteristic.class).ifPresent(c -> service.addOptionalCharacteristic(c));
89 getCharacteristic(PictureModeCharacteristic.class).ifPresent(c -> service.addOptionalCharacteristic(c));
91 getServices().add(service);