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 static org.openhab.io.homekit.internal.HomekitCharacteristicType.*;
17 import java.util.List;
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;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 import io.github.hapjava.characteristics.Characteristic;
27 import io.github.hapjava.characteristics.impl.thermostat.CurrentHeatingCoolingStateCharacteristic;
28 import io.github.hapjava.characteristics.impl.thermostat.CurrentTemperatureCharacteristic;
29 import io.github.hapjava.characteristics.impl.thermostat.TargetHeatingCoolingStateCharacteristic;
30 import io.github.hapjava.characteristics.impl.thermostat.TargetTemperatureCharacteristic;
31 import io.github.hapjava.characteristics.impl.thermostat.TemperatureDisplayUnitCharacteristic;
32 import io.github.hapjava.services.impl.ThermostatService;
35 * Implements Thermostat as a GroupedAccessory made up of multiple items:
37 * <li>Current Temperature: Number type</li>
38 * <li>Target Temperature: Number type</li>
39 * <li>Current Heating/Cooling Mode: String type (see HomekitSettings.thermostat*Mode)</li>
40 * <li>Target Heating/Cooling Mode: String type (see HomekitSettings.thermostat*Mode)</li>
43 * @author Andy Lintner - Initial contribution
45 class HomekitThermostatImpl extends AbstractHomekitAccessoryImpl {
46 private final Logger logger = LoggerFactory.getLogger(HomekitThermostatImpl.class);
48 public HomekitThermostatImpl(HomekitTaggedItem taggedItem, List<HomekitTaggedItem> mandatoryCharacteristics,
49 List<Characteristic> mandatoryRawCharacteristics, HomekitAccessoryUpdater updater,
50 HomekitSettings settings) {
51 super(taggedItem, mandatoryCharacteristics, mandatoryRawCharacteristics, updater, settings);
55 public void init() throws HomekitException {
58 // This characteristic is technically mandatory, but we provide a default if it's not provided
59 var displayUnitCharacteristic = getCharacteristic(TemperatureDisplayUnitCharacteristic.class)
60 .orElseGet(() -> HomekitCharacteristicFactory.createSystemTemperatureDisplayUnitCharacteristic());
62 addService(new ThermostatService(getCharacteristic(CurrentHeatingCoolingStateCharacteristic.class).get(),
63 getCharacteristic(TargetHeatingCoolingStateCharacteristic.class).get(),
64 getCharacteristic(CurrentTemperatureCharacteristic.class).get(),
65 getCharacteristic(TargetTemperatureCharacteristic.class).get(), displayUnitCharacteristic));