Skip to content

Commit 91336c5

Browse files
committed
added logo
1 parent ee84836 commit 91336c5

File tree

6 files changed

+85
-23
lines changed

6 files changed

+85
-23
lines changed

custom_components/hyperhdr_control/config_flow.py

Lines changed: 68 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,47 +6,96 @@
66
from homeassistant.const import CONF_HOST, CONF_PORT
77
from homeassistant.core import HomeAssistant
88
from homeassistant.data_entry_flow import FlowResult
9+
from homeassistant.helpers import device_registry as dr
910
import aiohttp
1011
import async_timeout
1112

12-
DOMAIN = "hyperhdr_control"
13+
from .const import DOMAIN, DEFAULT_PORT
1314

1415
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
1516
"""Handle a config flow for HyperHDR Control."""
1617

1718
VERSION = 1
1819

20+
def __init__(self) -> None:
21+
"""Initialize the config flow."""
22+
self._host: str | None = None
23+
self._port: int | None = None
24+
self._name: str | None = None
25+
26+
async def async_step_zeroconf(self, discovery_info) -> FlowResult:
27+
"""Handle zeroconf discovery."""
28+
self._host = discovery_info.host
29+
self._port = discovery_info.port or DEFAULT_PORT
30+
self._name = discovery_info.name.replace("._hyperhdr-http._tcp.local.", "")
31+
32+
# Check if already configured
33+
await self.async_set_unique_id(f"{self._host}:{self._port}")
34+
self._abort_if_unique_id_configured()
35+
36+
# Set title for confirmation
37+
self.context["title_placeholders"] = {"name": self._name}
38+
39+
return await self.async_step_confirm()
40+
41+
async def async_step_confirm(self, user_input=None) -> FlowResult:
42+
"""Handle user-confirmation of discovered node."""
43+
if user_input is not None:
44+
return await self._test_connection()
45+
46+
return self.async_show_form(
47+
step_id="confirm",
48+
description_placeholders={
49+
"name": self._name,
50+
"host": self._host,
51+
"port": self._port,
52+
},
53+
)
54+
1955
async def async_step_user(
2056
self, user_input: dict[str, any] | None = None
2157
) -> FlowResult:
2258
"""Handle the initial step."""
2359
errors = {}
2460

2561
if user_input is not None:
26-
try:
27-
# Test the connection
28-
async with aiohttp.ClientSession() as session:
29-
url = f"http://{user_input[CONF_HOST]}:{user_input[CONF_PORT]}/json-rpc"
30-
test_request = {
31-
"command": "serverinfo"
32-
}
33-
async with async_timeout.timeout(10):
34-
async with session.get(url, params={"request": str(test_request)}) as response:
35-
if response.status == 200:
36-
return self.async_create_entry(
37-
title=f"HyperHDR Control ({user_input[CONF_HOST]})",
38-
data=user_input
39-
)
40-
except (aiohttp.ClientError, TimeoutError):
41-
errors["base"] = "cannot_connect"
62+
self._host = user_input[CONF_HOST]
63+
self._port = user_input[CONF_PORT]
64+
return await self._test_connection()
4265

4366
return self.async_show_form(
4467
step_id="user",
4568
data_schema=vol.Schema(
4669
{
4770
vol.Required(CONF_HOST): str,
48-
vol.Required(CONF_PORT, default=8090): int,
71+
vol.Required(CONF_PORT, default=DEFAULT_PORT): int,
4972
}
5073
),
5174
errors=errors,
52-
)
75+
)
76+
77+
async def _test_connection(self) -> FlowResult:
78+
"""Test the connection to HyperHDR."""
79+
try:
80+
async with aiohttp.ClientSession() as session:
81+
url = f"http://{self._host}:{self._port}/json-rpc"
82+
test_request = {
83+
"command": "serverinfo"
84+
}
85+
async with async_timeout.timeout(10):
86+
async with session.get(url, params={"request": str(test_request)}) as response:
87+
if response.status == 200:
88+
await self.async_set_unique_id(
89+
f"{self._host}:{self._port}", raise_on_progress=False
90+
)
91+
return self.async_create_entry(
92+
title=self._name or f"HyperHDR ({self._host})",
93+
data={
94+
CONF_HOST: self._host,
95+
CONF_PORT: self._port,
96+
}
97+
)
98+
except (aiohttp.ClientError, TimeoutError):
99+
pass
100+
101+
return self.async_abort(reason="cannot_connect")

custom_components/hyperhdr_control/const.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Constants for the HyperHDR Control integration."""
22

33
DOMAIN = "hyperhdr_control"
4+
DEFAULT_PORT = 8090
45

56
AVAILABLE_EFFECTS = [
67
"Atomic Swirl",

custom_components/hyperhdr_control/manifest.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
"documentation": "https://github.com/johnneerdael/hyperhdr_control",
55
"dependencies": [],
66
"codeowners": [],
7-
"requirements": ["aiohttp"],
7+
"requirements": ["aiohttp", "zeroconf"],
88
"iot_class": "local_polling",
99
"version": "1.1.0",
1010
"config_flow": true,
11-
"logo": "images/logo.png"
11+
"zeroconf": ["_hyperhdr-http._tcp.local."],
12+
"logo": "https://raw.githubusercontent.com/johnneerdael/hyperhdr_control/main/hyperhdr_control-logo.png"
1213
}

custom_components/hyperhdr_control/translations/en.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,18 @@
77
"host": "Host",
88
"port": "Port"
99
}
10+
},
11+
"confirm": {
12+
"title": "Confirm HyperHDR Discovery",
13+
"description": "Do you want to add HyperHDR {name} at {host}:{port} to Home Assistant?"
1014
}
1115
},
1216
"error": {
1317
"cannot_connect": "Failed to connect to HyperHDR server"
1418
},
1519
"abort": {
16-
"already_configured": "Device is already configured"
20+
"already_configured": "Device is already configured",
21+
"cannot_connect": "Failed to connect to HyperHDR server"
1722
}
1823
}
1924
}

hacs.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,11 @@
55
"documentation": "https://github.com/johnneerdael/hyperhdr_control",
66
"issue_tracker": "https://github.com/johnneerdael/hyperhdr_control/issues",
77
"homeassistant": "2023.8.0",
8-
"iot_class": "local_polling"
8+
"iot_class": "local_polling",
9+
"zip_release": true,
10+
"filename": "hyperhdr_control.zip",
11+
"hide_default_branch": true,
12+
"content_in_root": false,
13+
"render_readme": true,
14+
"logo": "hyperhdr_control-logo.png"
915
}

0 commit comments

Comments
 (0)