Exemplo n.º 1
0
  @Override
  public Collection<SourcedDeviceUpnp> getDeviceList() {
    // horribly unoptimal impl!
    Map<String, SourcedDeviceUpnp> baseXmpp =
        convertToSourcedDimmableLightMap(mXmppConnector.getDeviceList(), Source.XMPP);
    Map<String, SourcedDeviceUpnp> baseLocal =
        convertToSourcedDimmableLightMap(mLocalConnector.getDeviceList(), Source.LOCAL);

    Multimap<String, SourcedDeviceUpnp> multiMap = ArrayListMultimap.create();
    multiMap.putAll(Multimaps.forMap(baseXmpp));
    multiMap.putAll(Multimaps.forMap(baseLocal));

    Iterable<SourcedDeviceUpnp> lights =
        Iterables.transform(
            multiMap.asMap().values(),
            new Function<Collection<SourcedDeviceUpnp>, SourcedDeviceUpnp>() {
              @Override
              public SourcedDeviceUpnp apply(Collection<SourcedDeviceUpnp> lightsCollection) {
                EnumSet<Source> sources = EnumSet.noneOf(Source.class);
                for (SourcedDeviceUpnp light : lightsCollection) {
                  sources.addAll(light.getSources());
                }
                // we make srong assumption here that all sources on list have same state
                // (name/switch state/brightness)
                SourcedDeviceUpnp first = Iterables.getFirst(lightsCollection, null);
                first.setSources(sources);
                return first;
              }
            });

    return Lists.newArrayList(lights);
  }
Exemplo n.º 2
0
 @Override
 public void refresh() {
   mXmppConnector.refresh();
   mLocalConnector.refresh();
 }