Skip to content

Commit d4a66cb

Browse files
committed
added led device and brightness control
1 parent 506fb07 commit d4a66cb

File tree

6 files changed

+105
-24
lines changed

6 files changed

+105
-24
lines changed

README.md

Lines changed: 52 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,38 @@
11
# HyperHDR Control for Home Assistant
22

3-
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.
3+
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.
44

55
## Features
66

7-
- Control USB Video Capture device (on/off)
8-
- Activate various effects with buttons:
9-
- Atomic Swirl
10-
- Blue mood blobs
11-
- Breath
12-
- Candle
13-
- Cinema brighten/dim lights
14-
- And many more!
7+
### Controls
8+
- **LED Output Switch**: Turn the LED strip on/off
9+
- **USB Capture Switch**: Control the USB capture device
10+
- **Brightness Slider**: Adjust LED brightness from 0-100%
11+
12+
### Effects
13+
Buttons to activate various effects including:
14+
- Atomic Swirl
15+
- Blue mood blobs
16+
- Breath
17+
- Candle
18+
- Cinema brighten/dim lights
19+
- Cold mood blobs
20+
- Double swirl
21+
- Full color mood blobs
22+
- Green mood blobs
23+
- Knight rider
24+
- Notify Blue
25+
- Plasma
26+
- Police lights (single/solid)
27+
- Rainbow swirl (normal/fast)
28+
- Rainbow waves
29+
- Red mood blobs
30+
- Sea waves
31+
- Sparks
32+
- Strobe (red/white)
33+
- System shutdown
34+
- Warm mood blobs
35+
- Waves with color
1536

1637
## Installation
1738

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

3556
## Configuration
3657

58+
### Automatic Discovery
59+
The integration will automatically discover HyperHDR instances on your network using zeroconf.
60+
61+
### Manual Setup
3762
1. Go to Settings → Devices & Services
3863
2. Click "Add Integration"
3964
3. Search for "HyperHDR Control"
4065
4. Enter your HyperHDR server's IP address and port (default: 8090)
4166

4267
## Usage
4368

44-
### USB Capture Control
45-
- Use the "HyperHDR USB Capture" switch to turn the video capture on or off
69+
### LED Control
70+
- Use the "HyperHDR LED Output" switch to turn the LED strip on or off
71+
- Use the "HyperHDR USB Capture" switch to control the USB capture device
72+
- Adjust the "HyperHDR Brightness" slider to control LED brightness (0-100%)
4673

4774
### Effects
4875
- Each effect is available as a button in Home Assistant
4976
- Press any effect button to activate that effect
50-
- Effects will run indefinitely until another effect is activated or the USB capture is turned off
77+
- Effects will run indefinitely until another effect is activated or the LED output is turned off
78+
79+
### Automations
80+
All entities can be used in automations. Examples:
81+
- Turn on LED strip at sunset
82+
- Activate specific effects at certain times
83+
- Adjust brightness based on time of day
84+
- Turn on USB capture when watching TV
5185

5286
## Support
5387

54-
If you encounter any issues or have suggestions, please open an issue on GitHub.
88+
If you encounter any issues or have suggestions:
89+
1. Check the debug logs if you encounter any problems
90+
2. Open an issue on GitHub with:
91+
- Description of the problem
92+
- Debug logs if applicable
93+
- Steps to reproduce the issue

custom_components/hyperhdr_control/__init__.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@
55
from homeassistant.core import HomeAssistant
66
from homeassistant.const import CONF_HOST, CONF_PORT, Platform
77
from homeassistant.helpers import device_registry as dr
8+
import asyncio
89

910
from .const import DOMAIN
1011

11-
PLATFORMS: list[Platform] = [Platform.SWITCH, Platform.BUTTON, Platform.NUMBER]
12+
# Define platforms to load
13+
PLATFORMS = [
14+
Platform.SWITCH,
15+
Platform.BUTTON,
16+
Platform.NUMBER,
17+
]
1218

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

32-
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
38+
# Set up all platforms
39+
for platform in PLATFORMS:
40+
hass.async_create_task(
41+
hass.config_entries.async_forward_entry_setup(entry, platform)
42+
)
43+
3344
return True
3445

3546
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
3647
"""Unload a config entry."""
37-
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
48+
unload_ok = all(
49+
await asyncio.gather(
50+
*[
51+
hass.config_entries.async_forward_entry_unload(entry, platform)
52+
for platform in PLATFORMS
53+
]
54+
)
55+
)
56+
3857
if unload_ok:
3958
hass.data[DOMAIN].pop(entry.entry_id)
59+
4060
return unload_ok

custom_components/hyperhdr_control/button.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def device_info(self) -> DeviceInfo:
5353
manufacturer="HyperHDR",
5454
name=f"HyperHDR ({self._host})",
5555
model="HyperHDR LED Controller",
56-
sw_version="1.3.1",
56+
sw_version="1.3.2",
5757
)
5858

5959
async def async_press(self) -> None:

custom_components/hyperhdr_control/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"codeowners": [],
77
"requirements": ["aiohttp", "zeroconf"],
88
"iot_class": "local_polling",
9-
"version": "1.3.1",
9+
"version": "1.3.2",
1010
"config_flow": true,
1111
"zeroconf": ["_hyperhdr-http._tcp.local."],
1212
"logo": "https://raw.githubusercontent.com/johnneerdael/hyperhdr_control/main/hyperhdr_control-logo.png"

custom_components/hyperhdr_control/number.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ def __init__(self, entry_id: str, host: str, port: int) -> None:
5050
self._attr_native_step = 1
5151
self._attr_mode = NumberMode.SLIDER
5252
self._attr_native_unit_of_measurement = PERCENTAGE
53+
self._attr_native_value = 100 # Set initial value
54+
self._attr_available = True # Explicitly set availability
5355
self._last_update = datetime.min
5456
self._pending_value = None
5557
self._update_lock = asyncio.Lock()
@@ -63,9 +65,14 @@ def device_info(self) -> DeviceInfo:
6365
manufacturer="HyperHDR",
6466
name=f"HyperHDR ({self._host})",
6567
model="HyperHDR LED Controller",
66-
sw_version="1.3.1",
68+
sw_version="1.3.2",
6769
)
6870

71+
@property
72+
def available(self) -> bool:
73+
"""Return if entity is available."""
74+
return self._attr_available
75+
6976
async def _delayed_update(self) -> None:
7077
"""Handle the delayed update of the brightness value."""
7178
try:
@@ -111,11 +118,15 @@ async def _set_brightness(self, value: float) -> None:
111118

112119
async with async_timeout.timeout(10):
113120
async with session.get(url, params=params) as response:
114-
if response.status != 200:
121+
if response.status == 200:
122+
self._attr_available = True
123+
else:
124+
self._attr_available = False
115125
_LOGGER.error("Failed to set brightness: %s", response.status)
116126
response_text = await response.text()
117127
_LOGGER.error("Response: %s", response_text)
118128
except (aiohttp.ClientError, TimeoutError) as error:
129+
self._attr_available = False
119130
_LOGGER.error("Error setting brightness: %s", error)
120131

121132
async def async_update(self) -> None:
@@ -133,7 +144,18 @@ async def async_update(self) -> None:
133144
async with session.get(url, params=params) as response:
134145
if response.status == 200:
135146
data = await response.json()
136-
adjustment = data.get("info", {}).get("adjustment", {})
137-
self._attr_native_value = float(adjustment.get("brightness", 100))
147+
_LOGGER.debug("Received serverinfo response: %s", data)
148+
149+
# Find the brightness in the adjustment array
150+
adjustments = data.get("info", {}).get("adjustment", [])
151+
if isinstance(adjustments, list) and adjustments:
152+
# Take the first adjustment's brightness value
153+
brightness = adjustments[0].get("brightness", 100)
154+
self._attr_native_value = float(brightness)
155+
156+
self._attr_available = True
157+
else:
158+
self._attr_available = False
138159
except (aiohttp.ClientError, TimeoutError) as error:
160+
self._attr_available = False
139161
_LOGGER.error("Error updating brightness: %s", error)

custom_components/hyperhdr_control/switch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def device_info(self) -> DeviceInfo:
5858
manufacturer="HyperHDR",
5959
name=f"HyperHDR ({self._host})",
6060
model="HyperHDR LED Controller",
61-
sw_version="1.3.1",
61+
sw_version="1.3.2",
6262
)
6363

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

0 commit comments

Comments
 (0)