htd-client-ha 0.1.2__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.
- htd_client_ha-0.1.2/LICENSE +21 -0
- htd_client_ha-0.1.2/PKG-INFO +74 -0
- htd_client_ha-0.1.2/README.md +55 -0
- htd_client_ha-0.1.2/htd_client/__init__.py +107 -0
- htd_client_ha-0.1.2/htd_client/base_client.py +654 -0
- htd_client_ha-0.1.2/htd_client/constants.py +258 -0
- htd_client_ha-0.1.2/htd_client/lync_client.py +490 -0
- htd_client_ha-0.1.2/htd_client/mca_client.py +694 -0
- htd_client_ha-0.1.2/htd_client/models.py +37 -0
- htd_client_ha-0.1.2/htd_client/utils.py +202 -0
- htd_client_ha-0.1.2/pyproject.toml +41 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024
|
|
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,74 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: htd-client-ha
|
|
3
|
+
Version: 0.1.2
|
|
4
|
+
Summary: A client supporting Home Theater Direct's gateway device.
|
|
5
|
+
License: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Author: Adam Kirschner
|
|
8
|
+
Author-email: accounts@adamskirschner.com
|
|
9
|
+
Requires-Python: >=3.13,<4.0
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
14
|
+
Requires-Dist: pyserial-asyncio (>=0.6,<0.7)
|
|
15
|
+
Project-URL: Issues, https://github.com/theharshl/python-htd/issues
|
|
16
|
+
Project-URL: Repository, https://github.com/theharshl/python-htd
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
# htd_client
|
|
20
|
+
|
|
21
|
+
This library contains a client to communicate with the HTD MC/MCA66 gateway. Future support
|
|
22
|
+
for the Lync system is planned.
|
|
23
|
+
|
|
24
|
+
## Table of Contents
|
|
25
|
+
|
|
26
|
+
- [Installation](#installation)
|
|
27
|
+
- [Usage](#usage)
|
|
28
|
+
- [Contributing](#contributing)
|
|
29
|
+
- [License](#license)
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
|
|
33
|
+
Use pip to install this package
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pip install htd_client
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Usage
|
|
40
|
+
|
|
41
|
+
Here's a basic example.
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
|
|
45
|
+
import HtdClient
|
|
46
|
+
from base_client
|
|
47
|
+
|
|
48
|
+
client = HtdClient("192.168.1.2")
|
|
49
|
+
model_info = client.get_model_info()
|
|
50
|
+
client.async_volume_up()
|
|
51
|
+
client.async_volume_down()
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Contributing
|
|
56
|
+
|
|
57
|
+
[Poetry](https://python-poetry.org/docs/#installation) is used to manage dependencies, run tests, and publish.
|
|
58
|
+
|
|
59
|
+
Run unit tests
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
$ poetry run pytest
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Generate documentation
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
$ poetry run sphinx-build -b html docs docs/_build
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## License
|
|
72
|
+
|
|
73
|
+
This project is licensed under the MIT License - see the LICENSE file for details.
|
|
74
|
+
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# htd_client
|
|
2
|
+
|
|
3
|
+
This library contains a client to communicate with the HTD MC/MCA66 gateway. Future support
|
|
4
|
+
for the Lync system is planned.
|
|
5
|
+
|
|
6
|
+
## Table of Contents
|
|
7
|
+
|
|
8
|
+
- [Installation](#installation)
|
|
9
|
+
- [Usage](#usage)
|
|
10
|
+
- [Contributing](#contributing)
|
|
11
|
+
- [License](#license)
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
Use pip to install this package
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pip install htd_client
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
Here's a basic example.
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
|
|
27
|
+
import HtdClient
|
|
28
|
+
from base_client
|
|
29
|
+
|
|
30
|
+
client = HtdClient("192.168.1.2")
|
|
31
|
+
model_info = client.get_model_info()
|
|
32
|
+
client.async_volume_up()
|
|
33
|
+
client.async_volume_down()
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Contributing
|
|
38
|
+
|
|
39
|
+
[Poetry](https://python-poetry.org/docs/#installation) is used to manage dependencies, run tests, and publish.
|
|
40
|
+
|
|
41
|
+
Run unit tests
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
$ poetry run pytest
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Generate documentation
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
$ poetry run sphinx-build -b html docs docs/_build
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## License
|
|
54
|
+
|
|
55
|
+
This project is licensed under the MIT License - see the LICENSE file for details.
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. code-block:: python
|
|
3
|
+
|
|
4
|
+
# import the client
|
|
5
|
+
from htd_client import HtdClient
|
|
6
|
+
|
|
7
|
+
# Call its only function
|
|
8
|
+
client = HtdClient("192.168.1.2")
|
|
9
|
+
|
|
10
|
+
model_info = client.get_model_info()
|
|
11
|
+
zone_info = client.query_zone(1)
|
|
12
|
+
updated_zone_info = client.volume_up(1)
|
|
13
|
+
"""
|
|
14
|
+
import asyncio
|
|
15
|
+
import logging
|
|
16
|
+
from typing import Tuple
|
|
17
|
+
|
|
18
|
+
import htd_client.utils
|
|
19
|
+
from .base_client import BaseClient
|
|
20
|
+
from .constants import HtdCommonCommands, HtdModelInfo, HtdDeviceKind, HtdConstants
|
|
21
|
+
from .lync_client import HtdLyncClient
|
|
22
|
+
from .mca_client import HtdMcaClient
|
|
23
|
+
|
|
24
|
+
_LOGGER = logging.getLogger(__name__)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
async def async_get_client(
|
|
28
|
+
serial_address: str = None,
|
|
29
|
+
network_address: Tuple[str, int] = None,
|
|
30
|
+
loop: asyncio.AbstractEventLoop = None,
|
|
31
|
+
retry_attempts: int = HtdConstants.DEFAULT_RETRY_ATTEMPTS,
|
|
32
|
+
) -> BaseClient:
|
|
33
|
+
"""
|
|
34
|
+
Create a new client object.
|
|
35
|
+
|
|
36
|
+
Args:
|
|
37
|
+
network_address (str): The address to communicate with over TCP.
|
|
38
|
+
serial_address (str): The location of the serial port.
|
|
39
|
+
loop (asyncio.AbstractEventLoop): The event loop to use.
|
|
40
|
+
retry_attempts (int): Number of times to retry a command before failing.
|
|
41
|
+
|
|
42
|
+
Returns:
|
|
43
|
+
HtdClient: The new client object.
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
model_info = await async_get_model_info(
|
|
47
|
+
loop if loop is not None else asyncio.get_running_loop(),
|
|
48
|
+
network_address=network_address,
|
|
49
|
+
serial_address=serial_address
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
if model_info["kind"] == HtdDeviceKind.mca:
|
|
53
|
+
client = HtdMcaClient(
|
|
54
|
+
loop if loop is not None else asyncio.get_running_loop(),
|
|
55
|
+
model_info,
|
|
56
|
+
network_address=network_address,
|
|
57
|
+
serial_address=serial_address,
|
|
58
|
+
retry_attempts=retry_attempts,
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
elif model_info["kind"] == HtdDeviceKind.lync:
|
|
62
|
+
client = HtdLyncClient(
|
|
63
|
+
loop if loop is not None else asyncio.get_running_loop(),
|
|
64
|
+
model_info,
|
|
65
|
+
network_address=network_address,
|
|
66
|
+
serial_address=serial_address,
|
|
67
|
+
retry_attempts=retry_attempts,
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
else:
|
|
71
|
+
raise ValueError(f"Unknown Device Kind: {model_info['kind']}")
|
|
72
|
+
|
|
73
|
+
await client.async_connect()
|
|
74
|
+
|
|
75
|
+
return client
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
async def async_get_model_info(
|
|
79
|
+
loop: asyncio.AbstractEventLoop = None,
|
|
80
|
+
network_address: Tuple[str, int] = None,
|
|
81
|
+
serial_address:str=None,
|
|
82
|
+
) -> HtdModelInfo | None:
|
|
83
|
+
"""
|
|
84
|
+
Get the model information from the gateway.
|
|
85
|
+
|
|
86
|
+
Returns:
|
|
87
|
+
(str, str): the raw model name from the gateway and the friendly
|
|
88
|
+
name, in a Tuple.
|
|
89
|
+
"""
|
|
90
|
+
|
|
91
|
+
cmd = htd_client.utils.build_command(
|
|
92
|
+
1, HtdCommonCommands.MODEL_QUERY_COMMAND_CODE, 0
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
model_id = await htd_client.utils.async_send_command(
|
|
96
|
+
loop if loop is not None else asyncio.get_running_loop(),
|
|
97
|
+
cmd,
|
|
98
|
+
network_address=network_address,
|
|
99
|
+
serial_address=serial_address
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
for model_name in HtdConstants.SUPPORTED_MODELS:
|
|
103
|
+
model = HtdConstants.SUPPORTED_MODELS[model_name]
|
|
104
|
+
if model["identifier"] in model_id:
|
|
105
|
+
return model
|
|
106
|
+
|
|
107
|
+
return None
|