replaced svglib with cairosvg, added ssdpy
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,3 +3,4 @@ build
|
|||||||
*.egg-info
|
*.egg-info
|
||||||
*.db
|
*.db
|
||||||
*.db-journal
|
*.db-journal
|
||||||
|
*.png
|
||||||
|
|||||||
3
setup.py
3
setup.py
@@ -30,7 +30,8 @@ setup(
|
|||||||
"jsonpickle==3.0.1",
|
"jsonpickle==3.0.1",
|
||||||
"streamdeck==0.9.3",
|
"streamdeck==0.9.3",
|
||||||
"pillow>=9.4.0,<10.0.0",
|
"pillow>=9.4.0,<10.0.0",
|
||||||
"svglib==1.5.1",
|
"cairosvg==2.7.0",
|
||||||
|
"ssdpy==0.4.1",
|
||||||
],
|
],
|
||||||
keywords=[],
|
keywords=[],
|
||||||
entry_points={
|
entry_points={
|
||||||
|
|||||||
@@ -5,3 +5,5 @@ VERSION = '0.0.3'
|
|||||||
PLUGIN_PORT = 6153
|
PLUGIN_PORT = 6153
|
||||||
PLUGIN_INFO = "/sd/info"
|
PLUGIN_INFO = "/sd/info"
|
||||||
PLUGIN_ICON = "/sd/icon"
|
PLUGIN_ICON = "/sd/icon"
|
||||||
|
|
||||||
|
SD_SSDP = "urn:home-assistant.io:device:stream-deck"
|
||||||
|
|||||||
@@ -13,16 +13,14 @@ from aiohttp import web
|
|||||||
from StreamDeck.DeviceManager import DeviceManager
|
from StreamDeck.DeviceManager import DeviceManager
|
||||||
from StreamDeck.Devices.StreamDeck import StreamDeck
|
from StreamDeck.Devices.StreamDeck import StreamDeck
|
||||||
from StreamDeck.ImageHelpers import PILHelper
|
from StreamDeck.ImageHelpers import PILHelper
|
||||||
from svglib.svglib import svg2rlg
|
import cairosvg
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
from ssdpy import SSDPServer
|
||||||
|
|
||||||
from streamdeckapi.const import PLUGIN_ICON, PLUGIN_INFO, PLUGIN_PORT
|
from streamdeckapi.const import PLUGIN_ICON, PLUGIN_INFO, PLUGIN_PORT, SD_SSDP
|
||||||
from streamdeckapi.types import SDApplication, SDButton, SDButtonPosition, SDDevice
|
from streamdeckapi.types import SDApplication, SDButton, SDButtonPosition, SDDevice
|
||||||
|
|
||||||
# TODO: MDI Icons not showing
|
|
||||||
# TODO: Text too small, positioning off
|
|
||||||
# TODO: Websocket broadcast not working yet
|
# TODO: Websocket broadcast not working yet
|
||||||
# TODO: SSDP server
|
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_ICON = re.sub(
|
DEFAULT_ICON = re.sub(
|
||||||
@@ -292,13 +290,14 @@ def update_button_icon(uuid: str, svg: str):
|
|||||||
|
|
||||||
def set_icon(deck: StreamDeck, key: int, svg: str):
|
def set_icon(deck: StreamDeck, key: int, svg: str):
|
||||||
"""Draw an icon to the button."""
|
"""Draw an icon to the button."""
|
||||||
svg_io = io.StringIO(svg)
|
png_bytes = io.BytesIO()
|
||||||
drawing = svg2rlg(svg_io)
|
cairosvg.svg2png(svg.encode("utf-8"), write_to=png_bytes)
|
||||||
png_string = drawing.asString("png")
|
|
||||||
png_bytes = io.BytesIO(png_string)
|
# Debug
|
||||||
|
cairosvg.svg2png(svg.encode("utf-8"), write_to=f"icon_{key}.png")
|
||||||
|
|
||||||
icon = Image.open(png_bytes)
|
icon = Image.open(png_bytes)
|
||||||
image = PILHelper.create_scaled_image(deck, icon, margins=[0, 0, 20, 0])
|
image = PILHelper.create_scaled_image(deck, icon)
|
||||||
|
|
||||||
deck.set_key_image(key, PILHelper.to_native_format(deck, image))
|
deck.set_key_image(key, PILHelper.to_native_format(deck, image))
|
||||||
|
|
||||||
@@ -357,3 +356,7 @@ def start():
|
|||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
loop.run_until_complete(start_server())
|
loop.run_until_complete(start_server())
|
||||||
loop.run_forever()
|
loop.run_forever()
|
||||||
|
|
||||||
|
# TODO: SSDP server
|
||||||
|
server = SSDPServer(SD_SSDP)
|
||||||
|
server.serve_forever()
|
||||||
|
|||||||
Reference in New Issue
Block a user