[homekit] remove support for legacy tags and fix issue with semantic tags (#9277)

Signed-off-by: Eugen Freiter <freiter@gmx.de>
This commit is contained in:
eugen
2020-12-07 17:04:59 +01:00
committed by GitHub
parent ac6f08908f
commit 91f05f0ea3
8 changed files with 26 additions and 232 deletions

View File

@@ -48,15 +48,7 @@ public enum HomekitAccessoryType {
HEATER_COOLER("HeaterCooler"),
LIGHT_SENSOR("LightSensor"),
AIR_QUALITY_SENSOR("AirQualitySensor"),
DUMMY("Dummy"),
@Deprecated()
BLINDS("Blinds"),
@Deprecated()
OLD_DIMMABLE_LIGHTBULB("DimmableLighting"),
@Deprecated()
OLD_HUMIDITY_SENSOR("CurrentHumidity"),
@Deprecated()
OLD_COLORFUL_LIGHTBULB("ColorfulLighting");
DUMMY("Dummy");
private static final Map<String, HomekitAccessoryType> TAG_MAP = new HashMap<>();

View File

@@ -107,20 +107,7 @@ public enum HomekitCharacteristicType {
SULPHUR_DIOXIDE_DENSITY("SulphurDioxideDensity"),
PM25_DENSITY("PM25Density"),
PM10_DENSITY("PM10Density"),
VOC_DENSITY("VOCDensity"),
@Deprecated()
OLD_BATTERY_LEVEL("homekit:BatteryLevel"),
@Deprecated()
OLD_BATTERY_LOW_STATUS("homekit:BatteryLowStatus"),
@Deprecated()
VERY_OLD_TARGET_HEATING_COOLING_MODE("homekit:HeatingCoolingMode"),
@Deprecated()
OLD_TARGET_HEATING_COOLING_MODE("homekit:TargetHeatingCoolingMode"),
@Deprecated()
OLD_CURRENT_HEATING_COOLING_STATE("homekit:CurrentHeatingCoolingMode"),
@Deprecated()
OLD_TARGET_TEMPERATURE("homekit:TargetTemperature");
VOC_DENSITY("VOCDensity");
private static final Map<String, HomekitCharacteristicType> TAG_MAP = new HashMap<>();

View File

@@ -38,10 +38,6 @@ public class HomekitCommandExtension extends AbstractConsoleCommandExtension {
private static final String SUBCMD_LIST_ACCESSORIES = "list";
private static final String SUBCMD_PRINT_ACCESSORY = "show";
private static final String SUBCMD_ALLOW_UNAUTHENTICATED = "allowUnauthenticated";
@Deprecated
private static final String LEGACY_SUBCMD_LIST_ACCESSORIES = "listAccessories";
@Deprecated
private static final String LEGACY_SUBCMD_PRINT_ACCESSORY = "printAccessory";
private final Logger logger = LoggerFactory.getLogger(HomekitCommandExtension.class);
@@ -69,24 +65,14 @@ public class HomekitCommandExtension extends AbstractConsoleCommandExtension {
}
break;
case SUBCMD_LIST_ACCESSORIES:
case LEGACY_SUBCMD_LIST_ACCESSORIES:
listAccessories(console);
if (subCommand.equalsIgnoreCase(LEGACY_SUBCMD_LIST_ACCESSORIES)) {
console.println("");
console.println("Hey, you can use the shorter command 'homekit list'");
}
break;
case SUBCMD_PRINT_ACCESSORY:
case LEGACY_SUBCMD_PRINT_ACCESSORY:
if (args.length > 1) {
printAccessory(args[1], console);
} else {
console.println("accessory id or name is required as an argument");
}
if (subCommand.equalsIgnoreCase(LEGACY_SUBCMD_PRINT_ACCESSORY)) {
console.println("");
console.println("Hey, you can use the shorter command 'homekit show <accessory_id|name>'");
}
break;
default:
console.println("Unknown command '" + subCommand + "'");

View File

@@ -81,7 +81,6 @@ public class HomekitImpl implements Homekit {
private HomekitSettings processConfig(Map<String, Object> config) {
HomekitSettings settings = (new Configuration(config)).as(HomekitSettings.class);
settings.process();
if (settings.networkInterface == null) {
settings.networkInterface = networkAddressService.getPrimaryIpv4HostAddress();
}

View File

@@ -21,7 +21,7 @@ public class HomekitSettings {
public static final String MANUFACTURER = "openHAB Community";
public static final String SERIAL_NUMBER = "none";
public static final String MODEL = "openHAB";
public static final String HARDWARE_REVISION = "2.5";
public static final String HARDWARE_REVISION = "3.0";
public String name = "openHAB";
public int port = 9123;
@@ -46,30 +46,6 @@ public class HomekitSettings {
public String doorTargetStateOpen = "OPEN";
public String networkInterface;
@Deprecated
public String thermostatHeatMode;
@Deprecated
public String thermostatCoolMode;
@Deprecated
public String thermostatAutoMode;
@Deprecated
public String thermostatOffMode;
public void process() {
if (thermostatHeatMode /* legacy setting */ != null) {
this.thermostatTargetModeHeat = thermostatHeatMode;
}
if (thermostatCoolMode /* legacy setting */ != null) {
this.thermostatTargetModeCool = thermostatCoolMode;
}
if (thermostatAutoMode /* legacy setting */ != null) {
this.thermostatTargetModeAuto = thermostatAutoMode;
}
if (thermostatOffMode /* legacy setting */ != null) {
this.thermostatTargetModeOff = thermostatOffMode;
}
}
@Override
public int hashCode() {
final int prime = 31;

View File

@@ -31,8 +31,6 @@ import org.openhab.core.items.ItemRegistry;
import org.openhab.core.items.Metadata;
import org.openhab.core.items.MetadataKey;
import org.openhab.core.items.MetadataRegistry;
import org.openhab.core.library.items.ColorItem;
import org.openhab.core.library.items.DimmerItem;
import org.openhab.io.homekit.internal.HomekitAccessoryType;
import org.openhab.io.homekit.internal.HomekitAccessoryUpdater;
import org.openhab.io.homekit.internal.HomekitCharacteristicType;
@@ -54,7 +52,6 @@ import io.github.hapjava.services.Service;
* @author Eugen Freiter - refactoring for optional characteristics
*/
@NonNullByDefault
@SuppressWarnings("deprecation")
public class HomekitAccessoryFactory {
private static final Logger logger = LoggerFactory.getLogger(HomekitAccessoryFactory.class);
public final static String METADATA_KEY = "homekit"; // prefix for HomeKit meta information in items.xml
@@ -89,14 +86,8 @@ public class HomekitAccessoryFactory {
new HomekitCharacteristicType[] { CURRENT_DOOR_STATE, TARGET_DOOR_STATE, OBSTRUCTION_STATUS });
put(HEATER_COOLER, new HomekitCharacteristicType[] { ACTIVE_STATUS, CURRENT_HEATER_COOLER_STATE,
TARGET_HEATER_COOLER_STATE, CURRENT_TEMPERATURE });
// LEGACY
put(BLINDS, new HomekitCharacteristicType[] { TARGET_POSITION, CURRENT_POSITION, POSITION_STATE });
put(WINDOW, new HomekitCharacteristicType[] { CURRENT_POSITION, TARGET_POSITION, POSITION_STATE });
put(DOOR, new HomekitCharacteristicType[] { CURRENT_POSITION, TARGET_POSITION, POSITION_STATE });
put(OLD_HUMIDITY_SENSOR, new HomekitCharacteristicType[] { RELATIVE_HUMIDITY });
put(OLD_DIMMABLE_LIGHTBULB, new HomekitCharacteristicType[] { ON_STATE });
put(OLD_COLORFUL_LIGHTBULB, new HomekitCharacteristicType[] { ON_STATE });
}
};
@@ -125,33 +116,9 @@ public class HomekitAccessoryFactory {
put(OUTLET, HomekitOutletImpl.class);
put(SPEAKER, HomekitSpeakerImpl.class);
put(GARAGE_DOOR_OPENER, HomekitGarageDoorOpenerImpl.class);
put(BLINDS, HomekitWindowCoveringImpl.class);
put(DOOR, HomekitDoorImpl.class);
put(WINDOW, HomekitWindowImpl.class);
put(HEATER_COOLER, HomekitHeaterCoolerImpl.class);
put(OLD_HUMIDITY_SENSOR, HomekitHumiditySensorImpl.class);
put(OLD_DIMMABLE_LIGHTBULB, HomekitLightbulbImpl.class);
put(OLD_COLORFUL_LIGHTBULB, HomekitLightbulbImpl.class);
}
};
/** mapping of legacy attributes to new attributes. **/
private final static Map<HomekitCharacteristicType, HomekitCharacteristicType> LEGACY_CHARACTERISTICS_MAPPING = new HashMap<HomekitCharacteristicType, HomekitCharacteristicType>() {
{
put(OLD_CURRENT_HEATING_COOLING_STATE, CURRENT_HEATING_COOLING_STATE);
put(OLD_TARGET_HEATING_COOLING_MODE, TARGET_HEATING_COOLING_STATE);
put(OLD_TARGET_TEMPERATURE, TARGET_TEMPERATURE);
put(OLD_BATTERY_LOW_STATUS, BATTERY_LOW_STATUS);
put(VERY_OLD_TARGET_HEATING_COOLING_MODE, CURRENT_HEATING_COOLING_STATE);
}
};
/** list of optional implicit optional characteristics. mainly used for legacy accessory type */
private final static Map<HomekitAccessoryType, HomekitCharacteristicType[]> IMPLICIT_OPTIONAL_CHARACTERISTICS = new HashMap<HomekitAccessoryType, HomekitCharacteristicType[]>() {
{
put(OLD_DIMMABLE_LIGHTBULB, new HomekitCharacteristicType[] { BRIGHTNESS });
put(OLD_COLORFUL_LIGHTBULB, new HomekitCharacteristicType[] { HUE, SATURATION, BRIGHTNESS });
}
};
@@ -213,32 +180,24 @@ public class HomekitAccessoryFactory {
MetadataRegistry metadataRegistry) {
final List<Entry<HomekitAccessoryType, HomekitCharacteristicType>> accessories = new ArrayList<>();
final @Nullable Metadata metadata = metadataRegistry.get(new MetadataKey(METADATA_KEY, item.getUID()));
boolean legacyMode = metadata == null;
String[] tags = !legacyMode ? metadata.getValue().split(",") : item.getTags().toArray(new String[0]); // fallback
for (String tag : tags) {
final String[] meta = tag.split("\\.");
Optional<HomekitAccessoryType> accessoryType = HomekitAccessoryType.valueOfTag(meta[0].trim());
if (accessoryType.isPresent()) { // it accessory, check for characteristic
HomekitAccessoryType type = accessoryType.get();
if ((legacyMode) && (type.equals(LIGHTBULB))) { // support old smart logic to convert Lighting to
// DimmableLighting or ColorfulLighting depending on
// item type
if (item instanceof ColorItem) {
type = OLD_COLORFUL_LIGHTBULB;
} else if (item instanceof DimmerItem) {
type = OLD_DIMMABLE_LIGHTBULB;
if (metadata != null) {
String[] tags = metadata.getValue().split(",");
for (String tag : tags) {
final String[] meta = tag.split("\\.");
Optional<HomekitAccessoryType> accessoryType = HomekitAccessoryType.valueOfTag(meta[0].trim());
if (accessoryType.isPresent()) { // it accessory, check for characteristic
HomekitAccessoryType type = accessoryType.get();
if (meta.length > 1) {
// it has characteristic as well
accessories.add(new SimpleEntry<>(type,
HomekitCharacteristicType.valueOfTag(meta[1].trim()).orElse(EMPTY)));
} else {// it has no characteristic
accessories.add(new SimpleEntry<>(type, EMPTY));
}
} else { // it is no accessory, so, maybe it is a characteristic
HomekitCharacteristicType.valueOfTag(meta[0].trim())
.ifPresent(c -> accessories.add(new SimpleEntry<>(DUMMY, c)));
}
if (meta.length > 1) {
// it has characteristic as well
accessories.add(new SimpleEntry<>(type,
HomekitCharacteristicType.valueOfTag(meta[1].trim()).orElse(EMPTY)));
} else {// it has no characteristic
accessories.add(new SimpleEntry<>(type, EMPTY));
}
} else { // it is no accessory, so, maybe it is a characteristic
HomekitCharacteristicType.valueOfTag(meta[0].trim())
.ifPresent(c -> accessories.add(new SimpleEntry<>(DUMMY, c)));
}
}
return accessories;
@@ -331,8 +290,7 @@ public class HomekitAccessoryFactory {
} else {
// item has characteristic tag on it, so, adding it as that characteristic.
// check whether it is a legacy characteristic, i.e. old tag was used, and replaced by a new one
final HomekitCharacteristicType characteristic = legacyCheck(accessory.getValue());
final HomekitCharacteristicType characteristic = accessory.getValue();
// check whether it is a mandatory characteristic. optional will be added later by another method.
if (isMandatoryCharacteristic(mainItem.getAccessoryType(), characteristic)) {
@@ -395,22 +353,13 @@ public class HomekitAccessoryFactory {
GroupItem groupItem = (GroupItem) taggedItem.getItem();
groupItem.getMembers().forEach(item -> getAccessoryTypes(item, metadataRegistry).stream()
.filter(c -> !isRootAccessory(c))
.filter(c -> !isMandatoryCharacteristic(taggedItem.getAccessoryType(), legacyCheck(c.getValue())))
.forEach(characteristic -> characteristicItems.put(legacyCheck(characteristic.getValue()),
(GenericItem) item)));
.filter(c -> !isMandatoryCharacteristic(taggedItem.getAccessoryType(), c.getValue()))
.forEach(characteristic -> characteristicItems.put(characteristic.getValue(), (GenericItem) item)));
} else {
getAccessoryTypes(taggedItem.getItem(), metadataRegistry).stream().filter(c -> !isRootAccessory(c))
.filter(c -> !isMandatoryCharacteristic(taggedItem.getAccessoryType(), legacyCheck(c.getValue())))
.forEach(characteristic -> characteristicItems.put(legacyCheck(characteristic.getValue()),
.filter(c -> !isMandatoryCharacteristic(taggedItem.getAccessoryType(), c.getValue()))
.forEach(characteristic -> characteristicItems.put(characteristic.getValue(),
(GenericItem) taggedItem.getItem()));
final HomekitCharacteristicType[] implicitOptionalCharacteristics = IMPLICIT_OPTIONAL_CHARACTERISTICS
.get(taggedItem.getAccessoryType());
if (implicitOptionalCharacteristics != null) {
Arrays.stream(implicitOptionalCharacteristics)
.filter(c -> !isMandatoryCharacteristic(taggedItem.getAccessoryType(), c))
.forEach(characteristic -> characteristicItems.put(legacyCheck(characteristic),
(GenericItem) taggedItem.getItem()));
}
}
logger.trace("Optional characteristics for item {} characteristics {}", taggedItem.getName(),
characteristicItems);
@@ -439,15 +388,4 @@ public class HomekitAccessoryFactory {
private static boolean isRootAccessory(Entry<HomekitAccessoryType, HomekitCharacteristicType> accessory) {
return ((accessory.getValue() == null) || (accessory.getValue() == EMPTY));
}
/**
* check whether it is legacy characteristic and return new name in such case. otherwise return the input parameter
* unchanged.
*
* @param characteristicType characteristic to check
* @return new characteristic type
*/
private static HomekitCharacteristicType legacyCheck(HomekitCharacteristicType characteristicType) {
return LEGACY_CHARACTERISTICS_MAPPING.getOrDefault(characteristicType, characteristicType);
}
}

View File

@@ -90,7 +90,6 @@ import io.github.hapjava.characteristics.impl.windowcovering.TargetVerticalTiltA
* @author Eugen Freiter - Initial contribution
*/
@NonNullByDefault
@SuppressWarnings("deprecation")
public class HomekitCharacteristicFactory {
private static final Logger logger = LoggerFactory.getLogger(HomekitCharacteristicFactory.class);
@@ -136,8 +135,6 @@ public class HomekitCharacteristicFactory {
put(PM25_DENSITY, HomekitCharacteristicFactory::createPM25DensityCharacteristic);
put(PM10_DENSITY, HomekitCharacteristicFactory::createPM10DensityCharacteristic);
put(VOC_DENSITY, HomekitCharacteristicFactory::createVOCDensityCharacteristic);
// LEGACY
put(OLD_BATTERY_LOW_STATUS, HomekitCharacteristicFactory::createStatusLowBatteryCharacteristic);
}
};