Skip to content

Commit ff83360

Browse files
committed
v0.5.1
1 parent ea814c0 commit ff83360

File tree

4 files changed

+37
-21
lines changed

4 files changed

+37
-21
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.5.1] - 2024-12-18
9+
10+
### Added
11+
12+
- Text over TCP: Added support for C++ and hex style control characters to e.g. add a new line, tab or a carriage return
13+
- C++ style characters can be escaped with a single additional backslash (e.g. \\\n)
14+
- Hex style characters can be escaped with "0\\\\\\" (e.g. 0\\\\\\0x09)
15+
816
## [0.5.0] - 2024-12-15
917

1018
### Added

README.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ Using [uc-integration-api](https://github.com/aitatoi/integration-python-library
1212

1313
- [Configuration](#configuration)
1414
- [Usage](#usage)
15-
- [Wake-on-lan](#wake-on-lan)
15+
- [1 - Wake-on-lan](#1---wake-on-lan)
1616
- [Supported parameters](#supported-parameters)
17-
- [HTTP requests](#http-requests)
17+
- [2 - HTTP requests](#2---http-requests)
1818
- [Expected server response](#expected-server-response)
1919
- [Adding payload data](#adding-payload-data)
2020
- [Only one payload type per requests is supported](#only-one-payload-type-per-requests-is-supported)
21-
- [Text over TCP](#text-over-tcp)
21+
- [3 - Text over TCP](#3---text-over-tcp)
22+
- [Control characters](#control-characters)
23+
- [Escaping](#escaping)
2224
- [Installation](#installation)
2325
- [Run on the remote as a custom integration driver](#run-on-the-remote-as-a-custom-integration-driver)
2426
- [Missing firmware features](#missing-firmware-features)
@@ -67,15 +69,15 @@ During the integration setup you can change the default http request timeout of
6769

6870
The integration exposes a media player entity for each supported request command. These entities only support the source feature. Just enter the desired url (including http(s)://) or mac address in the source field when you configure your activity/macro sequences or activity ui.
6971

70-
### Wake-on-lan
72+
### 1 - Wake-on-lan
7173

7274
Choose the Wake on lan entity from the integration setup and add it to an activity or macro. Enter the desired hostname, mac or ip address (ipv4/v6) in the source field when you configure your activity/macro sequence or activity ui. Multiple addresses can be separated by a comma.
7375

7476
#### Supported parameters
7577

7678
All parameters from [pywakeonlan](https://github.com/remcohaszing/pywakeonlan) are supported (interface, port, ip_address)
7779

78-
### HTTP requests
80+
### 2 - HTTP requests
7981

8082
Choose one or more HTTP request method entities from the integration setup and add it to an activity or macro. Enter the desired url (including http(s)://) in the source field when you configure your activity/macro sequences or activity ui.
8183

@@ -99,12 +101,21 @@ Optional payload data can be added to the request body with a specific separator
99101

100102
If your actual url contains one or more of the above separators or other special characters that are not url reserved control characters you need to url-encode them first (e.g. with <https://www.urlencoder.io>)
101103

102-
### Text over TCP
104+
### 3 - Text over TCP
103105

104106
This protocol is used by some home automation systems, IoT devices or tools like [win-remote-control](https://github.com/moefh/win-remote-control).
105107

106108
Example: 192.168.1.1:1234, "Hello World"
107109

110+
#### Control characters
111+
112+
C++ and hex style control characters are supported to e.g. add a new line (\\n or 0x0A), tab (\\t or 0x09) or a carriage return (\\r or 0x0D)
113+
114+
##### Escaping
115+
116+
- C++ style characters can be escaped with a single additional backslash (e.g. \\\n)
117+
- Hex style characters can be escaped with "0\\\\\\" (e.g. 0\\\\\\0x09)
118+
108119
## Installation
109120

110121
### Run on the remote as a custom integration driver

driver.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"driver_id": "requests",
3-
"version": "0.5.0",
4-
"release_date": "2024-12-14",
3+
"version": "0.5.1",
4+
"release_date": "2024-12-18",
55
"min_core_api": "0.24.3",
66
"name": {
77
"en": "HTTP requests, WoL & text over TCP",

intg-requests/media_player.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -185,27 +185,25 @@ def async_rq_cmd(rq_cmd: str, url: str, data: str = None, xml: bool = False):
185185

186186
def tcp_text_process_control_data(data):
187187
"""
188-
Processes a string with hex notation and/or C++ style control characters.
189-
- `0xHH` is interpreted as a control character.
190-
- `\\0xHH` remains as literal `0xHH`. Use a single backslash in the remote source string because an addition backslash is added afterwards
191-
- C++ escape sequences such as `\n`, `\t` are processed and can be escaped with a single backslash
188+
- Hex style characters such as "0x09" are processed and can be be escaped with "0\\\" (e.g. 0\\\x09)
189+
- C++ control characters such as "\n", "\t" are also processed and can be escaped with a single additional backslash (e.g. \\n)
192190
"""
193-
194-
# Schritt 1: Behandle Literal-Hex-Werte (\\0xHH) - als 0xHH beibehalten
191+
192+
# Search for hex style escape characters (starting with \\)
195193
def replace_literal_hex(match):
196-
return match.group(0) # Den gesamten Literal-Wert als Literal zurückgeben (einschließlich \)
194+
return match.group(1) # Den gesamten Literal-Wert als Literal zurückgeben (einschließlich \)
197195

198-
# Ersetze \\0xHH (mit doppeltem Backslash) durch den Literal-Wert
196+
# replace \\0xHH (with a double backslash) through string/literal value
199197
data = sub(r"\\\\(0x[0-9A-Fa-f]{2})", replace_literal_hex, data)
200198

201-
# Schritt 2: Behandle echte Steuerzeichen (0xHH) - Steuerzeichen ersetzen
199+
# Match real hex style control characters (0xHH)
202200
def replace_control_hex(match):
203-
return chr(int(match.group(1), 16)) # Hex-Wert in Steuerzeichen umwandeln
201+
return chr(int(match.group(1), 16))
204202

205-
# Ersetze 0xHH durch das entsprechende Steuerzeichen (nur ohne Backslash)
203+
# Replace 0xHH with the corresponding control character
206204
data = sub(r"(?<!\\)(0x[0-9A-Fa-f]{2})", replace_control_hex, data)
207205

208-
# Schritt 3: Verarbeite C++-Escape-Sequenzen (\n, \t, etc.)
206+
# Process C++ style control characters (\n, \t, etc.)
209207
data = data.encode("utf-8").decode("unicode_escape")
210208

211209
return data
@@ -219,7 +217,6 @@ async def async_tcp_text_cmd(cmd_param:str) -> str:
219217
port = int(port)
220218
data = data.strip().strip('"\'') #Remove spaces and (double) quotes at the beginning and the end
221219
data = tcp_text_process_control_data(data)
222-
#data = data.encode("utf-8").decode("unicode_escape") #Convert possible control characters like \n or \r from the string. Escaped characters (e.g. \\n) will not be converted
223220

224221
try:
225222
reader, writer = await asyncio.open_connection(host, port)

0 commit comments

Comments
 (0)