From 89f61e93ca27f7c3d91d4285d953c5b0b683b7dd Mon Sep 17 00:00:00 2001 From: Petr Hrdina Date: Tue, 10 Feb 2026 23:24:29 +0100 Subject: [PATCH] Allow reading unique_id from config --- README.md | 2 ++ custom_components/xiaomi_miio_philipslight/light.py | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c639eff..4937f46 100644 --- a/README.md +++ b/README.md @@ -106,6 +106,7 @@ light: host: 192.168.130.67 token: da548d86f55996413d82eea94279d2ff model: philips.light.bulb + unique_id: 12345 - platform: xiaomi_miio_philipslight name: Xiaomi Philips Smart LED Ceiling Lamp host: 192.168.130.68 @@ -123,6 +124,7 @@ Configuration variables: - **token** (*Required*): The API token of your light. - **name** (*Optional*): The name of your light. - **model** (*Optional*): The model of your light. Valid values are `philips.light.sread1`, `philips.light.ceiling`, `philips.light.zyceiling`, `philips.light.moonlight`, `philips.light.bulb`, `philips.light.candle`, `philips.light.candle2`, `philips.light.mono1` and `philips.light.downlight`. This setting can be used to bypass the device model detection and is recommended if your device isn't always available. +- **unique_id** (*Optional*): Unique ID of your device. It probably can be set to any reasonable value - such as serial number or mac address. Used to create device from entity in the UI. Without the ID one cannot do that. ## Debugging diff --git a/custom_components/xiaomi_miio_philipslight/light.py b/custom_components/xiaomi_miio_philipslight/light.py index 576d4ee..c6b3dca 100644 --- a/custom_components/xiaomi_miio_philipslight/light.py +++ b/custom_components/xiaomi_miio_philipslight/light.py @@ -17,7 +17,7 @@ ColorMode, LightEntity, ) -from homeassistant.const import ATTR_ENTITY_ID, CONF_HOST, CONF_NAME, CONF_TOKEN +from homeassistant.const import ATTR_ENTITY_ID, CONF_HOST, CONF_NAME, CONF_TOKEN, CONF_UNIQUE_ID from homeassistant.exceptions import PlatformNotReady from homeassistant.util import color, dt from miio import ( @@ -60,6 +60,7 @@ ] ), vol.Optional(CONF_AUTO_MIDNIGHT_MODE, default=True): cv.boolean, + vol.Optional(CONF_UNIQUE_ID): cv.string, } ) @@ -133,12 +134,12 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= token = config[CONF_TOKEN] name = config[CONF_NAME] model = config.get(CONF_MODEL) + unique_id = config[CONF_UNIQUE_ID] auto_midnight_mode = config.get(CONF_AUTO_MIDNIGHT_MODE) _LOGGER.info("Initializing with host %s (token %s...)", host, token[:5]) devices = [] - unique_id = None if model is None: try: