mirror of
https://github.com/home-assistant/core.git
synced 2025-08-04 13:15:18 +02:00
Get hostname id from get_settings
This commit is contained in:
@@ -12,6 +12,7 @@ from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
|
||||
from .const import DOMAIN
|
||||
from .helper import get_hostname_id
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@@ -32,9 +33,10 @@ async def test_connection(hass: HomeAssistant, data) -> str:
|
||||
session = async_get_clientsession(hass)
|
||||
async with ApiClient(session, data["host"]) as client:
|
||||
await client.login(data["password"])
|
||||
values = await client.get_setting_values("scb:network", "Hostname")
|
||||
hostname_id = await get_hostname_id(client)
|
||||
values = await client.get_setting_values("scb:network", hostname_id)
|
||||
|
||||
return values["scb:network"]["Hostname"]
|
||||
return values["scb:network"][hostname_id]
|
||||
|
||||
|
||||
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
|
@@ -23,6 +23,7 @@ from .const import DOMAIN
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
_DataT = TypeVar("_DataT")
|
||||
KNOWN_HOSTNAME_IDS = ("Network:Hostname", "Hostname")
|
||||
|
||||
|
||||
class Plenticore:
|
||||
@@ -69,6 +70,7 @@ class Plenticore:
|
||||
)
|
||||
|
||||
# get some device meta data
|
||||
hostname_id = await get_hostname_id(self._client)
|
||||
settings = await self._client.get_setting_values(
|
||||
{
|
||||
"devices:local": [
|
||||
@@ -78,7 +80,7 @@ class Plenticore:
|
||||
"Properties:VersionIOC",
|
||||
"Properties:VersionMC",
|
||||
],
|
||||
"scb:network": ["Hostname"],
|
||||
"scb:network": [hostname_id],
|
||||
}
|
||||
)
|
||||
|
||||
@@ -91,7 +93,7 @@ class Plenticore:
|
||||
identifiers={(DOMAIN, device_local["Properties:SerialNo"])},
|
||||
manufacturer="Kostal",
|
||||
model=f"{prod1} {prod2}",
|
||||
name=settings["scb:network"]["Hostname"],
|
||||
name=settings["scb:network"][hostname_id],
|
||||
sw_version=f'IOC: {device_local["Properties:VersionIOC"]}'
|
||||
+ f' MC: {device_local["Properties:VersionMC"]}',
|
||||
)
|
||||
@@ -403,3 +405,12 @@ class PlenticoreDataFormatter:
|
||||
return state
|
||||
|
||||
return PlenticoreDataFormatter.EM_STATES.get(value)
|
||||
|
||||
|
||||
async def get_hostname_id(client: ApiClient) -> str:
|
||||
"""Check for known existing hostname ids."""
|
||||
all_settings = await client.get_settings()
|
||||
for entry in all_settings["scb:network"]:
|
||||
if entry.id in KNOWN_HOSTNAME_IDS:
|
||||
return entry.id
|
||||
raise ApiException("Hostname identifier not found in KNOWN_HOSTNAME_IDS")
|
||||
|
Reference in New Issue
Block a user