Skip to content

Commit

Permalink
refactored functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
hrdasdominik committed Jan 22, 2025
1 parent e62b763 commit 68a1a17
Show file tree
Hide file tree
Showing 63 changed files with 2,533 additions and 1,602 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ streaming = Streaming(
)

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

# Set the color space to xyb or rgb
streaming.set_color_space("xyb")
Expand All @@ -117,7 +117,7 @@ streaming.set_input((0.63435, 0.0, 0.3, 1)) # Light command for the second ligh
time.sleep(0.1)

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

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.
4 changes: 2 additions & 2 deletions example/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def example():
entertainment_service.get_ent_conf_repo(),
)

streaming.start_stream()
streaming.setup_for_streaming()

streaming.set_color_space("xyb")

Expand All @@ -52,7 +52,7 @@ def example():

time.sleep(0.1)

streaming.stop_stream()
streaming.setup_for_stop_streaming()
logging.info("Example finished")


Expand Down
41 changes: 25 additions & 16 deletions example/example_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,47 @@
6. Stops the streaming service after a brief pause.
"""
import time
from decimal import Decimal

from src.hue_entertainment_pykit.hue_entertainment_pykit_new import HueEntertainmentPyKit
from src.hue_entertainment_pykit.models.light import LightXYB
from src.hue_entertainment_pykit.hue_entertainment_pykit import HueEntertainmentPyKit
from src.hue_entertainment_pykit.light.light_xyb import LightXYB
from src.hue_entertainment_pykit.utils.color_space_enum import ColorSpaceEnum
from src.hue_entertainment_pykit.utils.logger import logging


def example():
"""Runs the example workflow for discovering bridges and managing streaming."""

hue_pykit = HueEntertainmentPyKit()
hue_pykit.modify_log_config(level=logging.WARNING)
hue_pykit = HueEntertainmentPyKit("example_new#test")
hue_pykit.modify_log_config(level=logging.DEBUG)

logging.info("Example started")

bridge_dict = hue_pykit.get_all_bridges()
hue_pykit.set_bridge(bridge_dict["1st Bridge"])
bridge_name_list = hue_pykit.get_bridge_name_list()
entertainment_configuration_name_list = hue_pykit.get_entertainment_configuration_name_list(bridge_name_list[0])

configurations = hue_pykit.get_entertainment_configurations()
hue_pykit.set_entertainment_configuration(configurations["43bcab07-e159-45bb-8760-59e347559319"])
hue_pykit.set_active_entertainment_configuration_on_bridge(bridge_name_list[0], entertainment_configuration_name_list[0])

hue_pykit.start_stream()
hue_pykit.set_color_space("xyb")
light_list = hue_pykit.get_light_list_from_bridge(bridge_name_list[0])

light_list = []
light1 = LightXYB(1, "", 0.4, 0.3, 1.0)
light_list.append(light1)
hue_pykit.start_streaming_on_all_bridges()

hue_pykit.set_lights_functions(light_list)
hue_pykit.set_color_space(ColorSpaceEnum.XYB)

time.sleep(0.1)
color = Decimal("0.0")
for _ in range(10):
logging.info(f"Color space: {color}")
if color > 1.0:
break

hue_pykit.stop_stream()
for light in light_list:
light.set_colors(float(color), float(color), 1.0)

hue_pykit.set_color_and_brightness(bridge_name_list[0], light_list)
color += Decimal("0.1")
time.sleep(0.1)

hue_pykit.stop_streaming_on_all_bridges()
logging.info("Example finished")


Expand Down
File renamed without changes.
25 changes: 25 additions & 0 deletions src/hue_entertainment_pykit/bridge/bridge_api_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import logging

from src.hue_entertainment_pykit.bridge.bridge import Bridge
from src.hue_entertainment_pykit.http.http_client import HttpClient
from src.hue_entertainment_pykit.http.http_method_enum import HttpMethodEnum
from src.hue_entertainment_pykit.light.light import Light
from src.hue_entertainment_pykit.utils.endpoint_enum import EndpointEnum


# pylint: disable=too-few-public-methods
class BridgeApiService:
def __init__(self):
self._http_client = HttpClient()

def add_hue_application_key(self, hue_application_key: str) -> None:
logging.info("Adding Hue Application Key: {}".format(hue_application_key))
self._http_client.add_headers("hue-application-key", hue_application_key)
logging.info("Successfully added Hue Application Key: {}".format(hue_application_key))

def fetch_lights(self) -> list[Light]:
logging.info("Fetching lights")
response_light = self._http_client.make_request(HttpMethodEnum.GET, EndpointEnum.RESOURCE_LIGHT)
data: list[Light] = response_light.json()["data"]
logging.info("Fetched lights successfully")
return data
Loading

0 comments on commit 68a1a17

Please sign in to comment.