Package: hue-entertainment-pykit
Hue Entertainment PyKitIntroductionUnlock 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.MotivationConfronted 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 StartInstallingTo install Hue Entertainment PyKit, ensure you have Python installed on your system, and then run the following command:pipinstallhue-entertainment-pykitUsageTo 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:importloggingfromhue_entertainment_pykitimportsetup_logs# Initialize default loggingsetup_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 filessetup_logs(level=logging.INFO,max_file_size=1024*1024,backup_count=1)# Each parameter is optional and comes with predefined default valuesDiscovery (Optional)Use only on your Local Area Network (LAN) to discover and fetch all Bridges that can be used then for streamingfromhue_entertainment_pykitimportDiscoverydiscovery=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 APIbridges=discovery.discover_bridges()StreamingThe 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:importtimefromhue_entertainment_pykitimportcreate_bridge,Entertainment,Streaming# Set up the Bridge instance with the all needed configurationbridge=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 serviceentertainment_service=Entertainment(bridge)# Fetch all Entertainment Configurations on the Hue bridgeentertainment_configs=entertainment_service.get_entertainment_configs()# Add some Entertainment Area selection logic# For the purposes of example I'm going to do manual selectionentertainment_config=list(entertainment_configs.values())[0]# Set up the Streaming servicestreaming=Streaming(bridge,entertainment_config,entertainment_service.get_ent_conf_repo())# Start streaming messages to the bridgestreaming.start_stream()# Set the color space to xyb or rgbstreaming.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 APIstreaming.set_input((0.0,0.63435,0.3,0))# Light command for the first lightstreaming.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 continuouslytime.sleep(0.1)# Stop the streaming sessionstreaming.stop_stream()Replace the placeholders in theset_inputmethod with actual light IDs and the color and brightness values you intend to use. Thestart_streammethod initiates the streaming session,set_color_spaceconfigures the color space, andstop_streamterminates the session.ContributingContributions 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 tagenhancement. Don't forget to give the project a star! Thanks again!Fork the ProjectSwitch to the dev branchgitcheckoutdevCreate your Feature Branchgitcheckout-bfeature/AmazingFeatureCommit your Changesgitcommit-m'Add some AmazingFeature'Push to the Branchgitpushoriginfeature/AmazingFeatureOpen a Pull Request todevbranchAlso, theDiscussionssection on GitHub is open for conversations, and theIssuessection is available for reporting problems or discussing improvements.