forked from openhab/openhab-addons
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[squeezebox] Implement like/unlike for remote streaming services (ope…
…nhab#7396) * Implement like/unlike for remote streaming services * Fix formatting * Address review feedback * Combine like/unlike to single rate channel * Address review comments Signed-off-by: Mark Hilbush <mark@hilbush.com>
- Loading branch information
Showing
16 changed files
with
574 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...nding.squeezebox/src/main/java/org/openhab/binding/squeezebox/internal/dto/ButtonDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** | ||
* Copyright (c) 2010-2020 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.binding.squeezebox.internal.dto; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
|
||
/** | ||
* The {@link ButtonDTO} represents a custom button that overrides existing | ||
* button functionality. For example, "like song" replaces the repeat button. | ||
* | ||
* @author Mark Hilbush - Initial contribution | ||
*/ | ||
public class ButtonDTO { | ||
|
||
/** | ||
* Indicates whether button is standard or custom | ||
*/ | ||
public Boolean custom; | ||
|
||
/** | ||
* Indicates if standard button is enabled or disabled | ||
*/ | ||
public Boolean enabled; | ||
|
||
/** | ||
* Concatenation of elements of command array | ||
*/ | ||
public String command; | ||
|
||
/** | ||
* Currently not used | ||
*/ | ||
@SerializedName("icon") | ||
public String icon; | ||
|
||
/** | ||
* Currently not used | ||
*/ | ||
@SerializedName("jiveStyle") | ||
public String jiveStyle; | ||
|
||
/** | ||
* Currently not used | ||
*/ | ||
@SerializedName("tooltip") | ||
public String toolTip; | ||
|
||
public boolean isCustom() { | ||
return custom == null ? Boolean.FALSE : custom; | ||
} | ||
|
||
public boolean isEnabled() { | ||
return enabled == null ? Boolean.FALSE : enabled; | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...ebox/src/main/java/org/openhab/binding/squeezebox/internal/dto/ButtonDTODeserializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* Copyright (c) 2010-2020 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.binding.squeezebox.internal.dto; | ||
|
||
import java.lang.reflect.Type; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.StreamSupport; | ||
|
||
import com.google.gson.JsonDeserializationContext; | ||
import com.google.gson.JsonDeserializer; | ||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonObject; | ||
import com.google.gson.JsonParseException; | ||
|
||
/** | ||
* The {@link ButtonDTODeserializer} is responsible for deserializing a button object, which | ||
* can either be an Integer, or a custom button specification. | ||
* | ||
* @author Mark Hilbush - Initial contribution | ||
*/ | ||
public class ButtonDTODeserializer implements JsonDeserializer<ButtonDTO> { | ||
|
||
@Override | ||
public ButtonDTO deserialize(JsonElement jsonElement, Type tyoeOfT, JsonDeserializationContext context) | ||
throws JsonParseException { | ||
ButtonDTO button = null; | ||
if (jsonElement.isJsonPrimitive() && jsonElement.getAsJsonPrimitive().isNumber()) { | ||
Integer value = jsonElement.getAsInt(); | ||
button = new ButtonDTO(); | ||
button.custom = false; | ||
button.enabled = value != 0; | ||
} else if (jsonElement.isJsonObject()) { | ||
JsonObject jsonObject = jsonElement.getAsJsonObject(); | ||
button = new ButtonDTO(); | ||
button.custom = true; | ||
button.icon = jsonObject.get("icon").getAsString(); | ||
button.jiveStyle = jsonObject.get("jiveStyle").getAsString(); | ||
button.toolTip = jsonObject.get("tooltip").getAsString(); | ||
button.command = StreamSupport.stream(jsonObject.getAsJsonArray("command").spliterator(), false) | ||
.map(JsonElement::getAsString).collect(Collectors.joining(" ")); | ||
} | ||
return button; | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...ding.squeezebox/src/main/java/org/openhab/binding/squeezebox/internal/dto/ButtonsDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* Copyright (c) 2010-2020 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.binding.squeezebox.internal.dto; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
|
||
/** | ||
* The {@link ButtonsDTO} contains information about the forward, rewind, repeat, | ||
* and shuffle buttons, including any custom definitions, such as replacing repeat | ||
* and shuffle with like and unlike, respectively. | ||
* | ||
* @author Mark Hilbush - Initial contribution | ||
*/ | ||
public class ButtonsDTO { | ||
|
||
/** | ||
* Indicates if forward button is enabled/disabled, | ||
* or if there is a custom button definition. | ||
*/ | ||
@SerializedName("fwd") | ||
public ButtonDTO forward; | ||
|
||
/** | ||
* Indicates if rewind button is enabled/disabled, | ||
* or if there is a custom button definition. | ||
*/ | ||
@SerializedName("rew") | ||
public ButtonDTO rewind; | ||
|
||
/** | ||
* Indicates if repeat button is enabled/disabled, | ||
* or if there is a custom button definition. | ||
*/ | ||
@SerializedName("repeat") | ||
public ButtonDTO repeat; | ||
|
||
/** | ||
* Indicates if shuffle button is enabled/disabled, | ||
* or if there is a custom button definition. | ||
*/ | ||
@SerializedName("shuffle") | ||
public ButtonDTO shuffle; | ||
} |
Oops, something went wrong.