hap-java / HAP-Java

Java implementation of the HomeKit Accessory Protocol
MIT License
152 stars 83 forks source link

Add support for FilterMaintenanceAccessory #124

Closed gjvanderheiden closed 3 years ago

gjvanderheiden commented 3 years ago

#124

Pull Request Checklist

Please confirm that you've done the following when opening a new pull request:

gjvanderheiden commented 3 years ago

linked issue : #123

Had to change the IntegerCharacteristic too. It didn't support unit nor no value. (needed for ResetFilter). Tested it with my own project, which uses this characteristic excessively.

Really missing exciting unit tests here. Unit test could test how the IntegerCharacteristic is responding to this in the json build.

yfre commented 3 years ago

with the new linked service support we dont need to have any dedicated methods on accessory levels but can basically add any service to any accessory, e.g. we can add Fan to Air Purifier it looks like this (im adding battery service to switch but it works the same for all other accessories and services)

final MockSwitch switch1 = new MockSwitch();
final MockBatteryService batteryService = new MockBatteryService();
switch1.getServices().add(batteryService.getPrimaryService());

means the only thing we need to implement is the FilterMaintanceService

gjvanderheiden commented 3 years ago

for filter maintenance we need additional characteristics but i could not find them in PR. e.g. ResetFilterIndicationCharacteristic FilterLifeLevelCharacteristic FilterChangeIndicationCharacteristic

buggar. beep**-ed something up with the change lists in my IDE. Thanks for mentioning

gjvanderheiden commented 3 years ago

with the new linked service support we dont need to have any dedicated methods on accessory levels but can basically add any service to any accessory, e.g. we can add Fan to Air Purifier it looks like this (im adding battery service to switch but it works the same for all other accessories and services)

final MockSwitch switch1 = new MockSwitch();
final MockBatteryService batteryService = new MockBatteryService();
switch1.getServices().add(batteryService.getPrimaryService());

means the only thing we need to implement is the FilterMaintanceService

I like the dynamic possibilities. I could be missing something, but getServices() returns a new instance of the service with every call. I can't see this working with HomekitBridge.addAccessory().

edit:

also see HomeKitRegistry.reset(): .... for (Service service : accessory.getServices()) { newServices.add(service); newServices.addAll(service.getLinkedServices()); } ...

gjvanderheiden commented 3 years ago

Another alternative would be:

HomekitAccessory accessory = new MockSwitch(...); accessory.addLinkedAccessory(new MockBatteryAccessory());

gjvanderheiden commented 3 years ago

@yfre thrown the 2 modification out of the window. How to link the services is another issue. Thank you for the review

gjvanderheiden commented 3 years ago

added comment to #104(https://github.com/hap-java/HAP-Java/issues/104). Can't add the accessory right now.