Skip to content

Commit

Permalink
added led device and brightness control
Browse files Browse the repository at this point in the history
  • Loading branch information
johnneerdael committed Jan 10, 2025
1 parent 506fb07 commit d4a66cb
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 24 deletions.
65 changes: 52 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,38 @@
# HyperHDR Control for Home Assistant

A Home Assistant integration to control HyperHDR LED controller. This integration provides a switch to control the USB capture device and buttons to activate various effects.
A Home Assistant integration to control HyperHDR LED controller. This integration provides switches to control the LED and USB capture devices, a brightness slider, and buttons to activate various effects.

## Features

- Control USB Video Capture device (on/off)
- Activate various effects with buttons:
- Atomic Swirl
- Blue mood blobs
- Breath
- Candle
- Cinema brighten/dim lights
- And many more!
### Controls
- **LED Output Switch**: Turn the LED strip on/off
- **USB Capture Switch**: Control the USB capture device
- **Brightness Slider**: Adjust LED brightness from 0-100%

### Effects
Buttons to activate various effects including:
- Atomic Swirl
- Blue mood blobs
- Breath
- Candle
- Cinema brighten/dim lights
- Cold mood blobs
- Double swirl
- Full color mood blobs
- Green mood blobs
- Knight rider
- Notify Blue
- Plasma
- Police lights (single/solid)
- Rainbow swirl (normal/fast)
- Rainbow waves
- Red mood blobs
- Sea waves
- Sparks
- Strobe (red/white)
- System shutdown
- Warm mood blobs
- Waves with color

## Installation

Expand All @@ -34,21 +55,39 @@ A Home Assistant integration to control HyperHDR LED controller. This integratio

## Configuration

### Automatic Discovery
The integration will automatically discover HyperHDR instances on your network using zeroconf.

### Manual Setup
1. Go to Settings → Devices & Services
2. Click "Add Integration"
3. Search for "HyperHDR Control"
4. Enter your HyperHDR server's IP address and port (default: 8090)

## Usage

### USB Capture Control
- Use the "HyperHDR USB Capture" switch to turn the video capture on or off
### LED Control
- Use the "HyperHDR LED Output" switch to turn the LED strip on or off
- Use the "HyperHDR USB Capture" switch to control the USB capture device
- Adjust the "HyperHDR Brightness" slider to control LED brightness (0-100%)

### Effects
- Each effect is available as a button in Home Assistant
- Press any effect button to activate that effect
- Effects will run indefinitely until another effect is activated or the USB capture is turned off
- Effects will run indefinitely until another effect is activated or the LED output is turned off

### Automations
All entities can be used in automations. Examples:
- Turn on LED strip at sunset
- Activate specific effects at certain times
- Adjust brightness based on time of day
- Turn on USB capture when watching TV

## Support

If you encounter any issues or have suggestions, please open an issue on GitHub.
If you encounter any issues or have suggestions:
1. Check the debug logs if you encounter any problems
2. Open an issue on GitHub with:
- Description of the problem
- Debug logs if applicable
- Steps to reproduce the issue
28 changes: 24 additions & 4 deletions custom_components/hyperhdr_control/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@
from homeassistant.core import HomeAssistant
from homeassistant.const import CONF_HOST, CONF_PORT, Platform
from homeassistant.helpers import device_registry as dr
import asyncio

from .const import DOMAIN

PLATFORMS: list[Platform] = [Platform.SWITCH, Platform.BUTTON, Platform.NUMBER]
# Define platforms to load
PLATFORMS = [
Platform.SWITCH,
Platform.BUTTON,
Platform.NUMBER,
]

async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up HyperHDR Control from a config entry."""
Expand All @@ -26,15 +32,29 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
manufacturer="HyperHDR",
name=f"HyperHDR ({entry.data[CONF_HOST]})",
model="HyperHDR LED Controller",
sw_version="1.3.1",
sw_version="1.3.2",
)

await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
# Set up all platforms
for platform in PLATFORMS:
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, platform)
)

return True

async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
unload_ok = all(
await asyncio.gather(
*[
hass.config_entries.async_forward_entry_unload(entry, platform)
for platform in PLATFORMS
]
)
)

if unload_ok:
hass.data[DOMAIN].pop(entry.entry_id)

return unload_ok
2 changes: 1 addition & 1 deletion custom_components/hyperhdr_control/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def device_info(self) -> DeviceInfo:
manufacturer="HyperHDR",
name=f"HyperHDR ({self._host})",
model="HyperHDR LED Controller",
sw_version="1.3.1",
sw_version="1.3.2",
)

async def async_press(self) -> None:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/hyperhdr_control/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"codeowners": [],
"requirements": ["aiohttp", "zeroconf"],
"iot_class": "local_polling",
"version": "1.3.1",
"version": "1.3.2",
"config_flow": true,
"zeroconf": ["_hyperhdr-http._tcp.local."],
"logo": "https://raw.githubusercontent.com/johnneerdael/hyperhdr_control/main/hyperhdr_control-logo.png"
Expand Down
30 changes: 26 additions & 4 deletions custom_components/hyperhdr_control/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ def __init__(self, entry_id: str, host: str, port: int) -> None:
self._attr_native_step = 1
self._attr_mode = NumberMode.SLIDER
self._attr_native_unit_of_measurement = PERCENTAGE
self._attr_native_value = 100 # Set initial value
self._attr_available = True # Explicitly set availability
self._last_update = datetime.min
self._pending_value = None
self._update_lock = asyncio.Lock()
Expand All @@ -63,9 +65,14 @@ def device_info(self) -> DeviceInfo:
manufacturer="HyperHDR",
name=f"HyperHDR ({self._host})",
model="HyperHDR LED Controller",
sw_version="1.3.1",
sw_version="1.3.2",
)

@property
def available(self) -> bool:
"""Return if entity is available."""
return self._attr_available

async def _delayed_update(self) -> None:
"""Handle the delayed update of the brightness value."""
try:
Expand Down Expand Up @@ -111,11 +118,15 @@ async def _set_brightness(self, value: float) -> None:

async with async_timeout.timeout(10):
async with session.get(url, params=params) as response:
if response.status != 200:
if response.status == 200:
self._attr_available = True
else:
self._attr_available = False
_LOGGER.error("Failed to set brightness: %s", response.status)
response_text = await response.text()
_LOGGER.error("Response: %s", response_text)
except (aiohttp.ClientError, TimeoutError) as error:
self._attr_available = False
_LOGGER.error("Error setting brightness: %s", error)

async def async_update(self) -> None:
Expand All @@ -133,7 +144,18 @@ async def async_update(self) -> None:
async with session.get(url, params=params) as response:
if response.status == 200:
data = await response.json()
adjustment = data.get("info", {}).get("adjustment", {})
self._attr_native_value = float(adjustment.get("brightness", 100))
_LOGGER.debug("Received serverinfo response: %s", data)

# Find the brightness in the adjustment array
adjustments = data.get("info", {}).get("adjustment", [])
if isinstance(adjustments, list) and adjustments:
# Take the first adjustment's brightness value
brightness = adjustments[0].get("brightness", 100)
self._attr_native_value = float(brightness)

self._attr_available = True
else:
self._attr_available = False
except (aiohttp.ClientError, TimeoutError) as error:
self._attr_available = False
_LOGGER.error("Error updating brightness: %s", error)
2 changes: 1 addition & 1 deletion custom_components/hyperhdr_control/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def device_info(self) -> DeviceInfo:
manufacturer="HyperHDR",
name=f"HyperHDR ({self._host})",
model="HyperHDR LED Controller",
sw_version="1.3.1",
sw_version="1.3.2",
)

async def async_turn_on(self, **kwargs: Any) -> None:
Expand Down

0 comments on commit d4a66cb

Please sign in to comment.