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.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.common.NameCharacteristic;
28 import io.github.hapjava.characteristics.impl.lightbulb.BrightnessCharacteristic;
29 import io.github.hapjava.characteristics.impl.television.ClosedCaptionsCharacteristic;
30 import io.github.hapjava.characteristics.impl.television.CurrentMediaStateCharacteristic;
31 import io.github.hapjava.characteristics.impl.television.PictureModeCharacteristic;
32 import io.github.hapjava.characteristics.impl.television.PowerModeCharacteristic;
33 import io.github.hapjava.characteristics.impl.television.RemoteKeyCharacteristic;
34 import io.github.hapjava.characteristics.impl.television.SleepDiscoveryModeCharacteristic;
35 import io.github.hapjava.characteristics.impl.television.SleepDiscoveryModeEnum;
36 import io.github.hapjava.characteristics.impl.television.TargetMediaStateCharacteristic;
37 import io.github.hapjava.services.impl.TelevisionService;
40 * Implements Television
42 * This is a little different in that we don't implement the accessory interface.
43 * This is because several of the "mandatory" characteristics we don't require,
44 * and wait until all optional attributes are added and if they don't exist
45 * it will create "default" values for them.
47 * @author Cody Cutrer - Initial contribution
50 public class HomekitTelevisionImpl extends AbstractHomekitAccessoryImpl {
52 public HomekitTelevisionImpl(HomekitTaggedItem taggedItem, List<HomekitTaggedItem> mandatoryCharacteristics,
53 HomekitAccessoryUpdater updater, HomekitSettings settings) throws IncompleteAccessoryException {
54 super(taggedItem, mandatoryCharacteristics, updater, settings);
58 public void init() throws HomekitException {
61 // these charactereristics are technically mandatory, but we provide defaults if they're not provided
62 var activeIdentifierCharacteristic = getCharacteristic(ActiveIdentifierCharacteristic.class)
63 .orElseGet(() -> new ActiveIdentifierCharacteristic(() -> CompletableFuture.completedFuture(1), v -> {
67 var configuredNameCharacteristic = getCharacteristic(ConfiguredNameCharacteristic.class)
68 .orElseGet(() -> new ConfiguredNameCharacteristic(() -> getName(), v -> {
72 var remoteKeyCharacteristic = getCharacteristic(RemoteKeyCharacteristic.class)
73 .orElseGet(() -> new RemoteKeyCharacteristic((v) -> {
75 var sleepDiscoveryModeCharacteristic = getCharacteristic(SleepDiscoveryModeCharacteristic.class)
76 .orElseGet(() -> new SleepDiscoveryModeCharacteristic(
77 () -> CompletableFuture.completedFuture(SleepDiscoveryModeEnum.ALWAYS_DISCOVERABLE), v -> {
81 var service = new TelevisionService(getCharacteristic(ActiveCharacteristic.class).get(),
82 activeIdentifierCharacteristic, configuredNameCharacteristic, remoteKeyCharacteristic,
83 sleepDiscoveryModeCharacteristic);
85 getCharacteristic(NameCharacteristic.class).ifPresent(c -> service.addOptionalCharacteristic(c));
86 getCharacteristic(BrightnessCharacteristic.class).ifPresent(c -> service.addOptionalCharacteristic(c));
87 getCharacteristic(PowerModeCharacteristic.class).ifPresent(c -> service.addOptionalCharacteristic(c));
88 getCharacteristic(ClosedCaptionsCharacteristic.class).ifPresent(c -> service.addOptionalCharacteristic(c));
89 getCharacteristic(CurrentMediaStateCharacteristic.class).ifPresent(c -> service.addOptionalCharacteristic(c));
90 getCharacteristic(TargetMediaStateCharacteristic.class).ifPresent(c -> service.addOptionalCharacteristic(c));
91 getCharacteristic(PictureModeCharacteristic.class).ifPresent(c -> service.addOptionalCharacteristic(c));
93 getServices().add(service);