lghorizon 0.9.0__py3-none-any.whl → 0.9.0b0__py3-none-any.whl

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.
@@ -1,191 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: lghorizon
3
- Version: 0.9.0
4
- Summary: Python client for Liberty Global Horizon settop boxes
5
- Home-page: https://github.com/sholofly/LGHorizon-python
6
- Author: Rudolf Offereins
7
- Author-email: r.offereins@gmail.com
8
- License: MIT license
9
- Keywords: LG,Horizon,API,Settop box
10
- Classifier: Development Status :: 3 - Alpha
11
- Classifier: Programming Language :: Python :: 3
12
- Classifier: License :: OSI Approved :: MIT License
13
- Classifier: Operating System :: OS Independent
14
- Classifier: Natural Language :: English
15
- Classifier: Intended Audience :: Developers
16
- Classifier: Programming Language :: Python :: 3.6
17
- Classifier: Programming Language :: Python :: 3.7
18
- Classifier: Programming Language :: Python :: 3
19
- Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
- Requires-Python: >=3.9
21
- Description-Content-Type: text/markdown
22
- License-File: LICENSE
23
- Requires-Dist: paho-mqtt
24
- Requires-Dist: requests>=2.22.0
25
- Requires-Dist: backoff>=1.9.0
26
- Dynamic: author
27
- Dynamic: author-email
28
- Dynamic: classifier
29
- Dynamic: description
30
- Dynamic: description-content-type
31
- Dynamic: home-page
32
- Dynamic: keywords
33
- Dynamic: license
34
- Dynamic: license-file
35
- Dynamic: requires-dist
36
- Dynamic: requires-python
37
- Dynamic: summary
38
-
39
- # LG Horizon Api
40
-
41
- # LG Horizon API Python Library
42
-
43
- A Python library to interact with and control LG Horizon set-top boxes. This library provides functionalities for authentication, real-time device status monitoring via MQTT, and various control commands for your Horizon devices.
44
-
45
- ## Features
46
-
47
- - **Authentication**: Supports authentication using username/password or a refresh token. The library automatically handles access token refreshing.
48
- - **Device Management**: Discover and manage multiple LG Horizon set-top boxes associated with your account.
49
- - **Real-time Status**: Monitor device status (online/running/standby) and current playback information (channel, show, VOD, recording, app) through MQTT.
50
- - **Channel Information**: Retrieve a list of available channels and profile-specific favorite channels.
51
- - **Recording Management**:
52
- - Get a list of all recordings.
53
- - Retrieve recordings for specific shows.
54
- - Check recording quota and usage.
55
- - **Device Control**: Send various commands to your set-top box:
56
- - Power on/off.
57
- - Play, pause, stop, rewind, fast forward.
58
- - Change channels (up/down, direct channel selection).
59
- - Record current program.
60
- - Set player position for VOD/recordings.
61
- - Display custom messages on the TV screen.
62
- - Send emulated remote control key presses.
63
- - **Robustness**: Includes automatic MQTT reconnection with exponential backoff and token refresh logic to maintain a stable connection.
64
-
65
- ## Installation
66
-
67
- ```bash
68
- pip install lghorizon-python # (Replace with actual package name if different)
69
- ```
70
-
71
- ## Usage
72
-
73
- Here's a basic example of how to use the library to connect to your LG Horizon devices and monitor their state:
74
-
75
- First, create a `secrets.json` file in the root of your project with your LG Horizon credentials:
76
-
77
- ```json
78
- {
79
- "username": "your_username",
80
- "password": "your_password",
81
- "country": "nl" // e.g., "nl" for Netherlands, "be" for Belgium
82
- }
83
- ```
84
-
85
- Then, you can use the library as follows:
86
-
87
- ```python
88
- import asyncio
89
- import json
90
- import logging
91
- import aiohttp
92
-
93
- from lghorizon.lghorizon_api import LGHorizonApi
94
- from lghorizon.lghorizon_models import LGHorizonAuth
95
-
96
- _LOGGER = logging.getLogger(__name__)
97
-
98
- async def main():
99
- logging.basicConfig(level=logging.INFO) # Set to DEBUG for more verbose output
100
-
101
- with open("secrets.json", encoding="utf-8") as f:
102
- secrets = json.load(f)
103
- username = secrets.get("username")
104
- password = secrets.get("password")
105
- country = secrets.get("country", "nl")
106
-
107
- async with aiohttp.ClientSession() as session:
108
- auth = LGHorizonAuth(session, country, username=username, password=password)
109
- api = LGHorizonApi(auth)
110
-
111
- async def device_state_changed_callback(device_id: str):
112
- device = devices[device_id]
113
- _LOGGER.info(
114
- f"Device {device.device_friendly_name} ({device.device_id}) state changed:\n"
115
- f" State: {device.device_state.state.value}\n"
116
- f" UI State: {device.device_state.ui_state_type.value}\n"
117
- f" Source Type: {device.device_state.source_type.value}\n"
118
- f" Channel: {device.device_state.channel_name or 'N/A'} ({device.device_state.channel_id or 'N/A'})\n"
119
- f" Show: {device.device_state.show_title or 'N/A'}\n"
120
- f" Episode: {device.device_state.episode_title or 'N/A'}\n"
121
- f" Position: {device.device_state.position or 'N/A'} / {device.device_state.duration or 'N/A'}\n"
122
- )
123
-
124
- try:
125
- _LOGGER.info("Initializing LG Horizon API...")
126
- await api.initialize()
127
- devices = await api.get_devices()
128
-
129
- for device in devices.values():
130
- _LOGGER.info(f"Registering callback for device: {device.device_friendly_name}")
131
- await device.set_callback(device_state_changed_callback)
132
-
133
- _LOGGER.info("API initialized. Monitoring device states. Press Ctrl+C to exit.")
134
- # Keep the script running to receive MQTT updates
135
- while True:
136
- await asyncio.sleep(3600) # Sleep for a long time, MQTT callbacks will still fire
137
-
138
- except Exception as e:
139
- _LOGGER.error(f"An error occurred: {e}", exc_info=True)
140
- finally:
141
- _LOGGER.info("Disconnecting from LG Horizon API.")
142
- await api.disconnect()
143
- _LOGGER.info("Disconnected.")
144
-
145
- if __name__ == "__main__":
146
- asyncio.run(main())
147
- ```
148
-
149
- ## Authentication
150
-
151
- The `LGHorizonAuth` class handles authentication. You can initialize it with a username and password, or directly with a refresh token if you have one. The library automatically refreshes access tokens as needed.
152
-
153
- ```python
154
- # Using username and password
155
- auth = LGHorizonAuth(session, "nl", username="your_username", password="your_password")
156
-
157
- # Using a refresh token (e.g., if you've saved it from a previous session)
158
- # auth = LGHorizonAuth(session, "nl", refresh_token="your_refresh_token")
159
- ```
160
-
161
- You can also set a callback to receive the updated refresh token when it's refreshed, allowing you to persist it for future sessions:
162
-
163
- ```python
164
- def token_updated_callback(new_refresh_token: str):
165
- print(f"New refresh token received: {new_refresh_token}")
166
- # Here you would typically save this new_refresh_token
167
- # to your secrets.json or other persistent storage.
168
-
169
- # After initializing LGHorizonApi:
170
- # api.set_token_refresh_callback(token_updated_callback)
171
- ```
172
-
173
- ## Error Handling
174
-
175
- The library defines custom exceptions for common error scenarios:
176
-
177
- - `LGHorizonApiError`: Base exception for all API-related errors.
178
- - `LGHorizonApiConnectionError`: Raised for network or connection issues.
179
- - `LGHorizonApiUnauthorizedError`: Raised when authentication fails (e.g., invalid credentials).
180
- - `LGHorizonApiLockedError`: A specific type of `LGHorizonApiUnauthorizedError` indicating a locked account.
181
-
182
- These exceptions allow for more granular error handling in your application.
183
-
184
- ## Development
185
-
186
- To run the example script (`main.py`) from the repository:
187
-
188
- 1. Clone this repository.
189
- 2. Install dependencies: `pip install -r requirements.txt` (ensure `requirements.txt` is up-to-date).
190
- 3. Create a `secrets.json` file as described in the Usage section.
191
- 4. Run `python main.py`.
@@ -1,17 +0,0 @@
1
- lghorizon/__init__.py,sha256=y44i_P6jsl3VV0R4UYIymXpRXIJVYPwb97uQK9pEfYA,1852
2
- lghorizon/const.py,sha256=HINlbyevEN9ZRnfIBbSGNc6i9J8WkIgpqkLZrwyqpGQ,5307
3
- lghorizon/exceptions.py,sha256=4cnnPRuKBtqXiTlOZK4xmP1WADikk5NvCsy293mijT8,500
4
- lghorizon/helpers.py,sha256=SGlEN6V0kh2vqw1qCKmM1KhfeO-UvPyyQmnThgFLFhs,272
5
- lghorizon/lghorizon_api.py,sha256=_yP7X3LIei3OPc_byPPZg22QrPkDQdRyMoR6GLg3c3M,12881
6
- lghorizon/lghorizon_device.py,sha256=HfpbOnmiN44Y0ObSj-lCP8vYQ85WBYU8rbBaqvDzri8,14767
7
- lghorizon/lghorizon_device_state_processor.py,sha256=LW_Gavhg7bSSeZJiprAi1YJqOcUhZcB-2GdHn9hMj-o,15380
8
- lghorizon/lghorizon_message_factory.py,sha256=BkJrVgcTsidcugrM9Pt5brvdw5_WI4PRAHvWQyHurz8,1435
9
- lghorizon/lghorizon_models.py,sha256=-xhTIz1UC5efR5HJtXf2a59EspDbZKGp967flYvhryM,46435
10
- lghorizon/lghorizon_mqtt_client.py,sha256=6BsZkRo3PBf62F2530_FdQ4OMr9w1jiewcv19Y8MWWo,12764
11
- lghorizon/lghorizon_recording_factory.py,sha256=JaFjmXWChp1jdFzkioe9K-MqzVU0AsOgdKGjm2Seyq0,2318
12
- lghorizon/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
- lghorizon-0.9.0.dist-info/licenses/LICENSE,sha256=6Dh2tur1gMX3r3rITjVwUONBEJxyyPZDY8p6DZXtimE,1059
14
- lghorizon-0.9.0.dist-info/METADATA,sha256=HJvdaN47p25UvHdotYhrI5BIPUeTmqJbFqfad7rJRwY,7471
15
- lghorizon-0.9.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
16
- lghorizon-0.9.0.dist-info/top_level.txt,sha256=usii76_AxGfPI6gjrrh-NyZxcQQuF1B8_Q9kd7sID8Q,10
17
- lghorizon-0.9.0.dist-info/RECORD,,