[dsmr] Fix incorrect deriving of sub channel names when updating channels (#13076)

Subchannels were created by appending the key. However this was done inside a loop and if multiple updates were needed they would be appended to the channel name, instead of taking the channel name each time.
Signed-off-by: Hilbrand Bouwkamp <hilbrand@h72.nl>
This commit is contained in:
Hilbrand Bouwkamp 2022-07-04 21:50:03 +02:00 committed by GitHub
parent 3e8df2bff8
commit a58ae57942
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 8 deletions

View File

@ -136,15 +136,13 @@ public class DSMRMeterHandler extends BaseThingHandler implements P1TelegramList
private synchronized void updateState() {
logger.trace("Update state for device: {}", getThing().getThingTypeUID().getId());
if (!lastReceivedValues.isEmpty()) {
for (CosemObject cosemObject : lastReceivedValues) {
String channel = cosemObject.getType().name().toLowerCase();
for (final CosemObject cosemObject : lastReceivedValues) {
for (final Entry<String, ? extends State> entry : cosemObject.getCosemValues().entrySet()) {
final String channel = cosemObject.getType().name().toLowerCase()
/* CosemObject has a specific sub channel if key not empty */
+ (entry.getKey().isEmpty() ? "" : "_" + entry.getKey());
for (Entry<String, ? extends State> entry : cosemObject.getCosemValues().entrySet()) {
if (!entry.getKey().isEmpty()) {
/* CosemObject has a specific sub channel */
channel += "_" + entry.getKey();
}
State newState = entry.getValue();
final State newState = entry.getValue();
logger.debug("Updating state for channel {} to value {}", channel, newState);
updateState(channel, newState);
}