From 8c794964442901127b73050b34b17902aee50be2 Mon Sep 17 00:00:00 2001 From: Zachary Christiansen Date: Wed, 6 May 2020 00:04:56 -0500 Subject: [PATCH 1/3] *add played indicator config option *add additional control options *various bug fixes and code cleanup to prepare for pull request Signed-off-by: Zachary Christiansen --- bundles/org.openhab.binding.emby/.classpath | 32 ++ bundles/org.openhab.binding.emby/.project | 23 ++ bundles/org.openhab.binding.emby/NOTICE | 13 + bundles/org.openhab.binding.emby/README.md | 69 ++++ bundles/org.openhab.binding.emby/pom.xml | 16 + .../src/main/feature/feature.xml | 9 + .../emby/internal/EmbyBindingConstants.java | 80 ++++ .../internal/EmbyBridgeConfiguration.java | 95 +++++ .../emby/internal/EmbyBridgeListener.java | 32 ++ .../internal/EmbyDeviceConfiguration.java | 24 ++ .../emby/internal/EmbyEventListener.java | 84 +++++ .../emby/internal/EmbyHandlerFactory.java | 134 +++++++ .../discovery/EmbyClientDiscoveryService.java | 100 +++++ .../discovery/EmbyDiscoveryService.java | 204 ++++++++++ .../internal/handler/EmbyBridgeHandler.java | 159 ++++++++ .../internal/handler/EmbyDeviceHandler.java | 356 ++++++++++++++++++ .../internal/model/EmbyNowPlayingItem.java | 82 ++++ .../emby/internal/model/EmbyPlayState.java | 69 ++++ .../internal/model/EmbyPlayStateModel.java | 188 +++++++++ .../model/EmbyPlayingPostJsonModel.java | 93 +++++ .../internal/protocol/EmbyClientSocket.java | 245 ++++++++++++ .../EmbyClientSocketEventListener.java | 31 ++ .../internal/protocol/EmbyConnection.java | 108 ++++++ .../internal/protocol/EmbyDeviceEncoder.java | 32 ++ .../emby/internal/protocol/EmbyHTTPUtils.java | 94 +++++ .../protocol/EmbyHttpRetryExceeded.java | 25 ++ .../resources/ESH-INF/binding/binding.xml | 10 + .../resources/ESH-INF/thing/thing-types.xml | 195 ++++++++++ bundles/pom.xml | 4 +- 29 files changed, 2604 insertions(+), 2 deletions(-) create mode 100644 bundles/org.openhab.binding.emby/.classpath create mode 100644 bundles/org.openhab.binding.emby/.project create mode 100644 bundles/org.openhab.binding.emby/NOTICE create mode 100644 bundles/org.openhab.binding.emby/README.md create mode 100644 bundles/org.openhab.binding.emby/pom.xml create mode 100644 bundles/org.openhab.binding.emby/src/main/feature/feature.xml create mode 100644 bundles/org.openhab.binding.emby/src/main/java/org/openhab/binding/emby/internal/EmbyBindingConstants.java create mode 100644 bundles/org.openhab.binding.emby/src/main/java/org/openhab/binding/emby/internal/EmbyBridgeConfiguration.java create mode 100644 bundles/org.openhab.binding.emby/src/main/java/org/openhab/binding/emby/internal/EmbyBridgeListener.java create mode 100644 bundles/org.openhab.binding.emby/src/main/java/org/openhab/binding/emby/internal/EmbyDeviceConfiguration.java create mode 100644 bundles/org.openhab.binding.emby/src/main/java/org/openhab/binding/emby/internal/EmbyEventListener.java create mode 100644 bundles/org.openhab.binding.emby/src/main/java/org/openhab/binding/emby/internal/EmbyHandlerFactory.java create mode 100644 bundles/org.openhab.binding.emby/src/main/java/org/openhab/binding/emby/internal/discovery/EmbyClientDiscoveryService.java create mode 100644 bundles/org.openhab.binding.emby/src/main/java/org/openhab/binding/emby/internal/discovery/EmbyDiscoveryService.java create mode 100644 bundles/org.openhab.binding.emby/src/main/java/org/openhab/binding/emby/internal/handler/EmbyBridgeHandler.java create mode 100644 bundles/org.openhab.binding.emby/src/main/java/org/openhab/binding/emby/internal/handler/EmbyDeviceHandler.java create mode 100644 bundles/org.openhab.binding.emby/src/main/java/org/openhab/binding/emby/internal/model/EmbyNowPlayingItem.java create mode 100644 bundles/org.openhab.binding.emby/src/main/java/org/openhab/binding/emby/internal/model/EmbyPlayState.java create mode 100644 bundles/org.openhab.binding.emby/src/main/java/org/openhab/binding/emby/internal/model/EmbyPlayStateModel.java create mode 100644 bundles/org.openhab.binding.emby/src/main/java/org/openhab/binding/emby/internal/model/EmbyPlayingPostJsonModel.java create mode 100644 bundles/org.openhab.binding.emby/src/main/java/org/openhab/binding/emby/internal/protocol/EmbyClientSocket.java create mode 100644 bundles/org.openhab.binding.emby/src/main/java/org/openhab/binding/emby/internal/protocol/EmbyClientSocketEventListener.java create mode 100644 bundles/org.openhab.binding.emby/src/main/java/org/openhab/binding/emby/internal/protocol/EmbyConnection.java create mode 100644 bundles/org.openhab.binding.emby/src/main/java/org/openhab/binding/emby/internal/protocol/EmbyDeviceEncoder.java create mode 100644 bundles/org.openhab.binding.emby/src/main/java/org/openhab/binding/emby/internal/protocol/EmbyHTTPUtils.java create mode 100644 bundles/org.openhab.binding.emby/src/main/java/org/openhab/binding/emby/internal/protocol/EmbyHttpRetryExceeded.java create mode 100644 bundles/org.openhab.binding.emby/src/main/resources/ESH-INF/binding/binding.xml create mode 100644 bundles/org.openhab.binding.emby/src/main/resources/ESH-INF/thing/thing-types.xml diff --git a/bundles/org.openhab.binding.emby/.classpath b/bundles/org.openhab.binding.emby/.classpath new file mode 100644 index 0000000000000..a5d95095ccaaf --- /dev/null +++ b/bundles/org.openhab.binding.emby/.classpath @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bundles/org.openhab.binding.emby/.project b/bundles/org.openhab.binding.emby/.project new file mode 100644 index 0000000000000..fd1181c0281bd --- /dev/null +++ b/bundles/org.openhab.binding.emby/.project @@ -0,0 +1,23 @@ + + + org.openhab.binding.emby + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/bundles/org.openhab.binding.emby/NOTICE b/bundles/org.openhab.binding.emby/NOTICE new file mode 100644 index 0000000000000..38d625e349232 --- /dev/null +++ b/bundles/org.openhab.binding.emby/NOTICE @@ -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 diff --git a/bundles/org.openhab.binding.emby/README.md b/bundles/org.openhab.binding.emby/README.md new file mode 100644 index 0000000000000..0ed08706609f2 --- /dev/null +++ b/bundles/org.openhab.binding.emby/README.md @@ -0,0 +1,69 @@ +# Emby Binding + +The Emby Binding integrates EMBY support with openHAB, allowing both controlling the player as well as retrieving player status data like the currently played movie title. + +This binding supports multiple clients connected to a EMBY Media Server. This binding allows simlar integration and control in the same manner as the Plex Binding. For example with this binding, it's possible to dim your lights when a video starts playing. + +## Supported Things + +_Please describe the different supported things / devices within this section._ +_Which different types are supported, which models were tested etc.?_ +_Note that it is planned to generate some part of this based on the XML files within ```ESH-INF/thing``` of your binding._ + +## Discovery + +The binding will autodiscover all clients which are conneted to your EMBY media server. These clients will be added to the inbox after the first time they come online and begin playing media. This however only works once a connection to an EMBY media server has been established by creating the bridge thing type for the EMBY media server. + + +## Thing Configuration + +There are two types of things for this binding. The bridge type and the device. The bridge must be created before any device types will be generated. + +The bridge should be configured as follows: + +| Parameter | Description | +|---------|----------------------------------------------------------| +| API Key | This is the API key generated from EMBY used for Authorization. (Generated from your emby server at Dashboard -> Expert -> Advanced -> Security) | +| Web Socket Buffer Size | Here you can define a custom size for the websocket buffer size. Default is 100000. Increasing this can descrease server timeouts in certain cases | +| ipAddress | This is the ip address of the EMBY Server. | +| Port | This is the port of the EMBY server. | +| Refresh Parameter | This is the refresh interval in milliseconds that will be sent to the websocket. | + +## Channels + +An emby device that is automatically discovered will come with several preconfigured channels: + +| Channel Type | Item Type | Config Parameters | Description | +|--------------|----------------------|----------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| Control | Player | None | This channel will indicate the playing status of the device. It can also be used to send play/pause commands | +| Stop | Switch | None | This channel will indicate whether there is media currently playing on the device. When media is playing the channel will indicate ON. Sending a command of OFF to the channel will send a command to stop any currently playing media. | +| Title | String | None | Will show the title of the currently playing song | +| Mute | Switch | None | Indicates whether the device is muted. Sending a command of ON will send a mute command to the currently playing media. | +| ShowTitle | String | None | Will show the title of the currently playing movie or TV show. | +| Image URL | String | Image Max Height + Image Max Width + Image Type + Percent Played | This will produce a URL to the currently playing media. More information about the config parameters can be found at https://github.com/MediaBrowser/Emby/wiki/Images. | +| Current Time | Number:Time | None | The current play time of the playing media. | +| Duration | Number:Time | None | The length of time left in the current playing media item. | +| Media Type | String | None | Description | +| Send Play | String | None | Description | + + +## Full Example + +*.things +*.items +String EMBYWMCPosterImage_URL "URL: [%s]" (EMBY) {channel="emby:device:416bcb51:d96138c30b0b404cba7513ae09db7966:imageurl"} +String EMBYWMCTVStatus "Status [%s]"