Skip to content

Commit

Permalink
Merge pull request #31 from Garulf/add-source-list-to-media_player-en…
Browse files Browse the repository at this point in the history
…tities
  • Loading branch information
Garulf authored Feb 5, 2022
2 parents 549681f + d02723b commit 294f611
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"Name": "HA-Commander",
"Description": "Search, and interact with Home Assistant using Wox or Flow Launcher.",
"Author": "Garulf",
"Version": "3.0.4",
"Version": "3.1.0",
"Language": "python",
"Website": "https://github.com/Garulf/HA-Commander",
"IcoPath": "icons\\home-assistant.png",
Expand Down
18 changes: 18 additions & 0 deletions plugin/homeassistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
import json
from functools import partial, wraps
import webbrowser
import logging

import requests
from requests.exceptions import ConnectionError, HTTPError

from icons import DEFAULT_ICONS

log = logging.getLogger(__name__)

COLORS_FILE = "./plugin/colors.json"
META_FILE = "./meta.json"

Expand Down Expand Up @@ -308,6 +311,21 @@ class MediaPlayer(Entity):

def __init__(self, client: Client, entity: dict) -> None:
super().__init__(client, entity)
for source in self.attributes.get("source_list", []):
setattr(self, source, partial(self._select_source, source))
getattr(self, source).name = source
getattr(self, source).__doc__ = 'Set Source to "{}"'.format(source)
getattr(self, source).icon = "radiobox-blank"
if source == self.attributes.get("source"):
getattr(self, source).icon = "radiobox-marked"
getattr(self, source).__doc__ = "Currently selected Source."

@service(icon="arrow-right")
def _select_source(self, source) -> None:
"""Select source."""
data = self.target
data["source"] = source
self._client.call_services("media_player", "select_source", data=data)

@service(icon="play")
def play(self) -> None:
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
requests==2.25.1
git+https://github.com/garulf/flox@v0.9.5#egg=flox
git+https://github.com/garulf/flox@v0.10.4#egg=flox-lib

0 comments on commit 294f611

Please sign in to comment.