diff --git a/custom_components/bangolufsen/config_flow.py b/custom_components/bangolufsen/config_flow.py index db30005..8926d16 100644 --- a/custom_components/bangolufsen/config_flow.py +++ b/custom_components/bangolufsen/config_flow.py @@ -5,6 +5,7 @@ import logging from typing import Any, TypedDict +from inflection import underscore from mozart_api.exceptions import ApiException from mozart_api.mozart_client import MozartClient from urllib3.exceptions import MaxRetryError, NewConnectionError @@ -12,7 +13,7 @@ from homeassistant.components.zeroconf import ZeroconfServiceInfo from homeassistant.config_entries import ConfigEntry, ConfigFlow, OptionsFlow -from homeassistant.const import CONF_HOST, CONF_MODEL, CONF_NAME +from homeassistant.const import CONF_FRIENDLY_NAME, CONF_HOST, CONF_MODEL, CONF_NAME from homeassistant.core import callback from homeassistant.data_entry_flow import AbortFlow, FlowResult from homeassistant.helpers import config_validation as cv, selector @@ -114,6 +115,7 @@ class UserInput(TypedDict): """TypedDict for user_input.""" name: str + friendly_name: str volume_step: int default_volume: int max_volume: int @@ -186,15 +188,26 @@ async def async_step_zeroconf( async def async_step_confirm( self, user_input: UserInput | None = None ) -> FlowResult: - """Confirm the configuration of the discovered device.""" + """Confirm the configuration of the device.""" if user_input is not None: - # Make sure that information from the zeroconf discovery is included + # Get the desired friendly name before changing it for generating entity_id + self._name = user_input[CONF_NAME] + + # Make sure that all information is included data = user_input data[CONF_HOST] = self._host data[CONF_MODEL] = self._model data[CONF_BEOLINK_JID] = self._beolink_jid + data[CONF_FRIENDLY_NAME] = self._name - return self.async_create_entry(title=data[CONF_NAME], data=data) + # Manually define the entity_id + model_name = underscore(self._model.replace(" ", "_")) + data[CONF_NAME] = f"{model_name}_{self._serial_number}" + + return self.async_create_entry( + title=self._name, + data=data, + ) client = MozartClient(self._host) volume_settings = client.get_volume_settings(async_req=True).get() @@ -240,17 +253,17 @@ async def async_step_init(self, user_input: UserInput | None = None) -> FlowResu data[CONF_MODEL] = self._config_entry.data[CONF_MODEL] data[CONF_BEOLINK_JID] = self._config_entry.data[CONF_BEOLINK_JID] + data[CONF_FRIENDLY_NAME] = user_input[CONF_NAME] if not self.show_advanced_options: data[CONF_HOST] = self._config_entry.data[CONF_HOST] # Check connection await _validate_host(data[CONF_HOST]) - return self.async_create_entry(title=data[CONF_NAME], data=data) # Create data schema with the last configuration as default values. data_schema = _config_schema( - name=self._config_entry.data[CONF_NAME], + name=self._config_entry.data[CONF_FRIENDLY_NAME], volume_step=self._config_entry.data[CONF_VOLUME_STEP], default_volume=self._config_entry.data[CONF_DEFAULT_VOLUME], max_volume=self._config_entry.data[CONF_MAX_VOLUME], diff --git a/custom_components/bangolufsen/manifest.json b/custom_components/bangolufsen/manifest.json index afcabb8..ba7d5c1 100644 --- a/custom_components/bangolufsen/manifest.json +++ b/custom_components/bangolufsen/manifest.json @@ -5,7 +5,7 @@ "issue_tracker": "https://github.com/bang-olufsen/bangolufsen-hacs/issues", "requirements": ["mozart-api==2.3.4.15123.6"], "zeroconf": ["_bangolufsen._tcp.local."], - "version": "0.5.2", + "version": "0.5.3", "codeowners": ["@mj23000"], "iot_class": "local_push", "config_flow": true