mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Deduplicate flux_led title and CONF_NAME (#66598)
This commit is contained in:
parent
734fdf7bff
commit
d64ef2ba73
@ -63,7 +63,7 @@ class FluxButton(FluxBaseEntity, ButtonEntity):
|
||||
"""Initialize the button."""
|
||||
self.entity_description = description
|
||||
super().__init__(device, entry)
|
||||
self._attr_name = f"{entry.data[CONF_NAME]} {description.name}"
|
||||
self._attr_name = f"{entry.data.get(CONF_NAME, entry.title)} {description.name}"
|
||||
base_unique_id = entry.unique_id or entry.entry_id
|
||||
self._attr_unique_id = f"{base_unique_id}_{description.key}"
|
||||
|
||||
|
@ -17,7 +17,7 @@ import voluptuous as vol
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components import dhcp
|
||||
from homeassistant.const import CONF_HOST, CONF_NAME
|
||||
from homeassistant.const import CONF_HOST
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.data_entry_flow import FlowResult
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
@ -145,10 +145,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
"""Create a config entry from a device."""
|
||||
self._async_abort_entries_match({CONF_HOST: device[ATTR_IPADDR]})
|
||||
name = async_name_from_discovery(device)
|
||||
data: dict[str, Any] = {
|
||||
CONF_HOST: device[ATTR_IPADDR],
|
||||
CONF_NAME: name,
|
||||
}
|
||||
data: dict[str, Any] = {CONF_HOST: device[ATTR_IPADDR]}
|
||||
async_populate_data_from_discovery(data, data, device)
|
||||
return self.async_create_entry(
|
||||
title=name,
|
||||
|
@ -125,10 +125,13 @@ def async_update_entry_from_discovery(
|
||||
if model_num and entry.data.get(CONF_MODEL_NUM) != model_num:
|
||||
data_updates[CONF_MODEL_NUM] = model_num
|
||||
async_populate_data_from_discovery(entry.data, data_updates, device)
|
||||
if not entry.data.get(CONF_NAME) or is_ip_address(entry.data[CONF_NAME]):
|
||||
updates["title"] = data_updates[CONF_NAME] = async_name_from_discovery(device)
|
||||
if data_updates:
|
||||
if is_ip_address(entry.title):
|
||||
updates["title"] = async_name_from_discovery(device)
|
||||
title_matches_name = entry.title == entry.data.get(CONF_NAME)
|
||||
if data_updates or title_matches_name:
|
||||
updates["data"] = {**entry.data, **data_updates}
|
||||
if title_matches_name:
|
||||
del updates["data"][CONF_NAME]
|
||||
if updates:
|
||||
return hass.config_entries.async_update_entry(entry, **updates)
|
||||
return False
|
||||
|
@ -40,7 +40,7 @@ def _async_device_info(
|
||||
ATTR_IDENTIFIERS: {(DOMAIN, entry.entry_id)},
|
||||
ATTR_MANUFACTURER: "Zengge",
|
||||
ATTR_MODEL: device.model,
|
||||
ATTR_NAME: entry.data[CONF_NAME],
|
||||
ATTR_NAME: entry.data.get(CONF_NAME, entry.title),
|
||||
ATTR_SW_VERSION: sw_version_str,
|
||||
}
|
||||
if hw_model := entry.data.get(CONF_MODEL):
|
||||
|
@ -178,7 +178,7 @@ async def async_setup_entry(
|
||||
FluxLight(
|
||||
coordinator,
|
||||
entry.unique_id or entry.entry_id,
|
||||
entry.data[CONF_NAME],
|
||||
entry.data.get(CONF_NAME, entry.title),
|
||||
list(custom_effect_colors),
|
||||
options.get(CONF_CUSTOM_EFFECT_SPEED_PCT, DEFAULT_EFFECT_SPEED),
|
||||
options.get(CONF_CUSTOM_EFFECT_TRANSITION, TRANSITION_GRADUAL),
|
||||
|
@ -50,7 +50,7 @@ async def async_setup_entry(
|
||||
| FluxMusicPixelsPerSegmentNumber
|
||||
| FluxMusicSegmentsNumber
|
||||
] = []
|
||||
name = entry.data[CONF_NAME]
|
||||
name = entry.data.get(CONF_NAME, entry.title)
|
||||
base_unique_id = entry.unique_id or entry.entry_id
|
||||
|
||||
if device.pixels_per_segment is not None:
|
||||
|
@ -53,7 +53,7 @@ async def async_setup_entry(
|
||||
| FluxRemoteConfigSelect
|
||||
| FluxWhiteChannelSelect
|
||||
] = []
|
||||
name = entry.data[CONF_NAME]
|
||||
name = entry.data.get(CONF_NAME, entry.title)
|
||||
base_unique_id = entry.unique_id or entry.entry_id
|
||||
|
||||
if device.device_type == DeviceType.Switch:
|
||||
|
@ -26,7 +26,7 @@ async def async_setup_entry(
|
||||
FluxPairedRemotes(
|
||||
coordinator,
|
||||
entry.unique_id or entry.entry_id,
|
||||
f"{entry.data[CONF_NAME]} Paired Remotes",
|
||||
f"{entry.data.get(CONF_NAME, entry.title)} Paired Remotes",
|
||||
"paired_remotes",
|
||||
)
|
||||
]
|
||||
|
@ -35,7 +35,7 @@ async def async_setup_entry(
|
||||
coordinator: FluxLedUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
||||
entities: list[FluxSwitch | FluxRemoteAccessSwitch | FluxMusicSwitch] = []
|
||||
base_unique_id = entry.unique_id or entry.entry_id
|
||||
name = entry.data[CONF_NAME]
|
||||
name = entry.data.get(CONF_NAME, entry.title)
|
||||
|
||||
if coordinator.device.device_type == DeviceType.Switch:
|
||||
entities.append(FluxSwitch(coordinator, base_unique_id, name, None))
|
||||
@ -73,7 +73,7 @@ class FluxRemoteAccessSwitch(FluxBaseEntity, SwitchEntity):
|
||||
) -> None:
|
||||
"""Initialize the light."""
|
||||
super().__init__(device, entry)
|
||||
self._attr_name = f"{entry.data[CONF_NAME]} Remote Access"
|
||||
self._attr_name = f"{entry.data.get(CONF_NAME, entry.title)} Remote Access"
|
||||
base_unique_id = entry.unique_id or entry.entry_id
|
||||
self._attr_unique_id = f"{base_unique_id}_remote_access"
|
||||
|
||||
|
@ -23,7 +23,7 @@ from homeassistant.components.flux_led.const import (
|
||||
TRANSITION_JUMP,
|
||||
TRANSITION_STROBE,
|
||||
)
|
||||
from homeassistant.const import CONF_DEVICE, CONF_HOST, CONF_NAME
|
||||
from homeassistant.const import CONF_DEVICE, CONF_HOST
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import RESULT_TYPE_ABORT, RESULT_TYPE_FORM
|
||||
|
||||
@ -94,7 +94,6 @@ async def test_discovery(hass: HomeAssistant):
|
||||
assert result3["data"] == {
|
||||
CONF_MINOR_VERSION: 4,
|
||||
CONF_HOST: IP_ADDRESS,
|
||||
CONF_NAME: DEFAULT_ENTRY_TITLE,
|
||||
CONF_MODEL: MODEL,
|
||||
CONF_MODEL_NUM: MODEL_NUM,
|
||||
CONF_MODEL_INFO: MODEL,
|
||||
@ -170,7 +169,6 @@ async def test_discovery_legacy(hass: HomeAssistant):
|
||||
assert result3["data"] == {
|
||||
CONF_MINOR_VERSION: 4,
|
||||
CONF_HOST: IP_ADDRESS,
|
||||
CONF_NAME: DEFAULT_ENTRY_TITLE,
|
||||
CONF_MODEL: MODEL,
|
||||
CONF_MODEL_NUM: MODEL_NUM,
|
||||
CONF_MODEL_INFO: MODEL,
|
||||
@ -253,7 +251,6 @@ async def test_discovery_with_existing_device_present(hass: HomeAssistant):
|
||||
assert result3["data"] == {
|
||||
CONF_MINOR_VERSION: 4,
|
||||
CONF_HOST: IP_ADDRESS,
|
||||
CONF_NAME: DEFAULT_ENTRY_TITLE,
|
||||
CONF_MODEL: MODEL,
|
||||
CONF_MODEL_NUM: MODEL_NUM,
|
||||
CONF_MODEL_INFO: MODEL,
|
||||
@ -330,7 +327,6 @@ async def test_manual_working_discovery(hass: HomeAssistant):
|
||||
assert result4["data"] == {
|
||||
CONF_MINOR_VERSION: 4,
|
||||
CONF_HOST: IP_ADDRESS,
|
||||
CONF_NAME: DEFAULT_ENTRY_TITLE,
|
||||
CONF_MODEL: MODEL,
|
||||
CONF_MODEL_NUM: MODEL_NUM,
|
||||
CONF_MODEL_INFO: MODEL,
|
||||
@ -377,7 +373,6 @@ async def test_manual_no_discovery_data(hass: HomeAssistant):
|
||||
CONF_HOST: IP_ADDRESS,
|
||||
CONF_MODEL_NUM: MODEL_NUM,
|
||||
CONF_MODEL_DESCRIPTION: MODEL_DESCRIPTION,
|
||||
CONF_NAME: IP_ADDRESS,
|
||||
}
|
||||
|
||||
|
||||
@ -445,7 +440,6 @@ async def test_discovered_by_discovery(hass):
|
||||
assert result2["data"] == {
|
||||
CONF_MINOR_VERSION: 4,
|
||||
CONF_HOST: IP_ADDRESS,
|
||||
CONF_NAME: DEFAULT_ENTRY_TITLE,
|
||||
CONF_MODEL: MODEL,
|
||||
CONF_MODEL_NUM: MODEL_NUM,
|
||||
CONF_MODEL_INFO: MODEL,
|
||||
@ -483,7 +477,6 @@ async def test_discovered_by_dhcp_udp_responds(hass):
|
||||
assert result2["data"] == {
|
||||
CONF_MINOR_VERSION: 4,
|
||||
CONF_HOST: IP_ADDRESS,
|
||||
CONF_NAME: DEFAULT_ENTRY_TITLE,
|
||||
CONF_MODEL: MODEL,
|
||||
CONF_MODEL_NUM: MODEL_NUM,
|
||||
CONF_MODEL_INFO: MODEL,
|
||||
@ -522,7 +515,6 @@ async def test_discovered_by_dhcp_no_udp_response(hass):
|
||||
CONF_HOST: IP_ADDRESS,
|
||||
CONF_MODEL_NUM: MODEL_NUM,
|
||||
CONF_MODEL_DESCRIPTION: MODEL_DESCRIPTION,
|
||||
CONF_NAME: DEFAULT_ENTRY_TITLE,
|
||||
}
|
||||
assert mock_async_setup.called
|
||||
assert mock_async_setup_entry.called
|
||||
@ -553,7 +545,6 @@ async def test_discovered_by_dhcp_partial_udp_response_fallback_tcp(hass):
|
||||
CONF_HOST: IP_ADDRESS,
|
||||
CONF_MODEL_NUM: MODEL_NUM,
|
||||
CONF_MODEL_DESCRIPTION: MODEL_DESCRIPTION,
|
||||
CONF_NAME: DEFAULT_ENTRY_TITLE,
|
||||
}
|
||||
assert mock_async_setup.called
|
||||
assert mock_async_setup_entry.called
|
||||
@ -630,7 +621,8 @@ async def test_options(hass: HomeAssistant):
|
||||
"""Test options flow."""
|
||||
config_entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data={CONF_HOST: IP_ADDRESS, CONF_NAME: DEFAULT_ENTRY_TITLE},
|
||||
data={CONF_HOST: IP_ADDRESS},
|
||||
title=IP_ADDRESS,
|
||||
options={
|
||||
CONF_CUSTOM_EFFECT_COLORS: "[255,0,0], [0,0,255]",
|
||||
CONF_CUSTOM_EFFECT_SPEED_PCT: 30,
|
||||
|
@ -117,7 +117,7 @@ async def test_config_entry_fills_unique_id_with_directed_discovery(
|
||||
) -> None:
|
||||
"""Test that the unique id is added if its missing via directed (not broadcast) discovery."""
|
||||
config_entry = MockConfigEntry(
|
||||
domain=DOMAIN, data={CONF_HOST: IP_ADDRESS}, unique_id=None
|
||||
domain=DOMAIN, data={CONF_HOST: IP_ADDRESS}, unique_id=None, title=IP_ADDRESS
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
last_address = None
|
||||
@ -144,7 +144,6 @@ async def test_config_entry_fills_unique_id_with_directed_discovery(
|
||||
assert config_entry.state == ConfigEntryState.LOADED
|
||||
|
||||
assert config_entry.unique_id == MAC_ADDRESS
|
||||
assert config_entry.data[CONF_NAME] == title
|
||||
assert config_entry.title == title
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user