From 8867c7a4e351fc197e6c9ad0700fd9110b44fdc8 Mon Sep 17 00:00:00 2001 From: Farzad E Date: Fri, 27 May 2022 20:30:52 -0700 Subject: [PATCH 1/4] Added support for setting art mode mats --- example/art_remove_mats.py | 34 ++++++++++++++++++++++++++++++++++ samsungtvws/art.py | 19 +++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 example/art_remove_mats.py diff --git a/example/art_remove_mats.py b/example/art_remove_mats.py new file mode 100644 index 0000000..6caeecb --- /dev/null +++ b/example/art_remove_mats.py @@ -0,0 +1,34 @@ +import sys +import logging + +sys.path.append('../') + +from samsungtvws import SamsungTVWS + +# Increase debug level +logging.basicConfig(level=logging.INFO) + +# Normal constructor +tv = SamsungTVWS('192.168.xxx.xxx') + +# Set all mats to this type +target_matte_type = 'none' + +# Is art mode supported? +if not tv.art().supported(): + logging.error('Art mode not supported') + sys.exit(1) + +# List available mats for displaying art +matte_types = [matte_type for elem in tv.art().get_matte_list() for matte_type in elem.values()] +if target_matte_type not in matte_types: + logging.error('Invalid matte type: {}'.format(target_matte_type)) + sys.exit(1) + +# List the art available on the device +available_art = tv.art().available() + +for art in available_art: + if art['matte_id'] != target_matte_type: + logging.info("Setting matte to %s for %s", target_matte_type, art['content_id']) + tv.art().change_matte(art['content_id'], target_matte_type) diff --git a/samsungtvws/art.py b/samsungtvws/art.py index bded67a..8d0f7f9 100644 --- a/samsungtvws/art.py +++ b/samsungtvws/art.py @@ -338,3 +338,22 @@ def set_photo_filter(self, content_id, filter_id): "filter_id": filter_id, } ) + + def get_matte_list(self): + response = self._send_art_request( + {"request": "get_matte_list"}, + wait_for_event=D2D_SERVICE_MESSAGE_EVENT, + ) + assert response + data = json.loads(response["data"]) + + return json.loads(data["matte_type_list"]) + + def change_matte(self, content_id, matte_id): + self._send_art_request( + { + "request": "change_matte", + "content_id": content_id, + "matte_id": matte_id, + } + ) From 52baf84258f2354782e4b8043058e8371981dc5e Mon Sep 17 00:00:00 2001 From: Farzad E Date: Fri, 27 May 2022 21:01:12 -0700 Subject: [PATCH 2/4] Added tests for changing picture frame mats in art mode --- example/art_remove_mats.py | 4 ++-- tests/test_art.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/example/art_remove_mats.py b/example/art_remove_mats.py index 6caeecb..267e36b 100644 --- a/example/art_remove_mats.py +++ b/example/art_remove_mats.py @@ -22,7 +22,7 @@ # List available mats for displaying art matte_types = [matte_type for elem in tv.art().get_matte_list() for matte_type in elem.values()] if target_matte_type not in matte_types: - logging.error('Invalid matte type: {}'.format(target_matte_type)) + logging.error('Invalid matte type: {}. Supported matte types are: {}'.format(target_matte_type, matte_types)) sys.exit(1) # List the art available on the device @@ -30,5 +30,5 @@ for art in available_art: if art['matte_id'] != target_matte_type: - logging.info("Setting matte to %s for %s", target_matte_type, art['content_id']) + logging.info("Setting matte to {} for {}".format(target_matte_type, art['content_id'])) tv.art().change_matte(art['content_id'], target_matte_type) diff --git a/tests/test_art.py b/tests/test_art.py index 22fc8f5..7cd6305 100644 --- a/tests/test_art.py +++ b/tests/test_art.py @@ -92,3 +92,21 @@ def test_set_available(connection: Mock) -> None: connection.send.assert_called_once_with( '{"method": "ms.channel.emit", "params": {"event": "art_app_request", "to": "host", "data": "{\\"request\\": \\"get_content_list\\", \\"category\\": null, \\"id\\": \\"07e72228-7110-4655-aaa6-d81b5188c219\\"}"}}' ) + + +def test_change_matte(connection: Mock) -> None: + with patch( + "samsungtvws.art.uuid.uuid4", + return_value="07e72228-7110-4655-aaa6-d81b5188c219", + ): + connection.recv.side_effect = [ + MS_CHANNEL_CONNECT_SAMPLE, + MS_CHANNEL_READY_SAMPLE, + D2D_SERVICE_MESSAGE_AVAILABLE_SAMPLE, + ] + tv_art = SamsungTVArt("127.0.0.1") + tv_art.change_matte("test", "none") + + connection.send.assert_called_once_with( + '{"method": "ms.channel.emit", "params": {"event": "art_app_request", "to": "host", "data": "{\\"request\\": \\"change_matte\\", \\"content_id\\": \\"test\\", \\"matte_id\\": \\"none\\", \\"id\\": \\"07e72228-7110-4655-aaa6-d81b5188c219\\"}"}}' + ) From 752ff4b256ae061807b82607f61dd27728488aaa Mon Sep 17 00:00:00 2001 From: Farzad E Date: Sun, 29 May 2022 21:54:58 -0700 Subject: [PATCH 3/4] Style fix --- example/art_remove_mats.py | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/example/art_remove_mats.py b/example/art_remove_mats.py index 267e36b..952fb83 100644 --- a/example/art_remove_mats.py +++ b/example/art_remove_mats.py @@ -1,7 +1,7 @@ -import sys import logging +import sys -sys.path.append('../') +sys.path.append("../") from samsungtvws import SamsungTVWS @@ -9,26 +9,35 @@ logging.basicConfig(level=logging.INFO) # Normal constructor -tv = SamsungTVWS('192.168.xxx.xxx') +tv = SamsungTVWS("192.168.xxx.xxx") # Set all mats to this type -target_matte_type = 'none' +target_matte_type = "none" # Is art mode supported? if not tv.art().supported(): - logging.error('Art mode not supported') + logging.error("Art mode not supported") sys.exit(1) # List available mats for displaying art -matte_types = [matte_type for elem in tv.art().get_matte_list() for matte_type in elem.values()] +matte_types = [ + matte_type for elem in tv.art().get_matte_list() for matte_type in elem.values() +] + if target_matte_type not in matte_types: - logging.error('Invalid matte type: {}. Supported matte types are: {}'.format(target_matte_type, matte_types)) + logging.error( + "Invalid matte type: {}. Supported matte types are: {}".format( + target_matte_type, matte_types + ) + ) sys.exit(1) # List the art available on the device available_art = tv.art().available() for art in available_art: - if art['matte_id'] != target_matte_type: - logging.info("Setting matte to {} for {}".format(target_matte_type, art['content_id'])) - tv.art().change_matte(art['content_id'], target_matte_type) + if art["matte_id"] != target_matte_type: + logging.info( + "Setting matte to {} for {}".format(target_matte_type, art["content_id"]) + ) + tv.art().change_matte(art["content_id"], target_matte_type) From d0fa6a6033701cc93086e6519cf5fbdc74e2cf9b Mon Sep 17 00:00:00 2001 From: Farzad E Date: Sun, 29 May 2022 22:24:22 -0700 Subject: [PATCH 4/4] Ignore 'module level import not at top of file' error in art_remove_mats.py --- example/art_remove_mats.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/art_remove_mats.py b/example/art_remove_mats.py index 952fb83..12f8e12 100644 --- a/example/art_remove_mats.py +++ b/example/art_remove_mats.py @@ -3,7 +3,7 @@ sys.path.append("../") -from samsungtvws import SamsungTVWS +from samsungtvws import SamsungTVWS # noqa: E402 # Increase debug level logging.basicConfig(level=logging.INFO)