From 16e35cd65202f5de38834bc8f04c1dc62cf61962 Mon Sep 17 00:00:00 2001 From: spacemanspiff2007 <10754716+spacemanspiff2007@users.noreply.github.com> Date: Tue, 12 Jan 2021 09:35:20 +0100 Subject: [PATCH] 0.19.1 (#196) 0.19.1 - Text header is now properly set (fix for empty strings) - Added info about openhabian --- HABApp/__version__.py | 2 +- .../connection_handler/http_connection.py | 18 ++++++++++++++++-- _doc/installation.rst | 4 +++- conf_testing/lib/HABAppTests/_rest_patcher.py | 13 ++++++++++--- conf_testing/lib/HABAppTests/test_data.py | 2 +- 5 files changed, 31 insertions(+), 8 deletions(-) diff --git a/HABApp/__version__.py b/HABApp/__version__.py index e3dceae5..2d1ae652 100644 --- a/HABApp/__version__.py +++ b/HABApp/__version__.py @@ -1 +1 @@ -__version__ = '0.19.0' +__version__ = '0.19.1' diff --git a/HABApp/openhab/connection_handler/http_connection.py b/HABApp/openhab/connection_handler/http_connection.py index b5b257a4..ee6b4efd 100644 --- a/HABApp/openhab/connection_handler/http_connection.py +++ b/HABApp/openhab/connection_handler/http_connection.py @@ -65,8 +65,15 @@ async def post(url: str, log_404=True, json=None, data=None, **kwargs: Any) -> O assert not url.startswith('/'), url url = f'{HTTP_PREFIX}/rest/{url}/' + # todo: remove this workaround once there is a fix in aiohttp + headers = None + if data is not None: + headers = {'Content-Type': 'text/plain; charset=utf-8'} + mgr = _RequestContextManager( - HTTP_SESSION._request(METH_POST, url, allow_redirects=HTTP_ALLOW_REDIRECTS, data=data, json=json, **kwargs) + HTTP_SESSION._request( + METH_POST, url, allow_redirects=HTTP_ALLOW_REDIRECTS, headers=headers, data=data, json=json, **kwargs + ) ) if data is None: @@ -84,8 +91,15 @@ async def put(url: str, log_404=True, json=None, data=None, **kwargs: Any) -> Op assert not url.startswith('/'), url url = f'{HTTP_PREFIX}/rest/{url}/' + # todo: remove this workaround once there is a fix in aiohttp + headers = None + if data is not None: + headers = {'Content-Type': 'text/plain; charset=utf-8'} + mgr = _RequestContextManager( - HTTP_SESSION._request(METH_PUT, url, allow_redirects=HTTP_ALLOW_REDIRECTS, data=data, json=json, **kwargs) + HTTP_SESSION._request( + METH_PUT, url, allow_redirects=HTTP_ALLOW_REDIRECTS, headers=headers, data=data, json=json, **kwargs + ) ) if data is None: diff --git a/_doc/installation.rst b/_doc/installation.rst index 1240a24e..25a74bfb 100644 --- a/_doc/installation.rst +++ b/_doc/installation.rst @@ -12,7 +12,9 @@ Installation ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. hint:: - HABApp requires at least Python 3.6 + With openhabian the installation can be performed through the openhabian-config tool (option 2B). + HABApp will be installed into ``/opt/habapp``, so it is the same as the installation described here. + .. hint:: On Windows use the ``python`` command instead of ``python3`` diff --git a/conf_testing/lib/HABAppTests/_rest_patcher.py b/conf_testing/lib/HABAppTests/_rest_patcher.py index 1c4d7bac..e2f54409 100644 --- a/conf_testing/lib/HABAppTests/_rest_patcher.py +++ b/conf_testing/lib/HABAppTests/_rest_patcher.py @@ -27,11 +27,18 @@ async def resp_wrap(*args, **kwargs): resp = await to_call(*args, **kwargs) out = '' - if kwargs.get('json'): + if kwargs.get('json') is not None: out = f' {kwargs["json"]}' - if kwargs.get('data'): + if kwargs.get('data') is not None: out = f' "{kwargs["data"]}"' - self.log.debug(f'{resp.request_info.method:^6s} {shorten_url(resp.request_info.url)} ({resp.status}){out}') + + self.log.debug( + f'{resp.request_info.method:^6s} {shorten_url(resp.request_info.url)} ({resp.status}){out}' + ) + + if resp.status >= 300: + self.log.debug(f'{"":6s} Header request : {resp.request_info.headers}') + self.log.debug(f'{"":6s} Header response: {resp.headers}') def wrap_content(content_func): async def content_func_wrap(*cargs, **ckwargs): diff --git a/conf_testing/lib/HABAppTests/test_data.py b/conf_testing/lib/HABAppTests/test_data.py index c59e6e0e..294d3ac1 100644 --- a/conf_testing/lib/HABAppTests/test_data.py +++ b/conf_testing/lib/HABAppTests/test_data.py @@ -19,7 +19,7 @@ 'Number': [-111, 222, -13.13, 55.55], 'Player': ["PLAY", "PAUSE", "REWIND", "FASTFORWARD"], 'Rollershutter': [0, 100, 30.5], - 'String': ['A', 'B', 'C', 'öäüß'], + 'String': ['A', 'B', 'C', '', 'öäüß'], 'Switch': ['ON', 'OFF'], }