2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.heos.internal.json.dto;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
23 * Abstract parent class for the HEOS event/response objects
25 * @author Martin van Wingerden - Initial contribution
28 public abstract class HeosObject {
29 private final Logger logger = LoggerFactory.getLogger(HeosObject.class);
31 public final String rawCommand;
32 private final Map<String, String> attributes;
34 HeosObject(String rawCommand, Map<String, String> attributes) {
35 this.rawCommand = rawCommand;
36 this.attributes = attributes;
39 public boolean getBooleanAttribute(HeosCommunicationAttribute attributeName) {
40 return "on".equals(attributes.get(attributeName.getLabel()));
43 public @Nullable Long getNumericAttribute(HeosCommunicationAttribute attributeName) {
45 String attribute = attributes.get(attributeName.getLabel());
47 if (attribute == null) {
52 return Long.valueOf(attribute);
53 } catch (NumberFormatException e) {
54 logger.debug("Failed to parse number: {}, message: {}", attribute, e.getMessage());
59 public @Nullable String getAttribute(HeosCommunicationAttribute attributeName) {
60 return attributes.get(attributeName.getLabel());
63 public boolean hasAttribute(HeosCommunicationAttribute attribute) {
64 return attributes.containsKey(attribute.getLabel());
68 public String toString() {
69 return "HeosObject{" + "rawCommand='" + rawCommand + '\'' + ", attributes=" + attributes + '}';