Skip to content

Commit

Permalink
added logo
Browse files Browse the repository at this point in the history
  • Loading branch information
johnneerdael committed Jan 10, 2025
1 parent ee84836 commit 91336c5
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 23 deletions.
87 changes: 68 additions & 19 deletions custom_components/hyperhdr_control/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,96 @@
from homeassistant.const import CONF_HOST, CONF_PORT
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResult
from homeassistant.helpers import device_registry as dr
import aiohttp
import async_timeout

DOMAIN = "hyperhdr_control"
from .const import DOMAIN, DEFAULT_PORT

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

VERSION = 1

def __init__(self) -> None:
"""Initialize the config flow."""
self._host: str | None = None
self._port: int | None = None
self._name: str | None = None

async def async_step_zeroconf(self, discovery_info) -> FlowResult:
"""Handle zeroconf discovery."""
self._host = discovery_info.host
self._port = discovery_info.port or DEFAULT_PORT
self._name = discovery_info.name.replace("._hyperhdr-http._tcp.local.", "")

# Check if already configured
await self.async_set_unique_id(f"{self._host}:{self._port}")
self._abort_if_unique_id_configured()

# Set title for confirmation
self.context["title_placeholders"] = {"name": self._name}

return await self.async_step_confirm()

async def async_step_confirm(self, user_input=None) -> FlowResult:
"""Handle user-confirmation of discovered node."""
if user_input is not None:
return await self._test_connection()

return self.async_show_form(
step_id="confirm",
description_placeholders={
"name": self._name,
"host": self._host,
"port": self._port,
},
)

async def async_step_user(
self, user_input: dict[str, any] | None = None
) -> FlowResult:
"""Handle the initial step."""
errors = {}

if user_input is not None:
try:
# Test the connection
async with aiohttp.ClientSession() as session:
url = f"http://{user_input[CONF_HOST]}:{user_input[CONF_PORT]}/json-rpc"
test_request = {
"command": "serverinfo"
}
async with async_timeout.timeout(10):
async with session.get(url, params={"request": str(test_request)}) as response:
if response.status == 200:
return self.async_create_entry(
title=f"HyperHDR Control ({user_input[CONF_HOST]})",
data=user_input
)
except (aiohttp.ClientError, TimeoutError):
errors["base"] = "cannot_connect"
self._host = user_input[CONF_HOST]
self._port = user_input[CONF_PORT]
return await self._test_connection()

return self.async_show_form(
step_id="user",
data_schema=vol.Schema(
{
vol.Required(CONF_HOST): str,
vol.Required(CONF_PORT, default=8090): int,
vol.Required(CONF_PORT, default=DEFAULT_PORT): int,
}
),
errors=errors,
)
)

async def _test_connection(self) -> FlowResult:
"""Test the connection to HyperHDR."""
try:
async with aiohttp.ClientSession() as session:
url = f"http://{self._host}:{self._port}/json-rpc"
test_request = {
"command": "serverinfo"
}
async with async_timeout.timeout(10):
async with session.get(url, params={"request": str(test_request)}) as response:
if response.status == 200:
await self.async_set_unique_id(
f"{self._host}:{self._port}", raise_on_progress=False
)
return self.async_create_entry(
title=self._name or f"HyperHDR ({self._host})",
data={
CONF_HOST: self._host,
CONF_PORT: self._port,
}
)
except (aiohttp.ClientError, TimeoutError):
pass

return self.async_abort(reason="cannot_connect")
1 change: 1 addition & 0 deletions custom_components/hyperhdr_control/const.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Constants for the HyperHDR Control integration."""

DOMAIN = "hyperhdr_control"
DEFAULT_PORT = 8090

AVAILABLE_EFFECTS = [
"Atomic Swirl",
Expand Down
5 changes: 3 additions & 2 deletions custom_components/hyperhdr_control/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
"documentation": "https://github.com/johnneerdael/hyperhdr_control",
"dependencies": [],
"codeowners": [],
"requirements": ["aiohttp"],
"requirements": ["aiohttp", "zeroconf"],
"iot_class": "local_polling",
"version": "1.1.0",
"config_flow": true,
"logo": "images/logo.png"
"zeroconf": ["_hyperhdr-http._tcp.local."],
"logo": "https://raw.githubusercontent.com/johnneerdael/hyperhdr_control/main/hyperhdr_control-logo.png"
}
7 changes: 6 additions & 1 deletion custom_components/hyperhdr_control/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@
"host": "Host",
"port": "Port"
}
},
"confirm": {
"title": "Confirm HyperHDR Discovery",
"description": "Do you want to add HyperHDR {name} at {host}:{port} to Home Assistant?"
}
},
"error": {
"cannot_connect": "Failed to connect to HyperHDR server"
},
"abort": {
"already_configured": "Device is already configured"
"already_configured": "Device is already configured",
"cannot_connect": "Failed to connect to HyperHDR server"
}
}
}
8 changes: 7 additions & 1 deletion hacs.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,11 @@
"documentation": "https://github.com/johnneerdael/hyperhdr_control",
"issue_tracker": "https://github.com/johnneerdael/hyperhdr_control/issues",
"homeassistant": "2023.8.0",
"iot_class": "local_polling"
"iot_class": "local_polling",
"zip_release": true,
"filename": "hyperhdr_control.zip",
"hide_default_branch": true,
"content_in_root": false,
"render_readme": true,
"logo": "hyperhdr_control-logo.png"
}

0 comments on commit 91336c5

Please sign in to comment.