Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Axion Lighting integration #125039

Open
wants to merge 18 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ build.json @home-assistant/supervisor
/homeassistant/components/avea/ @pattyland
/homeassistant/components/awair/ @ahayworth @danielsjf
/tests/components/awair/ @ahayworth @danielsjf
/homeassistant/components/axion_dmx/ @Vrncanac
/tests/components/axion_dmx/ @Vrncanac
/homeassistant/components/axis/ @Kane610
/tests/components/axis/ @Kane610
/homeassistant/components/azure_data_explorer/ @kaareseras
Expand Down
45 changes: 45 additions & 0 deletions homeassistant/components/axion_dmx/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"""The Axion Lighting integration."""

from __future__ import annotations

from libaxion_dmx import AxionDmxApi # Import the API class
Vrncanac marked this conversation as resolved.
Show resolved Hide resolved

from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant

from .const import CONF_LIGHT_TYPE, DOMAIN

PLATFORMS: list[Platform] = [Platform.LIGHT]


async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
Vrncanac marked this conversation as resolved.
Show resolved Hide resolved
"""Set up Axion Lighting from a config entry."""

hass.data.setdefault(DOMAIN, {})
Vrncanac marked this conversation as resolved.
Show resolved Hide resolved

# Create API instance
api = AxionDmxApi(entry.data["host"], entry.data["password"])
Vrncanac marked this conversation as resolved.
Show resolved Hide resolved

# Validate the API connection (and authentication)
if not await api.authenticate():
return False

# Store an API object for your platforms to access
hass.data[DOMAIN][entry.entry_id] = {
"api": api,
"channel": entry.data["channel"],
"light_type": entry.data[CONF_LIGHT_TYPE],
Vrncanac marked this conversation as resolved.
Show resolved Hide resolved
}

await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)

return True


async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
hass.data[DOMAIN].pop(entry.entry_id)

return unload_ok
73 changes: 73 additions & 0 deletions homeassistant/components/axion_dmx/config_flow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
"""Config flow for Axion Lighting integration."""

from __future__ import annotations

from typing import Any

from libaxion_dmx import AxionDmxApi
import voluptuous as vol

from homeassistant import config_entries
from homeassistant.config_entries import ConfigFlowResult
from homeassistant.const import CONF_HOST, CONF_PASSWORD
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError

from .const import _LOGGER, CONF_CHANNEL, CONF_LIGHT_TYPE, DOMAIN

STEP_USER_DATA_SCHEMA = vol.Schema(
{
vol.Required(CONF_HOST): str,
vol.Required(CONF_PASSWORD): str,
vol.Required(CONF_CHANNEL): vol.All(vol.Coerce(int), vol.Range(min=1)),
Vrncanac marked this conversation as resolved.
Show resolved Hide resolved
vol.Required(CONF_LIGHT_TYPE): vol.In(
["White", "Tunable White", "RGB", "RGBW", "RGBWW"]
),
Vrncanac marked this conversation as resolved.
Show resolved Hide resolved
}
)


async def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> dict[str, Any]:
"""Validate the user input allows us to connect."""
api = AxionDmxApi(data[CONF_HOST], data[CONF_PASSWORD])

if not await api.authenticate():
raise InvalidAuth

return {"title": f"Axion DMX Light - Channel {data[CONF_CHANNEL]}"}

Vrncanac marked this conversation as resolved.
Show resolved Hide resolved

class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
Vrncanac marked this conversation as resolved.
Show resolved Hide resolved
"""Handle a config flow for Axion Lighting."""

VERSION = 1

async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Handle the initial step."""
errors: dict[str, str] = {}
if user_input is not None:
try:
info = await validate_input(self.hass, user_input)
except CannotConnect:
errors["base"] = "cannot_connect"
except InvalidAuth:
errors["base"] = "invalid_auth"
Vrncanac marked this conversation as resolved.
Show resolved Hide resolved
except Exception as e: # noqa: BLE001
_LOGGER.exception("Unexpected exception: %s", e)
errors["base"] = "unknown"
else:
return self.async_create_entry(title=info["title"], data=user_input)

return self.async_show_form(
step_id="user", data_schema=STEP_USER_DATA_SCHEMA, errors=errors
)


class CannotConnect(HomeAssistantError):
"""Error to indicate we cannot connect."""


class InvalidAuth(HomeAssistantError):
"""Error to indicate there is invalid auth."""
9 changes: 9 additions & 0 deletions homeassistant/components/axion_dmx/const.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""Constants for the Axion Lighting integration."""

import logging

_LOGGER = logging.getLogger(__name__)

DOMAIN = "axion_dmx"
CONF_CHANNEL = "channel"
CONF_LIGHT_TYPE = "light_type"
Loading