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.television.RemoteKeyCharacteristic;
28 import io.github.hapjava.characteristics.impl.television.SleepDiscoveryModeCharacteristic;
29 import io.github.hapjava.characteristics.impl.television.SleepDiscoveryModeEnum;
30 import io.github.hapjava.services.impl.TelevisionService;
33 * Implements Television
35 * This is a little different in that we don't implement the accessory interface.
36 * This is because several of the "mandatory" characteristics we don't require,
37 * and wait until all optional attributes are added and if they don't exist
38 * it will create "default" values for them.
40 * @author Cody Cutrer - Initial contribution
43 public class HomekitTelevisionImpl extends AbstractHomekitAccessoryImpl {
45 public HomekitTelevisionImpl(HomekitTaggedItem taggedItem, List<HomekitTaggedItem> mandatoryCharacteristics,
46 HomekitAccessoryUpdater updater, HomekitSettings settings) throws IncompleteAccessoryException {
47 super(taggedItem, mandatoryCharacteristics, updater, settings);
51 public void init() throws HomekitException {
54 // these charactereristics are technically mandatory, but we provide defaults if they're not provided
55 var activeIdentifierCharacteristic = getCharacteristic(ActiveIdentifierCharacteristic.class)
56 .orElseGet(() -> new ActiveIdentifierCharacteristic(() -> CompletableFuture.completedFuture(1), v -> {
60 var configuredNameCharacteristic = getCharacteristic(ConfiguredNameCharacteristic.class)
61 .orElseGet(() -> new ConfiguredNameCharacteristic(() -> getName(), v -> {
65 var remoteKeyCharacteristic = getCharacteristic(RemoteKeyCharacteristic.class)
66 .orElseGet(() -> new RemoteKeyCharacteristic((v) -> {
68 var sleepDiscoveryModeCharacteristic = getCharacteristic(SleepDiscoveryModeCharacteristic.class)
69 .orElseGet(() -> new SleepDiscoveryModeCharacteristic(
70 () -> CompletableFuture.completedFuture(SleepDiscoveryModeEnum.ALWAYS_DISCOVERABLE), v -> {
74 var service = new TelevisionService(getCharacteristic(ActiveCharacteristic.class).get(),
75 activeIdentifierCharacteristic, configuredNameCharacteristic, remoteKeyCharacteristic,
76 sleepDiscoveryModeCharacteristic);