[netatmo] Update only the channel for which the REFRESH is sent (#9188)

Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
This commit is contained in:
Christoph Weitkamp 2020-12-01 01:40:56 +01:00 committed by GitHub
parent 6afbe23ea6
commit 1abe9da2d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 15 deletions

View File

@ -122,9 +122,7 @@ public abstract class AbstractNetatmoThingHandler extends BaseThingHandler {
protected abstract void initializeThing(); protected abstract void initializeThing();
protected State getNAThingProperty(String channelId) { protected State getNAThingProperty(String channelId) {
Optional<State> result; Optional<State> result = getBatteryHelper().flatMap(helper -> helper.getNAThingProperty(channelId));
result = getBatteryHelper().flatMap(helper -> helper.getNAThingProperty(channelId));
if (result.isPresent()) { if (result.isPresent()) {
return result.get(); return result.get();
} }
@ -146,15 +144,13 @@ public abstract class AbstractNetatmoThingHandler extends BaseThingHandler {
} }
private void updateDataChannels() { private void updateDataChannels() {
getThing().getChannels().stream().filter(channel -> !channel.getKind().equals(ChannelKind.TRIGGER)) getThing().getChannels().stream()
.forEach(channel -> { .filter(channel -> !ChannelKind.TRIGGER.equals(channel.getKind()) && isLinked(channel.getUID()))
.map(channel -> channel.getUID()).forEach(this::updateChannel);
String channelId = channel.getUID().getId();
if (isLinked(channelId)) {
State state = getNAThingProperty(channelId);
updateState(channel.getUID(), state);
} }
});
private void updateChannel(ChannelUID channelUID) {
updateState(channelUID, getNAThingProperty(channelUID.getId()));
} }
/** /**
@ -162,8 +158,8 @@ public abstract class AbstractNetatmoThingHandler extends BaseThingHandler {
* (when a channel is triggered, a rule can get all other information from the updated non-trigger channels) * (when a channel is triggered, a rule can get all other information from the updated non-trigger channels)
*/ */
private void triggerEventChannels() { private void triggerEventChannels() {
getThing().getChannels().stream().filter(channel -> channel.getKind().equals(ChannelKind.TRIGGER)) getThing().getChannels().stream().filter(channel -> ChannelKind.TRIGGER.equals(channel.getKind()))
.forEach(channel -> triggerChannelIfRequired(channel.getUID().getId())); .map(channel -> channel.getUID().getId()).forEach(this::triggerChannelIfRequired);
} }
/** /**
@ -177,8 +173,8 @@ public abstract class AbstractNetatmoThingHandler extends BaseThingHandler {
@Override @Override
public void handleCommand(ChannelUID channelUID, Command command) { public void handleCommand(ChannelUID channelUID, Command command) {
if (command == RefreshType.REFRESH) { if (command == RefreshType.REFRESH) {
logger.debug("Refreshing {}", channelUID); logger.debug("Refreshing '{}'", channelUID);
updateChannels(); updateChannel(channelUID);
} }
} }