TISControlProtocol 1.0.36__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. tiscontrolprotocol-1.0.36/.gitignore +2 -0
  2. tiscontrolprotocol-1.0.36/.vscode/c_cpp_properties.json +18 -0
  3. tiscontrolprotocol-1.0.36/.vscode/launch.json +24 -0
  4. tiscontrolprotocol-1.0.36/.vscode/settings.json +67 -0
  5. tiscontrolprotocol-1.0.36/.vscode/tasks.json +43 -0
  6. tiscontrolprotocol-1.0.36/LICENSE +21 -0
  7. tiscontrolprotocol-1.0.36/MANIFEST.in +1 -0
  8. tiscontrolprotocol-1.0.36/PKG-INFO +51 -0
  9. tiscontrolprotocol-1.0.36/README.md +37 -0
  10. tiscontrolprotocol-1.0.36/dev/pump_version.py +53 -0
  11. tiscontrolprotocol-1.0.36/pyproject.toml +25 -0
  12. tiscontrolprotocol-1.0.36/src/TISControlProtocol/BytesHelper.py +65 -0
  13. tiscontrolprotocol-1.0.36/src/TISControlProtocol/Protocols/__init__.py +18 -0
  14. tiscontrolprotocol-1.0.36/src/TISControlProtocol/Protocols/udp/AckCoordinator.py +50 -0
  15. tiscontrolprotocol-1.0.36/src/TISControlProtocol/Protocols/udp/PacketDispatcher.py +20 -0
  16. tiscontrolprotocol-1.0.36/src/TISControlProtocol/Protocols/udp/PacketExtractor.py +22 -0
  17. tiscontrolprotocol-1.0.36/src/TISControlProtocol/Protocols/udp/PacketHandlers/AnalogFeedbackHandler.py +23 -0
  18. tiscontrolprotocol-1.0.36/src/TISControlProtocol/Protocols/udp/PacketHandlers/AutoBinaryFeedbackHandler.py +18 -0
  19. tiscontrolprotocol-1.0.36/src/TISControlProtocol/Protocols/udp/PacketHandlers/BinaryFeedbackHandler.py +17 -0
  20. tiscontrolprotocol-1.0.36/src/TISControlProtocol/Protocols/udp/PacketHandlers/ClimateBinaryFeedbackHandler.py +62 -0
  21. tiscontrolprotocol-1.0.36/src/TISControlProtocol/Protocols/udp/PacketHandlers/ClimateControlFeedbackHandler.py +48 -0
  22. tiscontrolprotocol-1.0.36/src/TISControlProtocol/Protocols/udp/PacketHandlers/ControlResponseHandler.py +34 -0
  23. tiscontrolprotocol-1.0.36/src/TISControlProtocol/Protocols/udp/PacketHandlers/DiscoveryFeedbackHandler.py +10 -0
  24. tiscontrolprotocol-1.0.36/src/TISControlProtocol/Protocols/udp/PacketHandlers/EnergyFeedbackHandler.py +84 -0
  25. tiscontrolprotocol-1.0.36/src/TISControlProtocol/Protocols/udp/PacketHandlers/FloorBinaryFeedbackHandler.py +23 -0
  26. tiscontrolprotocol-1.0.36/src/TISControlProtocol/Protocols/udp/PacketHandlers/HealthFeedbackHandler.py +58 -0
  27. tiscontrolprotocol-1.0.36/src/TISControlProtocol/Protocols/udp/PacketHandlers/LunaTempFeedbackHandler.py +22 -0
  28. tiscontrolprotocol-1.0.36/src/TISControlProtocol/Protocols/udp/PacketHandlers/RealTimeFeedbackHandler.py +35 -0
  29. tiscontrolprotocol-1.0.36/src/TISControlProtocol/Protocols/udp/PacketHandlers/SearchResponseHandler.py +14 -0
  30. tiscontrolprotocol-1.0.36/src/TISControlProtocol/Protocols/udp/PacketHandlers/SecurityFeedbackHandler.py +41 -0
  31. tiscontrolprotocol-1.0.36/src/TISControlProtocol/Protocols/udp/PacketHandlers/UpdateResponseHandler.py +17 -0
  32. tiscontrolprotocol-1.0.36/src/TISControlProtocol/Protocols/udp/PacketHandlers/UpdateSecurityHandler.py +34 -0
  33. tiscontrolprotocol-1.0.36/src/TISControlProtocol/Protocols/udp/PacketHandlers/WeatherFeedbackHandler.py +45 -0
  34. tiscontrolprotocol-1.0.36/src/TISControlProtocol/Protocols/udp/PacketHandlers/__init__.py +1 -0
  35. tiscontrolprotocol-1.0.36/src/TISControlProtocol/Protocols/udp/PacketProtocol.py +81 -0
  36. tiscontrolprotocol-1.0.36/src/TISControlProtocol/Protocols/udp/PacketReceiver.py +35 -0
  37. tiscontrolprotocol-1.0.36/src/TISControlProtocol/Protocols/udp/PacketSender.py +78 -0
  38. tiscontrolprotocol-1.0.36/src/TISControlProtocol/Protocols/udp/ProtocolHandler.py +508 -0
  39. tiscontrolprotocol-1.0.36/src/TISControlProtocol/Protocols/udp/UpdateCoordinator.py +2 -0
  40. tiscontrolprotocol-1.0.36/src/TISControlProtocol/Protocols/udp/__init__.py +6 -0
  41. tiscontrolprotocol-1.0.36/src/TISControlProtocol/__init__.py +8 -0
  42. tiscontrolprotocol-1.0.36/src/TISControlProtocol/api.py +400 -0
  43. tiscontrolprotocol-1.0.36/src/TISControlProtocol/apis/__init__.py +43 -0
  44. tiscontrolprotocol-1.0.36/src/TISControlProtocol/apis/bill_config_endpoint.py +55 -0
  45. tiscontrolprotocol-1.0.36/src/TISControlProtocol/apis/change_password_endpoint.py +103 -0
  46. tiscontrolprotocol-1.0.36/src/TISControlProtocol/apis/get_bill_config_endpoint.py +28 -0
  47. tiscontrolprotocol-1.0.36/src/TISControlProtocol/apis/get_key_endpoint.py +26 -0
  48. tiscontrolprotocol-1.0.36/src/TISControlProtocol/apis/password_dashboard.py +28 -0
  49. tiscontrolprotocol-1.0.36/src/TISControlProtocol/apis/password_form_endpoint.py +18 -0
  50. tiscontrolprotocol-1.0.36/src/TISControlProtocol/apis/passwords_endpoint.py +44 -0
  51. tiscontrolprotocol-1.0.36/src/TISControlProtocol/apis/restart_endpoint.py +42 -0
  52. tiscontrolprotocol-1.0.36/src/TISControlProtocol/apis/scan_devices_endpoint.py +48 -0
  53. tiscontrolprotocol-1.0.36/src/TISControlProtocol/apis/shared.py +1 -0
  54. tiscontrolprotocol-1.0.36/src/TISControlProtocol/apis/submit_password.py +41 -0
  55. tiscontrolprotocol-1.0.36/src/TISControlProtocol/apis/tis_endpoint.py +33 -0
  56. tiscontrolprotocol-1.0.36/src/TISControlProtocol/apis/update_endpoint.py +87 -0
  57. tiscontrolprotocol-1.0.36/src/TISControlProtocol/crc.py +306 -0
  58. tiscontrolprotocol-1.0.36/src/TISControlProtocol/logo.png +0 -0
  59. tiscontrolprotocol-1.0.36/src/TISControlProtocol/shared.py +35 -0
  60. tiscontrolprotocol-1.0.36/src/TISControlProtocol/views/__init__.py +0 -0
  61. tiscontrolprotocol-1.0.36/src/TISControlProtocol/views/password_dashboard/index.html +300 -0
  62. tiscontrolprotocol-1.0.36/src/TISControlProtocol/views/password_dashboard/styles.css +1 -0
  63. tiscontrolprotocol-1.0.36/src/TISControlProtocol/views/password_form/index.html +149 -0
  64. tiscontrolprotocol-1.0.36/src/TISControlProtocol/views/password_form/styles.css +1 -0
  65. tiscontrolprotocol-1.0.36/tests/test.py +64 -0
@@ -0,0 +1,2 @@
1
+ .env
2
+ dist
@@ -0,0 +1,18 @@
1
+ {
2
+ "configurations": [
3
+ {
4
+ "name": "windows-gcc-x64",
5
+ "includePath": [
6
+ "${workspaceFolder}/**"
7
+ ],
8
+ "compilerPath": "gcc",
9
+ "cStandard": "${default}",
10
+ "cppStandard": "${default}",
11
+ "intelliSenseMode": "windows-gcc-x64",
12
+ "compilerArgs": [
13
+ ""
14
+ ]
15
+ }
16
+ ],
17
+ "version": 4
18
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "version": "0.2.0",
3
+ "configurations": [
4
+ {
5
+ "name": "C/C++ Runner: Debug Session",
6
+ "type": "cppdbg",
7
+ "request": "launch",
8
+ "args": [],
9
+ "stopAtEntry": false,
10
+ "externalConsole": true,
11
+ "cwd": "d:/TIS/dev/TISControlProtocol",
12
+ "program": "d:/TIS/dev/TISControlProtocol/build/Debug/outDebug",
13
+ "MIMode": "gdb",
14
+ "miDebuggerPath": "gdb",
15
+ "setupCommands": [
16
+ {
17
+ "description": "Enable pretty-printing for gdb",
18
+ "text": "-enable-pretty-printing",
19
+ "ignoreFailures": true
20
+ }
21
+ ]
22
+ }
23
+ ]
24
+ }
@@ -0,0 +1,67 @@
1
+ {
2
+ "C_Cpp_Runner.cCompilerPath": "gcc",
3
+ "C_Cpp_Runner.cppCompilerPath": "g++",
4
+ "C_Cpp_Runner.debuggerPath": "gdb",
5
+ "C_Cpp_Runner.cStandard": "",
6
+ "C_Cpp_Runner.cppStandard": "",
7
+ "C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/VR_NR/Community/VC/Auxiliary/Build/vcvarsall.bat",
8
+ "C_Cpp_Runner.useMsvc": false,
9
+ "C_Cpp_Runner.warnings": [
10
+ "-Wall",
11
+ "-Wextra",
12
+ "-Wpedantic",
13
+ "-Wshadow",
14
+ "-Wformat=2",
15
+ "-Wcast-align",
16
+ "-Wconversion",
17
+ "-Wsign-conversion",
18
+ "-Wnull-dereference"
19
+ ],
20
+ "C_Cpp_Runner.msvcWarnings": [
21
+ "/W4",
22
+ "/permissive-",
23
+ "/w14242",
24
+ "/w14287",
25
+ "/w14296",
26
+ "/w14311",
27
+ "/w14826",
28
+ "/w44062",
29
+ "/w44242",
30
+ "/w14905",
31
+ "/w14906",
32
+ "/w14263",
33
+ "/w44265",
34
+ "/w14928"
35
+ ],
36
+ "C_Cpp_Runner.enableWarnings": true,
37
+ "C_Cpp_Runner.warningsAsError": false,
38
+ "C_Cpp_Runner.compilerArgs": [],
39
+ "C_Cpp_Runner.linkerArgs": [],
40
+ "C_Cpp_Runner.includePaths": [],
41
+ "C_Cpp_Runner.includeSearch": [
42
+ "*",
43
+ "**/*"
44
+ ],
45
+ "C_Cpp_Runner.excludeSearch": [
46
+ "**/build",
47
+ "**/build/**",
48
+ "**/.*",
49
+ "**/.*/**",
50
+ "**/.vscode",
51
+ "**/.vscode/**"
52
+ ],
53
+ "C_Cpp_Runner.useAddressSanitizer": false,
54
+ "C_Cpp_Runner.useUndefinedSanitizer": false,
55
+ "C_Cpp_Runner.useLeakSanitizer": false,
56
+ "C_Cpp_Runner.showCompilationTime": false,
57
+ "C_Cpp_Runner.useLinkTimeOptimization": false,
58
+ "C_Cpp_Runner.msvcSecureNoWarnings": false,
59
+ "cSpell.words": [
60
+ "clientsession",
61
+ "DGRAM",
62
+ "dotenv",
63
+ "Fernet",
64
+ "hass",
65
+ "homeassistant"
66
+ ]
67
+ }
@@ -0,0 +1,43 @@
1
+ {
2
+ "version": "2.0.0",
3
+ "tasks": [
4
+ {
5
+ "label": "Update Version",
6
+ "type": "shell",
7
+ "command": "python",
8
+ "args": [
9
+ "${workspaceFolder}/dev/pump_version.py",
10
+ "${workspaceFolder}/pyproject.toml"
11
+ ],
12
+ "problemMatcher": [],
13
+ "detail": "Interactively update the version in pyproject.toml."
14
+ },
15
+ {
16
+ "label": "Build Package",
17
+ "type": "shell",
18
+ "command": "python",
19
+ "args": ["-m", "build"],
20
+ "problemMatcher": [],
21
+ "detail": "Build the latest version of the package.",
22
+ "group": {
23
+ "kind": "build",
24
+ "isDefault": true
25
+ }
26
+ },
27
+ {
28
+ "label": "Upload Package",
29
+ "type": "shell",
30
+ "command": "python",
31
+ "args": ["-m", "twine", "upload", "dist/*"],
32
+ "problemMatcher": [],
33
+ "detail": "Upload the latest version of the package to PyPI."
34
+ },
35
+ {
36
+ "label": "Update, Build, and Upload",
37
+ "dependsOn": ["Update Version", "Build Package", "Upload Package"],
38
+ "dependsOrder": "sequence",
39
+ "problemMatcher": [],
40
+ "detail": "Update the version, build the package, and upload it to PyPI."
41
+ }
42
+ ]
43
+ }
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) [year] [fullname]
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ recursive-include src/TISControlProtocol/views *
@@ -0,0 +1,51 @@
1
+ Metadata-Version: 2.4
2
+ Name: TISControlProtocol
3
+ Version: 1.0.36
4
+ Summary: A library for TIS Control Protocol
5
+ Project-URL: Homepage, https://github.com/TISControlHass
6
+ Project-URL: Issues, https://github.com/TISControlHass/issues
7
+ Author-email: Ibrahim Mohamed <ibrali2001.ia@gmail.com>
8
+ License-File: LICENSE
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: POSIX :: Linux
11
+ Classifier: Programming Language :: Python :: 3
12
+ Requires-Python: >=3.11
13
+ Description-Content-Type: text/markdown
14
+
15
+ # TISControlProtocol
16
+
17
+ ![Build Status](https://img.shields.io/badge/build-passing-brightgreen)
18
+ ![Version 0.1.0](https://img.shields.io/badge/version-3.0.0-blue)
19
+ ![License MIT](https://img.shields.io/badge/license-MIT-green)
20
+
21
+ TISControlProtocol is a powerful Python package for controlling TIS devices. It provides a simple and intuitive API for interacting with TIS devices, making it easy to integrate TIS devices into your Python applications.
22
+
23
+ ## Features
24
+
25
+ - ✅ Fully Supports Asynchronous Operations
26
+ - ✅ Flawless feedback mechanism to prevent data loss
27
+ - ✅ Debounce mechanism to prevent multiple commands from being sent for protection
28
+ - ✅ Easy to use API for controlling TIS devices
29
+ - ✅ Clean and simple codebase
30
+ - ✅ Ready to integrate with Home Assistant
31
+
32
+ ## Installation
33
+
34
+ You can install TISControlProtocol by adding it to your Manifest file or by using pip. Here's how you can install it using pip:
35
+
36
+ ```bash
37
+ pip install TISControlProtocol
38
+ ```
39
+
40
+ ## Building
41
+
42
+ To build the package, you can use the following commands:
43
+
44
+ ```bash
45
+ python -m build
46
+ twine upload dist/*
47
+ ```
48
+
49
+ ## License
50
+
51
+ TISControlProtocol is licensed under the MIT license. See the [LICENSE](https://your-license-link) file for details.
@@ -0,0 +1,37 @@
1
+ # TISControlProtocol
2
+
3
+ ![Build Status](https://img.shields.io/badge/build-passing-brightgreen)
4
+ ![Version 0.1.0](https://img.shields.io/badge/version-3.0.0-blue)
5
+ ![License MIT](https://img.shields.io/badge/license-MIT-green)
6
+
7
+ TISControlProtocol is a powerful Python package for controlling TIS devices. It provides a simple and intuitive API for interacting with TIS devices, making it easy to integrate TIS devices into your Python applications.
8
+
9
+ ## Features
10
+
11
+ - ✅ Fully Supports Asynchronous Operations
12
+ - ✅ Flawless feedback mechanism to prevent data loss
13
+ - ✅ Debounce mechanism to prevent multiple commands from being sent for protection
14
+ - ✅ Easy to use API for controlling TIS devices
15
+ - ✅ Clean and simple codebase
16
+ - ✅ Ready to integrate with Home Assistant
17
+
18
+ ## Installation
19
+
20
+ You can install TISControlProtocol by adding it to your Manifest file or by using pip. Here's how you can install it using pip:
21
+
22
+ ```bash
23
+ pip install TISControlProtocol
24
+ ```
25
+
26
+ ## Building
27
+
28
+ To build the package, you can use the following commands:
29
+
30
+ ```bash
31
+ python -m build
32
+ twine upload dist/*
33
+ ```
34
+
35
+ ## License
36
+
37
+ TISControlProtocol is licensed under the MIT license. See the [LICENSE](https://your-license-link) file for details.
@@ -0,0 +1,53 @@
1
+ import toml
2
+ import sys
3
+
4
+
5
+ def bump_version(version, part):
6
+ major, minor, patch = map(int, version.split("."))
7
+ if part == "major":
8
+ major += 1
9
+ minor = 0
10
+ patch = 0
11
+ elif part == "minor":
12
+ minor += 1
13
+ patch = 0
14
+ elif part == "patch":
15
+ patch += 1
16
+ else:
17
+ raise ValueError("Part must be 'major', 'minor', or 'patch'")
18
+ return f"{major}.{minor}.{patch}"
19
+
20
+
21
+ def update_version_file(file_path, part):
22
+ with open(file_path, "r") as f:
23
+ data = toml.load(f)
24
+
25
+ current_version = data["project"]["version"]
26
+ new_version = bump_version(current_version, part)
27
+ data["project"]["version"] = new_version
28
+
29
+ with open(file_path, "w") as f:
30
+ toml.dump(data, f)
31
+
32
+ print(f"Version updated from {current_version} to {new_version}")
33
+
34
+
35
+ if __name__ == "__main__":
36
+ if len(sys.argv) != 2:
37
+ print("Usage: python update_version_interactive.py <path_to_pyproject.toml>")
38
+ sys.exit(1)
39
+
40
+ file_path = sys.argv[1]
41
+ print("Select the part to bump:")
42
+ print("1. Major")
43
+ print("2. Minor")
44
+ print("3. Patch")
45
+ choice = input("Enter the number (1/2/3): ").strip()
46
+
47
+ part_map = {"1": "major", "2": "minor", "3": "patch"}
48
+ part = part_map.get(choice)
49
+ if not part:
50
+ print("Invalid choice. Must be 1, 2, or 3.")
51
+ sys.exit(1)
52
+
53
+ update_version_file(file_path, part)
@@ -0,0 +1,25 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "TISControlProtocol"
7
+ version = "1.0.36"
8
+ description = "A library for TIS Control Protocol"
9
+ readme = "README.md"
10
+ requires-python = ">=3.11"
11
+ classifiers = [
12
+ "Programming Language :: Python :: 3",
13
+ "License :: OSI Approved :: MIT License",
14
+ "Operating System :: POSIX :: Linux",
15
+ ]
16
+ [[project.authors]]
17
+ name = "Ibrahim Mohamed"
18
+ email = "ibrali2001.ia@gmail.com"
19
+
20
+ [project.urls]
21
+ Homepage = "https://github.com/TISControlHass"
22
+ Issues = "https://github.com/TISControlHass/issues"
23
+
24
+ [tool.hatch.build.targets.wheel]
25
+ packages = ["src/TISControlProtocol"]
@@ -0,0 +1,65 @@
1
+ import binascii
2
+ from TISControlProtocol.crc import checkCRC, packCRC
3
+
4
+
5
+ def bytes2hex(data, rtype=[]):
6
+ """A helper function to parse bytes to hex
7
+
8
+ :param data: the raw bytes array
9
+ :type data: bytes array
10
+ :param rtype: determine return type whether list of ints or single hex str, defaults to []
11
+ :type rtype: list, optional
12
+ :return: list of ints or hex string
13
+ :rtype: list | str
14
+ """
15
+ hex_string = binascii.hexlify(data).decode()
16
+ hex_list = [int(hex_string[i : i + 2], 16) for i in range(0, len(hex_string), 2)]
17
+ if isinstance(rtype, list):
18
+ return hex_list
19
+ else:
20
+ return hex_string
21
+
22
+
23
+ def build_packet(
24
+ operation_code: list,
25
+ ip_address: str,
26
+ destination_mac: str = "AA:AA:AA:AA:AA:AA:AA:AA",
27
+ source_mac: str = "CB:CB:CB:CB:CB:CB:CB:CB",
28
+ device_id: list = [],
29
+ source_device_id: list = [0x01, 0xFE],
30
+ additional_packets: list = [],
31
+ header="SMARTCLOUD",
32
+ ):
33
+
34
+ # test if all params are loaded
35
+ ip_bytes = [int(part) for part in ip_address.split(".")]
36
+ header_bytes = [ord(char) for char in header]
37
+ source_mac = [int(part, 16) for part in source_mac.split(":")]
38
+ destination_mac = [int(part, 16) for part in destination_mac.split(":")]
39
+ # TODO: modify length
40
+ # length = 21 + len(additional_packets)
41
+ length = 11 + len(additional_packets)
42
+ packet = (
43
+ ip_bytes
44
+ + header_bytes
45
+ + [0xAA, 0xAA]
46
+ + [length]
47
+ # + source_mac
48
+ + source_device_id
49
+ + [0xFF, 0xFE]
50
+ + operation_code
51
+ # + destination_mac
52
+ + device_id
53
+ + additional_packets
54
+ )
55
+ packet = packCRC(packet)
56
+ return packet
57
+
58
+
59
+ def decode_mac(mac: list):
60
+ return ":".join([f"{byte:02X}" for byte in mac])
61
+
62
+
63
+ def int_to_8_bit_binary(number):
64
+ binary_string = bin(number)[2:]
65
+ return binary_string.zfill(8)[::-1]
@@ -0,0 +1,18 @@
1
+ from asyncio import get_event_loop, AbstractEventLoop
2
+ import socket
3
+ from TISControlProtocol.Protocols.udp.PacketProtocol import PacketProtocol
4
+
5
+ loop = get_event_loop()
6
+
7
+
8
+ async def setup_udp_protocol(
9
+ sock: socket, loop: AbstractEventLoop, udp_ip, udp_port, hass
10
+ ) -> tuple[socket.socket, PacketProtocol]:
11
+ transport, protocol = await loop.create_datagram_endpoint(
12
+ lambda: PacketProtocol(sock, udp_ip, udp_port, hass),
13
+ remote_addr=(udp_ip, udp_port),
14
+ local_addr=("0.0.0.0", udp_port),
15
+ allow_broadcast=True,
16
+ reuse_port=True,
17
+ )
18
+ return transport, protocol
@@ -0,0 +1,50 @@
1
+ import asyncio
2
+ from TISControlProtocol.shared import ack_events
3
+ from typing import Union
4
+ import logging
5
+
6
+ class AckCoordinator:
7
+ def __init__(self):
8
+ self.ack_events = ack_events
9
+
10
+ def create_ack_event(self, unique_id: Union[str, tuple]) -> asyncio.Event:
11
+ logging.info(f"creating ack event for {unique_id}")
12
+ event = asyncio.Event()
13
+ self.ack_events[unique_id] = event
14
+ return event
15
+
16
+ def get_ack_event(self, unique_id: Union[str, tuple]) -> Union[asyncio.Event, None]:
17
+ return self.ack_events.get(unique_id)
18
+
19
+ def remove_ack_event(self, unique_id: Union[str, tuple]) -> None:
20
+ if unique_id in self.ack_events:
21
+ del self.ack_events[unique_id]
22
+
23
+ # async def create_ack_task(
24
+ # self,
25
+ # sender,
26
+ # packet,
27
+ # packet_dict=None,
28
+ # channel_number=None,
29
+ # attempts=3,
30
+ # timeout=5.0,
31
+ # ) -> bool:
32
+ # unique_id = (
33
+ # (tuple(packet_dict["device_id"])),
34
+ # packet_dict["operation_code"],
35
+ # channel_number,
36
+ # )
37
+ # event = self.create_ack_event(unique_id)
38
+
39
+ # for attempt in range(attempts):
40
+ # sender.send_packet(packet)
41
+ # try:
42
+ # await asyncio.wait_for(event.wait(), timeout)
43
+ # self.remove_ack_event(unique_id)
44
+ # return True
45
+ # except asyncio.TimeoutError:
46
+ # print(
47
+ # f"ack not received within {timeout} seconds, attempt {attempt + 1}"
48
+ # )
49
+
50
+ # return False
@@ -0,0 +1,20 @@
1
+ from homeassistant.core import HomeAssistant # type: ignore
2
+ import logging
3
+
4
+
5
+ class PacketDispatcher:
6
+ def __init__(self, hass: HomeAssistant, OPERATIONS_DICT: dict):
7
+ self.hass = hass
8
+ self.operations_dict = OPERATIONS_DICT
9
+
10
+ async def dispatch_packet(self, info):
11
+ try:
12
+ packet_handler = self.operations_dict.get(
13
+ tuple(info["operation_code"]), "unknown operation"
14
+ )
15
+ if packet_handler != "unknown operation":
16
+ await packet_handler(self.hass, info)
17
+ else:
18
+ logging.info(f"unknown operation code: {info['operation_code']}")
19
+ except Exception as e:
20
+ logging.info(f"error in dispatching packet: {e} , {info}")
@@ -0,0 +1,22 @@
1
+ from TISControlProtocol.BytesHelper import checkCRC
2
+ import logging
3
+
4
+
5
+ # PacketExtractor.py
6
+ class PacketExtractor:
7
+ @staticmethod
8
+ def extract_info(packet: list):
9
+ packet_check = checkCRC(packet)
10
+ info = {}
11
+ if packet_check:
12
+ logging.info("correct packet")
13
+ info["source_ip"] = packet[0:4]
14
+ info["device_id"] = packet[17:19]
15
+ info["device_type"] = packet[19:21]
16
+ info["operation_code"] = packet[21:23]
17
+ info["source_device_id"] = packet[23:25]
18
+ info["additional_bytes"] = packet[25:-2]
19
+
20
+ else:
21
+ logging.info("wrong packet")
22
+ return info
@@ -0,0 +1,23 @@
1
+ from homeassistant.core import HomeAssistant
2
+ import logging
3
+
4
+ #TODO get a way to set 4 sensors together
5
+ async def handle_analog_feedback(hass: HomeAssistant, info: dict):
6
+ """
7
+ Handle the feedback from an analog sensor.
8
+ """
9
+ device_id = info["device_id"]
10
+ channels_num = int(info["additional_bytes"][0])
11
+ analog = info["additional_bytes"][1:channels_num + 1]
12
+
13
+ event_data = {
14
+ "device_id": device_id,
15
+ "feedback_type": "analog_feedback",
16
+ "analog": analog,
17
+ "additional_bytes": info["additional_bytes"],
18
+ }
19
+
20
+ try:
21
+ hass.bus.async_fire(str(info["device_id"]), event_data)
22
+ except Exception as e:
23
+ logging.error(f"error in firing event for feedback: {e}")
@@ -0,0 +1,18 @@
1
+ from homeassistant.core import HomeAssistant # type: ignore
2
+ import logging
3
+
4
+
5
+ async def handle_auto_binary_feedback(hass: HomeAssistant, info: dict):
6
+ logging.info(f"Auto Binary Feedback: {info}")
7
+ channels_number: int = info["additional_bytes"][0]
8
+ channels_values: list = info["additional_bytes"][channels_number :]
9
+
10
+ event_data = {
11
+ "device_id": info["device_id"],
12
+ "feedback_type": "auto_binary_feedback",
13
+ "channels_values": channels_values,
14
+ }
15
+ # try:
16
+ # hass.bus.async_fire(str(info["device_id"]), event_data)
17
+ # except Exception as e:
18
+ # logging.error(f"error in firing event: {e}")
@@ -0,0 +1,17 @@
1
+ from homeassistant.core import HomeAssistant # type: ignore
2
+ import logging
3
+
4
+
5
+ async def handle_binary_feedback(hass: HomeAssistant, info: dict):
6
+ # remove auxilary bytes which represents number of scenarios
7
+ len_aux = info["additional_bytes"][0]
8
+ info["additional_bytes"] = info["additional_bytes"][len_aux + 1 :]
9
+ event_data = {
10
+ "device_id": info["device_id"],
11
+ "feedback_type": "binary_feedback",
12
+ "additional_bytes": info["additional_bytes"],
13
+ }
14
+ try:
15
+ hass.bus.async_fire(str(info["device_id"]), event_data)
16
+ except Exception as e:
17
+ logging.error(f"error in firing event: {e}")
@@ -0,0 +1,62 @@
1
+ from homeassistant.core import HomeAssistant
2
+ import logging
3
+
4
+ AC_NUMBER_MAP = {0x19: 0, 0x1A: 1, 0x1B: 2, 0x1C: 3, 0x1D: 4, 0x1E: 5, 0x1F: 6, 0x20: 7}
5
+ FLOOR_NUMBER_MAP = {0x22: 0, 0x23: 1, 0x24: 2, 0x25: 3}
6
+
7
+
8
+ async def handle_climate_binary_feedback(hass: HomeAssistant, info: dict):
9
+ # NOTE: Sometimes the packet contains number of floor heater and sometimes no floor heater num is given
10
+ # check sub_operation or number
11
+ if info["additional_bytes"][0] <= 0x18:
12
+ sub_operation = info["additional_bytes"][0]
13
+ operation_value = info["additional_bytes"][1]
14
+
15
+ if info["additional_bytes"][0] < 0x14:
16
+ feedback_type = "ac_feedback"
17
+ number = 0
18
+
19
+ else:
20
+ feedback_type = "floor_feedback"
21
+ number = 0
22
+
23
+ elif info["additional_bytes"][0] == 0x2E:
24
+ number = (info["additional_bytes"][1]) - 1
25
+ new_sub_operation = info["additional_bytes"][2]
26
+ if new_sub_operation == 0x03:
27
+ sub_operation = 0x14
28
+
29
+ elif new_sub_operation == 0x04:
30
+ sub_operation = 0x18
31
+
32
+ operation_value = info["additional_bytes"][3]
33
+
34
+
35
+
36
+ else:
37
+ ac_number = AC_NUMBER_MAP.get(info["additional_bytes"][0], None)
38
+ floor_number = FLOOR_NUMBER_MAP.get(info["additional_bytes"][0], None)
39
+ sub_operation = info["additional_bytes"][1]
40
+ operation_value = info["additional_bytes"][2]
41
+
42
+ if ac_number is not None:
43
+ feedback_type = "ac_feedback"
44
+ number = ac_number
45
+
46
+ else:
47
+ feedback_type = "floor_feedback"
48
+ number = floor_number
49
+
50
+ event_data = {
51
+ "device_id": info["device_id"],
52
+ "feedback_type": feedback_type,
53
+ "number": number,
54
+ "sub_operation": sub_operation,
55
+ "operation_value": operation_value,
56
+ }
57
+
58
+ try:
59
+ hass.bus.async_fire(str(info["device_id"]), event_data)
60
+
61
+ except Exception as e:
62
+ logging.error(f"error in firing event: {e}")