Skip to content

add support for linked services - #110

Merged
ccutrer merged 1 commit into
hap-java:masterfrom
dfrommi:add-linked-service-support
Dec 8, 2020
Merged

ccutrer merged 1 commit into
hap-java:masterfrom
dfrommi:add-linked-service-support

Conversation

@dfrommi

@dfrommi dfrommi commented Oct 16, 2020

Copy link
Copy Markdown
Contributor

Some services require linked services to work, for example, the Television service which requires each input to be a linked service.
With this change, support to link services is added, though it's not used in any existing service, as they don't need linking. But I verified the functionality using my own Television service, which is not yet production-ready.

This change also centralizes the generation of interface ids. They are now only generated in the registry.
We were previously also generating them in the accessory controller, relying on an identical processing sequence.

This is implementing the issue #104 and replacing PR #105.
The author seems to have abandoned the PR and I personally also think that linking accessories rather than services is not the right level.

Pull Request Checklist

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

  • For fixes and other improvements, please reference the GitHub issue that your change addresses.
  • For fixes, optimizations and new features, please add an entry to the CHANGES.md file.
  • Run mvn compile before committing, so that the auto-code formatter will format your changes consistently with the rest of the project.

@yfre

yfre commented Oct 16, 2020

Copy link
Copy Markdown
Contributor

@dfrommi thank you for your pull request. this is really most wanted/missing feature.
quick question: how to add a linked service to accessory? via getServices().add(..) or missed something?
maybe you can share you TV example

@dfrommi

dfrommi commented Oct 16, 2020

Copy link
Copy Markdown
Contributor Author

You have a base service (just made this name up) and a linked service.
For example, the Television service is the base service and the input source service would be the linked service.

And you just have to make sure that baseService.getLinkedServices() contains the linked service. So you don't add the linked service directly to the accessory services list, but just add it to the base service.

I don't have a strong opinion on how it should be added to the accessory interface, but you will probably somewhere have code like baseService.getLinkedServices().add(linkedService).

Sharing my TV-accessory doesn't help much. I have a small facade around HAP-Java to better integrate into my Project-Reactor and Kotlin environment. There's not this one small piece of code that I could share as an example.

@dfrommi

dfrommi commented Oct 18, 2020

Copy link
Copy Markdown
Contributor Author

@yfre I decided to make my wrapper public. Here's a sample for a TV service

@yfre

yfre commented Dec 7, 2020

Copy link
Copy Markdown
Contributor

@dfrommi i was trying to get it working with test client (here in sample branch) or with openhab but without success. probably the getLinkedService needs to be adapted as it always returns a new array and forget all services added via "getLinkedServices().add()".

  @Override
  public List<Service> getLinkedServices() {
    return new ArrayList<>();
  }

the way how you initialise HomkitAccessory in kotlin is not the way how it is typically done in java.

would it be ok for you, if I take your PR, add some additional java API and submit as a new PR?

@yfre

yfre commented Dec 7, 2020

Copy link
Copy Markdown
Contributor

@dfrommi just checked and indeed, getLinkedServices was the issue. so, only minor changes needed to make it work in java as well. i will propose them as part of PR review here, maybe you could incorporate

@yfre yfre left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please make LinkedServiceList persistent

public List<Service> getLinkedServices() {
return new ArrayList<>();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please make the linkedService list persistent by adding following

Suggested change
private final List<Service> linkedServices = new LinkedList<>();
@Override
public void addLinkedService(Service s) { linkedServices.add(s);}
@Override
public List<Service> getLinkedServices() { return Collections.unmodifiableList(linkedServices); }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

* ########-####-####-####-############.
*/
String getType();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add

Suggested change
void addLinkedService(Service s);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Characteristics are handled just the same as LinkedServices in the Service interface and AbstractServiceImpl. And so I didn't add addLinkedService to the Service interface, but only to the abstract class, which is just how it's done for Characteristics as well.

Some services require linked services to work, for example, the Television service which requires each input to be a linked service.
With this change, support to link services is added, though it's not used in any existing service, as they don't need linking.

This change also centralizes the generation of interface ids. They are now only generated in the registry.
We were previously also generating them in the accessory controller, relying on an identical processing sequence.
@dfrommi

dfrommi commented Dec 8, 2020

Copy link
Copy Markdown
Contributor Author

@yfre Thank you so much for reviewing my changes.
I've done the changes you suggested and now the linked services are treated just the same as characteristics on the Service interface and abstract service class.
To have it properly aligned, I did not add addLinkedServices to the interface, though. Hope you agree with that.

@yfre yfre left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good for me.
i have tested the sample client

@yfre

yfre commented Dec 8, 2020

Copy link
Copy Markdown
Contributor

@yfre Thank you so much for reviewing my changes.
I've done the changes you suggested and now the linked services are treated just the same as characteristics on the Service interface and abstract service class.
To have it properly aligned, I did not add addLinkedServices to the interface, though. Hope you agree with that.

@dfrommi you are right. linkedService should be done in the same way as characteristics.
thank you for your contribution. this feature will enable a number of new services & service combinations.

@ccutrer
ccutrer merged commit a746a02 into hap-java:master Dec 8, 2020
@yfre yfre mentioned this pull request Dec 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants