diff --git a/homeassistant/components/yeelight/__init__.py b/homeassistant/components/yeelight/__init__.py index 79249ae8c44..d1b8e9d4f46 100644 --- a/homeassistant/components/yeelight/__init__.py +++ b/homeassistant/components/yeelight/__init__.py @@ -244,7 +244,7 @@ async def _async_get_device( # Set up device 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 await device.bulb.async_listen(device.async_update_callback) diff --git a/homeassistant/components/yeelight/device.py b/homeassistant/components/yeelight/device.py index 5f70866b229..02228e5d9fc 100644 --- a/homeassistant/components/yeelight/device.py +++ b/homeassistant/components/yeelight/device.py @@ -7,7 +7,7 @@ import logging from yeelight import BulbException 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.helpers.dispatcher import async_dispatcher_send from homeassistant.helpers.event import async_call_later @@ -199,6 +199,8 @@ class YeelightDevice: elif self.capabilities: # Generate name from model and id when capabilities is available 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: self._name = self._host # Default name is host diff --git a/tests/components/yeelight/test_init.py b/tests/components/yeelight/test_init.py index 13c71d656bb..dc3d602edeb 100644 --- a/tests/components/yeelight/test_init.py +++ b/tests/components/yeelight/test_init.py @@ -588,3 +588,25 @@ async def test_non_oserror_exception_on_first_update( await hass.async_block_till_done() 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