[hdpowerview] Return capabilities if capabilitiesOverride is not defined (#13031)
* [hdpowerview] bug fix capabilitiesOverride * [hdpowerview] adopt reviewer requests * [hdpowerview] suppress log warning on hub v1 * [hdpowerview] adopt reviwer suggestions Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
This commit is contained in:
committed by
GitHub
parent
5ae0870bcb
commit
650fc523b5
@@ -333,20 +333,37 @@ public class ShadeCapabilitiesDatabase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a Capabilities class instance that corresponds to the given 'typeId' parameter. If the 'typeId' parameter
|
||||
* is a valid type in the database, and it has a 'capabilitiesOverride' value, then an instance of the respective
|
||||
* overridden Capabilities class is returned. Otherwise if the 'capabilitiesId' parameter is for a valid
|
||||
* capabilities entry in the database, then that respective Capabilities class instance is returned. Otherwise a
|
||||
* blank Capabilities class instance is returned.
|
||||
* Return a Capabilities class instance that corresponds to the given 'typeId' parameter.
|
||||
* <p>
|
||||
* <ul>
|
||||
* <li>If the 'typeId' parameter is a valid type in the database, and it has a 'capabilitiesOverride' value, then an
|
||||
* instance of the respective overridden Capabilities class is returned.
|
||||
* <li>Otherwise if the 'capabilitiesId' parameter is for a valid capabilities entry in the database, then that
|
||||
* respective Capabilities class instance is returned.
|
||||
* <li>Otherwise if the type is a valid type in the database, then its 'capabilities' instance is returned.
|
||||
* <li>Otherwise a default Capabilities '0' class instance is returned.
|
||||
* </ul>
|
||||
* <p>
|
||||
*
|
||||
* @param typeId the target shade type Id (to check if it has a 'capabilitiesOverride' value).
|
||||
* @param capabilitiesId the target capabilities value (when type Id does not have a 'capabilitiesOverride').
|
||||
* @return corresponding Capabilities class instance.
|
||||
*/
|
||||
public Capabilities getCapabilities(int typeId, @Nullable Integer capabilitiesId) {
|
||||
int targetCapabilities = TYPE_DATABASE.getOrDefault(typeId, new Type()).getCapabilitiesOverride();
|
||||
Type type = TYPE_DATABASE.getOrDefault(typeId, new Type());
|
||||
// first try capabilitiesOverride for type Id
|
||||
int targetCapabilities = type.getCapabilitiesOverride();
|
||||
// then try capabilitiesId
|
||||
if (targetCapabilities < 0 && capabilitiesId != null && isCapabilitiesInDatabase(capabilitiesId.intValue())) {
|
||||
targetCapabilities = capabilitiesId.intValue();
|
||||
}
|
||||
// then try capabilities for typeId
|
||||
if (targetCapabilities < 0) {
|
||||
targetCapabilities = capabilitiesId != null ? capabilitiesId.intValue() : -1;
|
||||
targetCapabilities = type.getCapabilities();
|
||||
}
|
||||
// fallback to default capabilities 0 (so at least something may work..)
|
||||
if (targetCapabilities < 0) {
|
||||
targetCapabilities = 0;
|
||||
}
|
||||
return getCapabilities(targetCapabilities);
|
||||
}
|
||||
|
||||
@@ -320,7 +320,7 @@ public class HDPowerViewShadeHandler extends AbstractHubbedThingHandler {
|
||||
}
|
||||
|
||||
if (propChanged && db.isCapabilitiesInDatabase(capabilitiesVal) && db.isTypeInDatabase(type)
|
||||
&& (capabilitiesVal != db.getType(type).getCapabilities())) {
|
||||
&& (capabilitiesVal != db.getType(type).getCapabilities()) && (shadeData.capabilities != null)) {
|
||||
db.logCapabilitiesMismatch(type, capabilitiesVal);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user