This commit is contained in:
parent
661984ff17
commit
5c7c8836f7
2 changed files with 6 additions and 4 deletions
|
@ -331,9 +331,9 @@ class HassUserClient(HassClient):
|
|||
},
|
||||
"player": {
|
||||
"unique_id": f"{self.node_id}_player",
|
||||
"p": "sensor",
|
||||
"p": "binary_sensor",
|
||||
"name": "Player",
|
||||
"icon": "mdi:music",
|
||||
"device_class": "running",
|
||||
"value_template": "{{ value_json.player.value }}",
|
||||
"json_attributes_topic": self.state_topic,
|
||||
"json_attributes_template": "{{ value_json.player.attributes | to_json }}",
|
||||
|
@ -381,6 +381,7 @@ class HassUserClient(HassClient):
|
|||
code, value = run_command(["playerctl", "status"])
|
||||
attrs = dict()
|
||||
if code == 0:
|
||||
res = "ON" if value == "Playing" else "OFF"
|
||||
for k in ["title", "album", "artist"]:
|
||||
code, v = run_command(["playerctl", "metadata", k])
|
||||
if code == 0:
|
||||
|
@ -389,9 +390,10 @@ class HassUserClient(HassClient):
|
|||
log.error(f"Failed to get metadata: {k}")
|
||||
else:
|
||||
log.debug("Player is not running")
|
||||
res = "OFF"
|
||||
|
||||
return {
|
||||
"value": value,
|
||||
"value": res,
|
||||
"attributes": attrs,
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ def run_command(cmd: list[str]) -> Tuple[int, str]:
|
|||
if proc.returncode != 0:
|
||||
return proc.returncode, ""
|
||||
|
||||
return proc.returncode, proc.stdout.decode("utf-8")
|
||||
return proc.returncode, proc.stdout.decode("utf-8").strip()
|
||||
|
||||
|
||||
def test_connection(host: str, port: int) -> bool:
|
||||
|
|
Loading…
Add table
Reference in a new issue