added server example

This commit is contained in:
Patrick762
2023-04-23 15:00:02 +02:00
parent 40368ab5f8
commit 9b8d3574c2
6 changed files with 35 additions and 9 deletions

2
.gitignore vendored
View File

@@ -1 +1,3 @@
**/__pycache__/ **/__pycache__/
build
*.egg-info

View File

@@ -7,3 +7,9 @@ Only compatible with separate [Stream Deck Plugin](https://github.com/Patrick762
## Dependencies ## Dependencies
- [websockets](https://pypi.org/project/websockets/) 11.0.2 - [websockets](https://pypi.org/project/websockets/) 11.0.2
## Server
This library also contains a server to use the streamdeck with linux or without the official Stream Deck Software.
For this to work, the LibUSB HIDAPI is required. [Installation instructions](https://python-elgato-streamdeck.readthedocs.io/en/stable/pages/backend_libusb_hidapi.html)

View File

@@ -7,7 +7,7 @@ here = os.path.abspath(os.path.dirname(__file__))
with codecs.open(os.path.join(here, "README.md"), encoding="utf-8") as fh: with codecs.open(os.path.join(here, "README.md"), encoding="utf-8") as fh:
long_description = "\n" + fh.read() long_description = "\n" + fh.read()
VERSION = '0.0.2' VERSION = '0.0.3'
DESCRIPTION = 'Stream Deck API Library' DESCRIPTION = 'Stream Deck API Library'
# Setting up # Setting up
@@ -21,8 +21,12 @@ setup(
long_description=long_description, long_description=long_description,
url="https://github.com/Patrick762/streamdeckapi", url="https://github.com/Patrick762/streamdeckapi",
packages=find_packages(), packages=find_packages(),
install_requires=["websockets==11.0.2"], install_requires=["websockets==11.0.2",
"streamdeck==0.9.3", "pillow>=9.4.0,<10.0.0"],
keywords=[], keywords=[],
entry_points={
"console_scripts": ["streamdeckapi-server = streamdeckapi.server:start"]
},
classifiers=[ classifiers=[
"Development Status :: 1 - Planning", "Development Status :: 1 - Planning",
"Intended Audience :: Developers", "Intended Audience :: Developers",

View File

@@ -9,11 +9,9 @@ import requests
from websockets.client import connect from websockets.client import connect
from websockets.exceptions import WebSocketException from websockets.exceptions import WebSocketException
from .types import SDInfo, SDWebsocketMessage from streamdeckapi.const import PLUGIN_ICON, PLUGIN_INFO, PLUGIN_PORT
_PLUGIN_PORT = 6153 from .types import SDInfo, SDWebsocketMessage
_PLUGIN_INFO = "/sd/info"
_PLUGIN_ICON = "/sd/icon"
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@@ -53,17 +51,17 @@ class StreamDeckApi:
@property @property
def _info_url(self) -> str: def _info_url(self) -> str:
"""URL to info endpoint.""" """URL to info endpoint."""
return f"http://{self._host}:{_PLUGIN_PORT}{_PLUGIN_INFO}" return f"http://{self._host}:{PLUGIN_PORT}{PLUGIN_INFO}"
@property @property
def _icon_url(self) -> str: def _icon_url(self) -> str:
"""URL to icon endpoint.""" """URL to icon endpoint."""
return f"http://{self._host}:{_PLUGIN_PORT}{_PLUGIN_ICON}/" return f"http://{self._host}:{PLUGIN_PORT}{PLUGIN_ICON}/"
@property @property
def _websocket_url(self) -> str: def _websocket_url(self) -> str:
"""URL to websocket.""" """URL to websocket."""
return f"ws://{self._host}:{_PLUGIN_PORT}" return f"ws://{self._host}:{PLUGIN_PORT}"
# #
# API Methods # API Methods

5
streamdeckapi/const.py Normal file
View File

@@ -0,0 +1,5 @@
"""Stream Deck API const."""
PLUGIN_PORT = 6153
PLUGIN_INFO = "/sd/info"
PLUGIN_ICON = "/sd/icon"

11
streamdeckapi/server.py Normal file
View File

@@ -0,0 +1,11 @@
"""Stream Deck API Server."""
from StreamDeck.DeviceManager import DeviceManager
from streamdeckapi.const import PLUGIN_ICON, PLUGIN_INFO, PLUGIN_PORT
def start():
streamdecks = DeviceManager().enumerate()
print("Found {} Stream Deck(s).\n".format(len(streamdecks)))
print("Started Stream Deck API server on port", PLUGIN_PORT)