diff --git a/homeassistant/components/modbus/__init__.py b/homeassistant/components/modbus/__init__.py index dc53b849861..cfe0aa370fe 100644 --- a/homeassistant/components/modbus/__init__.py +++ b/homeassistant/components/modbus/__init__.py @@ -42,6 +42,7 @@ from homeassistant.const import ( CONF_TEMPERATURE_UNIT, CONF_TIMEOUT, CONF_TYPE, + CONF_UNIQUE_ID, CONF_UNIT_OF_MEASUREMENT, ) from homeassistant.core import HomeAssistant @@ -122,6 +123,7 @@ BASE_COMPONENT_SCHEMA = vol.Schema( CONF_SCAN_INTERVAL, default=DEFAULT_SCAN_INTERVAL ): cv.positive_int, vol.Optional(CONF_LAZY_ERROR, default=0): cv.positive_int, + vol.Optional(CONF_UNIQUE_ID): cv.string, } ) diff --git a/homeassistant/components/modbus/base_platform.py b/homeassistant/components/modbus/base_platform.py index 682b3430807..615e86ae920 100644 --- a/homeassistant/components/modbus/base_platform.py +++ b/homeassistant/components/modbus/base_platform.py @@ -20,6 +20,7 @@ from homeassistant.const import ( CONF_SCAN_INTERVAL, CONF_SLAVE, CONF_STRUCTURE, + CONF_UNIQUE_ID, STATE_ON, ) from homeassistant.core import callback @@ -82,6 +83,7 @@ class BasePlatform(Entity): self._cancel_timer: Callable[[], None] | None = None self._cancel_call: Callable[[], None] | None = None + self._attr_unique_id = entry.get(CONF_UNIQUE_ID) self._attr_name = entry[CONF_NAME] self._attr_should_poll = False self._attr_device_class = entry.get(CONF_DEVICE_CLASS)