Skip to content

Commit

Permalink
Revrite command "ST_PC" as "ST_VD:<src>" (FR #274)
Browse files Browse the repository at this point in the history
  • Loading branch information
ollo69 committed Jan 7, 2024
1 parent cd60e0f commit eee3dc8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
18 changes: 8 additions & 10 deletions custom_components/samsungtv_smart/api/smartthings.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
""" Smartthings TV integration """
from __future__ import annotations

from asyncio import TimeoutError as AsyncTimeoutError
from datetime import timedelta
from enum import Enum
import json
import logging
from typing import Dict, List, Optional

from aiohttp import ClientConnectionError, ClientResponseError, ClientSession

Expand Down Expand Up @@ -104,20 +104,20 @@
_LOGGER = logging.getLogger(__name__)


def _headers(api_key: str) -> Dict[str, str]:
def _headers(api_key: str) -> dict[str, str]:
return {
"Authorization": f"Bearer {api_key}",
"Accept": "application/json",
"Connection": "keep-alive",
}


def _command(command: Dict, arguments: Optional[List] = None):
cmd = {"commands": [{"component": "main"}]}
cmd["commands"][0].update(command)
def _command(command: dict, arguments: list | None = None):
cmd = {"component": "main", **command}
if arguments:
cmd["commands"][0]["arguments"] = arguments
return str(cmd)
cmd["arguments"] = arguments
cmd_full = {"commands": [cmd]}
return str(cmd_full)


class STStatus(Enum):
Expand All @@ -136,7 +136,7 @@ def __init__(
api_key: str,
device_id: str,
use_channel_info: bool = True,
session: Optional[ClientSession] = None,
session: ClientSession | None = None,
):
"""Initialize SmartThingsTV."""
self._api_key = api_key
Expand Down Expand Up @@ -556,8 +556,6 @@ async def async_select_vd_source(self, source):
# if source not in self._source_list:
# return
data_cmd = _command(COMMAND_SET_VD_SOURCE, [source])
# set property to reflect new changes
self._set_source(source)
await self._async_send_command(data_cmd)

async def async_set_sound_mode(self, mode):
Expand Down
9 changes: 5 additions & 4 deletions custom_components/samsungtv_smart/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,8 +668,9 @@ async def _smartthings_keys(self, source_key: str):
await self._st.async_select_source(source_key.replace("ST_", ""))
elif source_key == "ST_TV":
await self._st.async_select_source("digitalTv")
elif source_key == "ST_PC":
await self._st.async_select_vd_source(source_key.replace("ST_", ""))
elif source_key.startswith("ST_VD:"):
if cmd := source_key.replace("ST_VD:", ""):
await self._st.async_select_vd_source(cmd)
elif source_key == "ST_CHUP":
await self._st.async_send_command("stepchannel", "up")
elif source_key == "ST_CHDOWN":
Expand All @@ -691,8 +692,8 @@ async def _smartthings_keys(self, source_key: str):
if vol_lev.isdigit():
await self._st.async_send_command("setvolume", vol_lev)
else:
_LOGGER.error("Unsupported SmartThings command: %s", source_key)
return False
raise ValueError(f"Unsupported SmartThings command: {source_key}")

return True

def _log_st_error(self, st_error: bool):
Expand Down
8 changes: 6 additions & 2 deletions docs/Smartthings.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ To identify your TV device ID use the following steps:

- Go [here](https://my.smartthings.com/advanced/devices) and login with your SmartThings credential
- Click on the name of your TV from the list of available devices
- In the new page search the colump called `Device ID`
- In the new page search the column called `Device ID`
- Copy the value (is a UUID code) and paste it in the HomeAssistant configuration page


Expand All @@ -50,13 +50,17 @@ ____________
Key|Description
---|-----------
ST_TV|TV
ST_PC|PC
ST_VD:`src`|`src`
ST_HDMI1|HDMI1
ST_HDMI2|HDMI2
ST_HDMI3|HDMI3
ST_HDMI4|HDMI4
...


With ST_VD:`src` replace `src` with the name of the source you want activate


*Channel Keys*
______________
Key|Description
Expand Down

0 comments on commit eee3dc8

Please sign in to comment.