use of org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homeassistant.CChannel in project smarthome by eclipse.
the class HomeAssistantThingHandler method accept.
/**
* Callback of {@link DelayedBatchProcessing}.
* Add all newly discovered components to the Thing and start the components.
*/
@SuppressWarnings("null")
@Override
public void accept(List<AbstractComponent> discoveredComponentsList) {
MqttBrokerConnection connection = this.connection;
if (connection == null) {
return;
}
List<Channel> channels = new ArrayList<>();
synchronized (haComponents) {
// sync whenever discoverComponents is started
for (AbstractComponent discovered : discoveredComponentsList) {
AbstractComponent known = haComponents.get(discovered.uid().getId());
// Is component already known?
if (known != null) {
if (discovered.getConfigHash() != known.getConfigHash()) {
// Don't wait for the future to complete. We are also not interested in failures.
// The component will be replaced in a moment.
known.stop();
} else {
continue;
}
}
// Add channel and group types to the types registry
channelTypeProvider.setChannelGroupType(discovered.groupTypeUID(), discovered.type());
discovered.addChannelTypes(channelTypeProvider);
// Add component to the component map
haComponents.put(discovered.uid().getId(), discovered);
// Start component / Subscribe to channel topics
discovered.start(connection, scheduler, 0).exceptionally(e -> {
logger.warn("Failed to start component {}", discovered.uid(), e);
return null;
});
}
// Add channels to Thing
for (AbstractComponent e : haComponents.values()) {
for (CChannel entry : e.channelTypes().values()) {
channels.add(entry.channel);
}
}
}
updateThing(editThing().withChannels(channels).build());
updateStatus(ThingStatus.ONLINE);
}
use of org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homeassistant.CChannel in project smarthome by eclipse.
the class HomeAssistantThingHandler method getChannelState.
@SuppressWarnings({ "null", "unused" })
@Override
@Nullable
public ChannelState getChannelState(ChannelUID channelUID) {
String groupID = channelUID.getGroupId();
if (groupID == null) {
return null;
}
AbstractComponent component;
synchronized (haComponents) {
// sync whenever discoverComponents is started
component = haComponents.get(groupID);
}
if (component == null) {
return null;
}
CChannel componentChannel = component.channel(channelUID.getIdWithoutGroup());
if (componentChannel == null) {
return null;
}
return componentChannel.channelState;
}
Aggregations