Skip to content

Commit

Permalink
[mpd]: Music Player Daemon initial contribution (#7870)
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Roellin <[email protected]>
  • Loading branch information
stefanroellin authored Aug 21, 2020
1 parent ce5d4d8 commit 5d100e9
Show file tree
Hide file tree
Showing 29 changed files with 2,031 additions and 0 deletions.
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@
/bundles/org.openhab.binding.sonyprojector/ @lolodomo
/bundles/org.openhab.binding.spotify/ @Hilbrand
/bundles/org.openhab.binding.squeezebox/ @digitaldan @mhilbush
/bundles/org.openhab.binding.mpd/ @stefanroellin
/bundles/org.openhab.binding.synopanalyzer/ @clinique
/bundles/org.openhab.binding.systeminfo/ @svilenvul
/bundles/org.openhab.binding.tado/ @dfrommi
Expand Down
5 changes: 5 additions & 0 deletions bom/openhab-addons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,11 @@
<artifactId>org.openhab.binding.modbus.sunspec</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.binding.mpd</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.binding.synopanalyzer</artifactId>
Expand Down
32 changes: 32 additions & 0 deletions bundles/org.openhab.binding.mpd/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
23 changes: 23 additions & 0 deletions bundles/org.openhab.binding.mpd/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.openhab.binding.mpd</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
13 changes: 13 additions & 0 deletions bundles/org.openhab.binding.mpd/NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
This content is produced and maintained by the openHAB project.

* Project home: https://www.openhab.org

== Declared Project Licenses

This program and the accompanying materials are made available under the terms
of the Eclipse Public License 2.0 which is available at
https://www.eclipse.org/legal/epl-2.0/.

== Source Code

https://github.com/openhab/openhab-addons
106 changes: 106 additions & 0 deletions bundles/org.openhab.binding.mpd/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# MPD Binding

[Music Player Daemon (MPD)](http://www.musicpd.org/) is a flexible, powerful, server-side application for playing music. Through plugins and libraries it can play a variety of sound files while being controlled by its network protocol.

With the openHAB MPD binding you can control Music Player Daemons.


## Supported Things

This binding supports one ThingType: mpd

## Discovery

If zeroconf is enabled in the Music Player Daemon, it is discovered. Each Music Player daemon requires a unique zeroconf_name for correct discovery.


## Thing Configuration

The ThingType mpd requires the following configuration parameters:

| Parameter Label | Parameter ID | Description | Required |
|-----------------|--------------|--------------------------------------------------------------------------|----------|
| IP Address | ipAddress | Host name or IP address of the Music Player Daemon | yes |
| Port | port | Port number on which the Music Player Daemon is listening. Default: 6600 | yes |
| Password | password | Password to access the Music Player Daemon | no |


## Channels

The following channels are currently available:

| Channel Type ID | Item Type | Description |
|-----------------|-----------|---------------------------|
| control | Player | Start/Pause/Next/Previous |
| volume | Dimmer | Volume in percent |
| stop | Switch | Stop playback |
| currentalbum | String | Current album |
| currentartist | String | Current artist |
| currentname | String | Current name |
| currentsong | Number | Current song |
| currentsongid | Number | Current song id |
| currenttitle | String | Current title |
| currenttrack | Number | Current track |


## Full Example

#### Thing

```
mpd:mpd:music [ ipAddress="192.168.1.2", port=6600 ]
```

#### Items

```
Switch morning_music "Morning music"
Player mpd_music_player "Player" { channel = "mpd:mpd:music:control" }
Dimmer mpd_music_volume "Volume [%d %%]" { channel = "mpd:mpd:music:volume" }
Switch mpd_music_stop "Stop" { channel = "mpd:mpd:music:stop" }
String mpd_music_album "Album [%s]" { channel = "mpd:mpd:music:currentalbum" }
String mpd_music_artist "Artist [%s]" { channel = "mpd:mpd:music:currentartist" }
String mpd_music_name "Name [%s]" { channel = "mpd:mpd:music:currentname" }
Number mpd_music_song "Song [%d]" { channel = "mpd:mpd:music:currentsong" }
Number mpd_music_song_id "Song Id [%d]" { channel = "mpd:mpd:music:currentsongid" }
String mpd_music_title "Title [%s]" { channel = "mpd:mpd:music:currenttitle" }
Number mpd_music_track "Track [%d]" { channel = "mpd:mpd:music:currenttrack" }
```

#### Sitemap

```
Frame label="Music" {
Default item=mpd_music_player
Slider item=mpd_music_volume
Switch item=mpd_music_stop
Text item=mpd_music_album
Text item=mpd_music_artist
Text item=mpd_music_name
Text item=mpd_music_song
Text item=mpd_music_song_id
Text item=mpd_music_title
Text item=mpd_music_track
}
```

#### Rule

```
rule "turn on morning music"
when
Item morning_music changed to ON
then
val actions = getActions("mpd","mpd:mpd:music")
if(actions === null) {
logWarn("myLog", "actions is null")
return
}
actions.sendCommand("clear")
actions.sendCommand("load", "MorningMusic");
actions.sendCommand("shuffle");
actions.sendCommand("play");
end
```
17 changes: 17 additions & 0 deletions bundles/org.openhab.binding.mpd/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.addons.reactor.bundles</artifactId>
<version>2.5.8-SNAPSHOT</version>
</parent>

<artifactId>org.openhab.binding.mpd</artifactId>

<name>openHAB Add-ons :: Bundles :: MPD Binding</name>

</project>
9 changes: 9 additions & 0 deletions bundles/org.openhab.binding.mpd/src/main/feature/feature.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<features name="org.openhab.binding.mpd-${project.version}" xmlns="http://karaf.apache.org/xmlns/features/v1.4.0">
<repository>mvn:org.openhab.core.features.karaf/org.openhab.core.features.karaf.openhab-core/${ohc.version}/xml/features</repository>

<feature name="openhab-binding-mpd" description="MPD Binding" version="${project.version}">
<feature>openhab-runtime-base</feature>
<bundle start-level="80">mvn:org.openhab.addons.bundles/org.openhab.binding.mpd/${project.version}</bundle>
</feature>
</features>
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* 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.mpd.internal;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.smarthome.core.thing.ThingTypeUID;

/**
* The {@link MPDBindingConstants} class defines common constants, which are
* used across the whole binding.
*
* @author Stefan Röllin - Initial contribution
*/
@NonNullByDefault
public class MPDBindingConstants {

private static final String BINDING_ID = "mpd";

// List of all Thing Type UIDs
public static final ThingTypeUID THING_TYPE_MPD = new ThingTypeUID(BINDING_ID, "mpd");

// List of all Channel ids
public static final String CHANNEL_CONTROL = "control";
public static final String CHANNEL_CURRENT_ALBUM = "currentalbum";
public static final String CHANNEL_CURRENT_ARTIST = "currentartist";
public static final String CHANNEL_CURRENT_NAME = "currentname";
public static final String CHANNEL_CURRENT_SONG = "currentsong";
public static final String CHANNEL_CURRENT_SONG_ID = "currentsongid";
public static final String CHANNEL_CURRENT_TITLE = "currenttitle";
public static final String CHANNEL_CURRENT_TRACK = "currenttrack";
public static final String CHANNEL_STOP = "stop";
public static final String CHANNEL_VOLUME = "volume";

// Config Parameters
public static final String PARAMETER_IPADDRESS = "ipAddress";
public static final String PARAMETER_PORT = "port";
public static final String UNIQUE_ID = "uniqueId";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* 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.mpd.internal;

import org.eclipse.jdt.annotation.NonNullByDefault;

/**
* The {@link MPDConfiguration} class contains fields mapping thing configuration parameters.
*
* @author Stefan Röllin - Initial contribution
*/
@NonNullByDefault
public class MPDConfiguration {

private String ipAddress = "";
private Integer port = 0;
private String password = "";

public String getIpAddress() {
return ipAddress;
}

public void setIpAddress(String ipAddress) {
this.ipAddress = ipAddress;
}

public Integer getPort() {
return port;
}

public void setPort(Integer port) {
this.port = port;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* 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.mpd.internal;

import org.eclipse.jdt.annotation.NonNullByDefault;

/**
* The {@link MPDException} class is used for any exception thrown by the binding
*
* @author Stefan Röllin - Initial contribution
*/
@NonNullByDefault
public class MPDException extends Exception {
private static final long serialVersionUID = 1L;

public MPDException() {
}

public MPDException(String message) {
super(message);
}
}
Loading

0 comments on commit 5d100e9

Please sign in to comment.