hue-entertainment-pykit


Namehue-entertainment-pykit JSON
Version 0.9.0 PyPI version JSON
download
home_page
SummaryA comprehensive Python toolkit for Philips Hue Entertainment API
upload_time2024-01-26 12:25:34
maintainer
docs_urlNone
authorDominik Hrdas
requires_python<=3.12.1,>=3.10
licenseMIT License Copyright (c) 2024 Dominik Hrdas Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords philips hue lights entertainment api
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Hue Entertainment PyKit
![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/hrdasdominik/hue-entertainment-pykit/python-app.yml?branch=main&label=main)
![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/hrdasdominik/hue-entertainment-pykit/python-app.yml?branch=dev&label=dev)
![GitHub Tag](https://img.shields.io/github/v/tag/hrdasdominik/hue-entertainment-pykit?include_prereleases)
![Python Version from PEP 621 TOML](https://img.shields.io/python/required-version-toml?tomlFilePath=https%3A%2F%2Fraw.githubusercontent.com%2Fhrdasdominik%2Fhue-entertainment-pykit%2Fmain%2Fpyproject.toml)
![PyPI - Version](https://img.shields.io/pypi/v/hue-entertainment-pykit?link=https%3A%2F%2Fpypi.org%2Fproject%2Fhue-entertainment-pykit%2F)
![PyPI - License](https://img.shields.io/pypi/l/hue-entertainment-pykit?link=https%3A%2F%2Fpypi.org%2Fproject%2Fhue-entertainment-pykit%2F)



<img align="right" alt="HEPK logo" src="docs/logo/horizontal.png" width="400">

## Introduction

Unlock the full spectrum of Philips Hue lighting with the Hue Entertainment PyKit. This Python library simplifies connecting to the Hue Bridge and controlling lights with minimal latency, empowering developers to create dynamic and responsive lighting environments.

## Motivation

Confronted with the complexity of the official Hue EDK and challenges in DTLS handshake implementation which many in the community had, Hue Entertainment PyKit was crafted to provide a straightforward, Python-centric approach to light control using the Philips Hue Entertainment API.

## Quick Start

### Installing

To install Hue Entertainment PyKit, ensure you have Python installed on your system, and then run the following command:
```sh
pip install hue-entertainment-pykit
```

## Usage

To interact with your Philips Hue lights you can do:

### Logging Configuration (Optional)

For an enhanced development experience when utilizing this library, logging capabilities have been integrated:

```python
import logging
from hue_entertainment_pykit import setup_logs

# Initialize default logging
setup_logs()

# Or customize the logging level (e.g., exclude DEBUG messages)
setup_logs(level=logging.INFO)

# You can also further customize logging by specifying the maximum log file size and the number of backup files
setup_logs(level=logging.INFO, max_file_size=1024 * 1024, backup_count=1)

# Each parameter is optional and comes with predefined default values
```

### Discovery (Optional)

Use only on your Local Area Network (LAN) to discover and fetch all Bridges that can be used then for streaming

```python
from hue_entertainment_pykit import Discovery

discovery = Discovery()

# returns dict[str, Bridge] where the key is name of the bridge and value is the Bridge model with all important info for connecting to Entertainment API
bridges = discovery.discover_bridges()  
```
### Streaming

The Streaming service in Hue Entertainment PyKit provides thread-safe communication with Hue lights, ensuring smooth and uninterrupted interactions. To prevent connection timeouts, the service implements a keep-alive feature: if no command is sent for 9.5 seconds, the last message is automatically resent to maintain the connection.

Below is a streamlined example to set up and manage your streaming session:

```python
import time
from hue_entertainment_pykit import create_bridge, Entertainment, Streaming

# Set up the Bridge instance with the all needed configuration
bridge = create_bridge(
    identification="4abb74df-5b6b-410e-819b-bf4448355dff",
    rid="d476df48-83ad-4430-a104-53c30b46b4d0",
    ip_address="192.168.1.100",
    swversion=1962097030,
    username="8nuTIcK2nOf5oi88-5zPvV1YCt0wTHZIGG8MwXpu",
    hue_app_id="94530efc-933a-4f7c-97e5-ccf1a9fc79af",
    client_key="B42753E1E1605A1AB90E1B6A0ECF9C51",
    name="1st Bridge"
)

# Set up the Entertainment API service
entertainment_service = Entertainment(bridge)

# Fetch all Entertainment Configurations on the Hue bridge
entertainment_configs = entertainment_service.get_entertainment_configs()

# Add some Entertainment Area selection logic
# For the purposes of example I'm going to do manual selection
entertainment_config = list(entertainment_configs.values())[0]

# Set up the Streaming service
streaming = Streaming(
    bridge, entertainment_config, entertainment_service.get_ent_conf_repo()
)

# Start streaming messages to the bridge
streaming.start_stream()

# Set the color space to xyb or rgb
streaming.set_color_space("xyb")

# Set input commands for the lights
# First three values in the tuple are placeholders for the color RGB8(int) or (in this case) XYB(float) and the last integer is light ID inside the Entertainment API
streaming.set_input((0.0, 0.63435, 0.3, 0))  # Light command for the first light
streaming.set_input((0.63435, 0.0, 0.3, 1))  # Light command for the second light
# ... Add more inputs as needed for additional lights and logic

# For the purpose of example sleep is used for all inputs to process before stop_stream is called
# Inputs are set inside Event queue meaning they're on another thread so user can interact with application continuously
time.sleep(0.1)

# Stop the streaming session
streaming.stop_stream()
```

Replace the placeholders in the `set_input` method with actual light IDs and the color and brightness values you intend to use. The `start_stream` method initiates the streaming session, `set_color_space` configures the color space, and `stop_stream` terminates the session.

## Contributing

Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag `enhancement`. Don't forget to give the project a star! Thanks again!

1. Fork the Project
2. Switch to the dev branch 
```sh
git checkout dev
```
3. Create your Feature Branch
```sh
git checkout -b feature/AmazingFeature
```
4. Commit your Changes 
```sh
git commit -m 'Add some AmazingFeature'
```
5. Push to the Branch 
```sh
git push origin feature/AmazingFeature
```
6. Open a Pull Request to `dev` branch

Also, the `Discussions` section on GitHub is open for conversations, and the `Issues` section is available for reporting problems or discussing improvements.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "hue-entertainment-pykit",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "<=3.12.1,>=3.10",
    "maintainer_email": "",
    "keywords": "philips,hue,lights,entertainment,api",
    "author": "Dominik Hrdas",
    "author_email": "",
    "download_url": "",
    "platform": null,
    "description": "# Hue Entertainment PyKit\n![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/hrdasdominik/hue-entertainment-pykit/python-app.yml?branch=main&label=main)\n![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/hrdasdominik/hue-entertainment-pykit/python-app.yml?branch=dev&label=dev)\n![GitHub Tag](https://img.shields.io/github/v/tag/hrdasdominik/hue-entertainment-pykit?include_prereleases)\n![Python Version from PEP 621 TOML](https://img.shields.io/python/required-version-toml?tomlFilePath=https%3A%2F%2Fraw.githubusercontent.com%2Fhrdasdominik%2Fhue-entertainment-pykit%2Fmain%2Fpyproject.toml)\n![PyPI - Version](https://img.shields.io/pypi/v/hue-entertainment-pykit?link=https%3A%2F%2Fpypi.org%2Fproject%2Fhue-entertainment-pykit%2F)\n![PyPI - License](https://img.shields.io/pypi/l/hue-entertainment-pykit?link=https%3A%2F%2Fpypi.org%2Fproject%2Fhue-entertainment-pykit%2F)\n\n\n\n<img align=\"right\" alt=\"HEPK logo\" src=\"docs/logo/horizontal.png\" width=\"400\">\n\n## Introduction\n\nUnlock the full spectrum of Philips Hue lighting with the Hue Entertainment PyKit. This Python library simplifies connecting to the Hue Bridge and controlling lights with minimal latency, empowering developers to create dynamic and responsive lighting environments.\n\n## Motivation\n\nConfronted with the complexity of the official Hue EDK and challenges in DTLS handshake implementation which many in the community had, Hue Entertainment PyKit was crafted to provide a straightforward, Python-centric approach to light control using the Philips Hue Entertainment API.\n\n## Quick Start\n\n### Installing\n\nTo install Hue Entertainment PyKit, ensure you have Python installed on your system, and then run the following command:\n```sh\npip install hue-entertainment-pykit\n```\n\n## Usage\n\nTo interact with your Philips Hue lights you can do:\n\n### Logging Configuration (Optional)\n\nFor an enhanced development experience when utilizing this library, logging capabilities have been integrated:\n\n```python\nimport logging\nfrom hue_entertainment_pykit import setup_logs\n\n# Initialize default logging\nsetup_logs()\n\n# Or customize the logging level (e.g., exclude DEBUG messages)\nsetup_logs(level=logging.INFO)\n\n# You can also further customize logging by specifying the maximum log file size and the number of backup files\nsetup_logs(level=logging.INFO, max_file_size=1024 * 1024, backup_count=1)\n\n# Each parameter is optional and comes with predefined default values\n```\n\n### Discovery (Optional)\n\nUse only on your Local Area Network (LAN) to discover and fetch all Bridges that can be used then for streaming\n\n```python\nfrom hue_entertainment_pykit import Discovery\n\ndiscovery = Discovery()\n\n# returns dict[str, Bridge] where the key is name of the bridge and value is the Bridge model with all important info for connecting to Entertainment API\nbridges = discovery.discover_bridges()  \n```\n### Streaming\n\nThe Streaming service in Hue Entertainment PyKit provides thread-safe communication with Hue lights, ensuring smooth and uninterrupted interactions. To prevent connection timeouts, the service implements a keep-alive feature: if no command is sent for 9.5 seconds, the last message is automatically resent to maintain the connection.\n\nBelow is a streamlined example to set up and manage your streaming session:\n\n```python\nimport time\nfrom hue_entertainment_pykit import create_bridge, Entertainment, Streaming\n\n# Set up the Bridge instance with the all needed configuration\nbridge = create_bridge(\n    identification=\"4abb74df-5b6b-410e-819b-bf4448355dff\",\n    rid=\"d476df48-83ad-4430-a104-53c30b46b4d0\",\n    ip_address=\"192.168.1.100\",\n    swversion=1962097030,\n    username=\"8nuTIcK2nOf5oi88-5zPvV1YCt0wTHZIGG8MwXpu\",\n    hue_app_id=\"94530efc-933a-4f7c-97e5-ccf1a9fc79af\",\n    client_key=\"B42753E1E1605A1AB90E1B6A0ECF9C51\",\n    name=\"1st Bridge\"\n)\n\n# Set up the Entertainment API service\nentertainment_service = Entertainment(bridge)\n\n# Fetch all Entertainment Configurations on the Hue bridge\nentertainment_configs = entertainment_service.get_entertainment_configs()\n\n# Add some Entertainment Area selection logic\n# For the purposes of example I'm going to do manual selection\nentertainment_config = list(entertainment_configs.values())[0]\n\n# Set up the Streaming service\nstreaming = Streaming(\n    bridge, entertainment_config, entertainment_service.get_ent_conf_repo()\n)\n\n# Start streaming messages to the bridge\nstreaming.start_stream()\n\n# Set the color space to xyb or rgb\nstreaming.set_color_space(\"xyb\")\n\n# Set input commands for the lights\n# First three values in the tuple are placeholders for the color RGB8(int) or (in this case) XYB(float) and the last integer is light ID inside the Entertainment API\nstreaming.set_input((0.0, 0.63435, 0.3, 0))  # Light command for the first light\nstreaming.set_input((0.63435, 0.0, 0.3, 1))  # Light command for the second light\n# ... Add more inputs as needed for additional lights and logic\n\n# For the purpose of example sleep is used for all inputs to process before stop_stream is called\n# Inputs are set inside Event queue meaning they're on another thread so user can interact with application continuously\ntime.sleep(0.1)\n\n# Stop the streaming session\nstreaming.stop_stream()\n```\n\nReplace the placeholders in the `set_input` method with actual light IDs and the color and brightness values you intend to use. The `start_stream` method initiates the streaming session, `set_color_space` configures the color space, and `stop_stream` terminates the session.\n\n## Contributing\n\nContributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.\n\nIf you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag `enhancement`. Don't forget to give the project a star! Thanks again!\n\n1. Fork the Project\n2. Switch to the dev branch \n```sh\ngit checkout dev\n```\n3. Create your Feature Branch\n```sh\ngit checkout -b feature/AmazingFeature\n```\n4. Commit your Changes \n```sh\ngit commit -m 'Add some AmazingFeature'\n```\n5. Push to the Branch \n```sh\ngit push origin feature/AmazingFeature\n```\n6. Open a Pull Request to `dev` branch\n\nAlso, the `Discussions` section on GitHub is open for conversations, and the `Issues` section is available for reporting problems or discussing improvements.\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2024 Dominik Hrdas  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "A comprehensive Python toolkit for Philips Hue Entertainment API",
    "version": "0.9.0",
    "project_urls": {
        "Repository": "https://github.com/hrdasdominik/hue-entertainment-pykit"
    },
    "split_keywords": [
        "philips",
        "hue",
        "lights",
        "entertainment",
        "api"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "23c0b541c67cacc8fdfd3263cc79826339009da558cafb3cae5f063f52c93e27",
                "md5": "22fdcd257e85fa66555a8c1c35342c81",
                "sha256": "01e4ed0e052ee65c85f0f4d5cc6513f9b705c469f811f41f06318f013d9318c5"
            },
            "downloads": -1,
            "filename": "hue_entertainment_pykit-0.9.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "22fdcd257e85fa66555a8c1c35342c81",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<=3.12.1,>=3.10",
            "size": 36161,
            "upload_time": "2024-01-26T12:25:34",
            "upload_time_iso_8601": "2024-01-26T12:25:34.162197Z",
            "url": "https://files.pythonhosted.org/packages/23/c0/b541c67cacc8fdfd3263cc79826339009da558cafb3cae5f063f52c93e27/hue_entertainment_pykit-0.9.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-26 12:25:34",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "hrdasdominik",
    "github_project": "hue-entertainment-pykit",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "hue-entertainment-pykit"
}
        
Elapsed time: 0.27774s