mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 17:57:11 +00:00
Fix yeelight name changing to ip address if discovery fails (#60967)
This commit is contained in:
parent
b8071c688b
commit
10e669e69e
@ -244,7 +244,7 @@ async def _async_get_device(
|
|||||||
# Set up device
|
# Set up device
|
||||||
bulb = AsyncBulb(host, model=model or None)
|
bulb = AsyncBulb(host, model=model or None)
|
||||||
|
|
||||||
device = YeelightDevice(hass, host, entry.options, bulb)
|
device = YeelightDevice(hass, host, {**entry.options, **entry.data}, bulb)
|
||||||
# start listening for local pushes
|
# start listening for local pushes
|
||||||
await device.bulb.async_listen(device.async_update_callback)
|
await device.bulb.async_listen(device.async_update_callback)
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ import logging
|
|||||||
from yeelight import BulbException
|
from yeelight import BulbException
|
||||||
from yeelight.aio import KEY_CONNECTED
|
from yeelight.aio import KEY_CONNECTED
|
||||||
|
|
||||||
from homeassistant.const import CONF_NAME
|
from homeassistant.const import CONF_ID, CONF_NAME
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||||
from homeassistant.helpers.event import async_call_later
|
from homeassistant.helpers.event import async_call_later
|
||||||
@ -199,6 +199,8 @@ class YeelightDevice:
|
|||||||
elif self.capabilities:
|
elif self.capabilities:
|
||||||
# Generate name from model and id when capabilities is available
|
# Generate name from model and id when capabilities is available
|
||||||
self._name = _async_unique_name(self.capabilities)
|
self._name = _async_unique_name(self.capabilities)
|
||||||
|
elif self.model and (id_ := self._config.get(CONF_ID)):
|
||||||
|
self._name = f"Yeelight {async_format_model_id(self.model, id_)}"
|
||||||
else:
|
else:
|
||||||
self._name = self._host # Default name is host
|
self._name = self._host # Default name is host
|
||||||
|
|
||||||
|
@ -588,3 +588,25 @@ async def test_non_oserror_exception_on_first_update(
|
|||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert hass.states.get("light.test_name").state != STATE_UNAVAILABLE
|
assert hass.states.get("light.test_name").state != STATE_UNAVAILABLE
|
||||||
|
|
||||||
|
|
||||||
|
async def test_async_setup_with_discovery_not_working(hass: HomeAssistant):
|
||||||
|
"""Test we can setup even if discovery is broken."""
|
||||||
|
config_entry = MockConfigEntry(
|
||||||
|
domain=DOMAIN,
|
||||||
|
data={CONF_HOST: "127.0.0.1", CONF_ID: ID},
|
||||||
|
options={},
|
||||||
|
unique_id=ID,
|
||||||
|
)
|
||||||
|
config_entry.add_to_hass(hass)
|
||||||
|
|
||||||
|
with _patch_discovery(
|
||||||
|
no_device=True
|
||||||
|
), _patch_discovery_timeout(), _patch_discovery_interval(), patch(
|
||||||
|
f"{MODULE}.AsyncBulb", return_value=_mocked_bulb()
|
||||||
|
):
|
||||||
|
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert config_entry.state is ConfigEntryState.LOADED
|
||||||
|
|
||||||
|
assert hass.states.get("light.yeelight_color_0x15243f").state == STATE_ON
|
||||||
|
Loading…
x
Reference in New Issue
Block a user