Skip to content

Commit

Permalink
Update __init__.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Xerolux authored Sep 23, 2024
1 parent 3223e68 commit 085759a
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions custom_components/violet_pool_controller/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
"""Violet Device Integration."""
import logging
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers import aiohttp_client
from homeassistant.helpers import device_registry as dr

from .const import DOMAIN, CONF_API_URL
from .const import DOMAIN, CONF_API_URL, CONF_DEVICE_NAME # Import CONF_DEVICE_NAME

_LOGGER = logging.getLogger(__name__)

Expand All @@ -19,6 +18,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
# Get the shared aiohttp session
session = aiohttp_client.async_get_clientsession(hass)

# Get the custom device name or default to 'Violet Pool Controller'
device_name = entry.data.get(CONF_DEVICE_NAME, "Violet Pool Controller")

try:
# Fetch data from the API, including firmware version
async with session.get(api_url, ssl=False) as response:
Expand All @@ -34,13 +36,13 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
config_entry_id=entry.entry_id,
identifiers={(DOMAIN, "violet_pool_controller")},
manufacturer="PoolDigital GmbH & Co. KG",
name="Violet Pool Controller",
name=device_name, # Use custom device name
model="Violet Model X",
sw_version=firmware_version,
configuration_url=f"http://{ip_address}", # Store the IP address in the configuration URL
)

_LOGGER.info("Device registered successfully.")
_LOGGER.info("Device '%s' registered successfully.", device_name)

except Exception as err:
_LOGGER.error("Failed to register device: %s", err)
Expand Down

0 comments on commit 085759a

Please sign in to comment.