Coding
PromptBeginner5 minmarkdown
Markdown Converter
Agent skill for markdown-converter
21
NOTE: The canonical source for these instructions is .cursorrules in the repo root.
Sign in to like and favorite skills
NOTE: The canonical source for these instructions is .cursorrules in the repo root. Any changes should be made there; this file syncs automatically via pre-commit hook.
X | None in type annotations; prefer union syntax in isinstance() checks (e.g., int | str) over tuples.X | None instead of Optional[X]hass: HomeAssistant, caplog: pytest.LogCaptureFixture-> None, -> str, -> dict[str, Any]# SPDX-License-Identifier: Apache-2.0, followed by the Apache block lines)..md extension (e.g., README.md).async_* methods); avoid blocking I/O in the event loop.
class FanSyncRuntimeData(TypedDict): client: FanSyncClient coordinator: FanSyncCoordinator type FanSyncConfigEntry = ConfigEntry[FanSyncRuntimeData] async def async_setup_entry(hass, entry: FanSyncConfigEntry) -> bool: client = entry.runtime_data.client # Full IDE autocomplete ✅
should_poll = False when using coordinator (inherited from CoordinatorEntity)__slots__ for memory efficiency in high-entity-count scenarios (optional)httpx.Client at custom_components.fansync.client.*websockets.connect at custom_components.fansync.client.websockets.connect with new_callable=AsyncMock_recv_task (async WebSocket receiver) and closes connections.hass: HomeAssistant, caplog: pytest.LogCaptureFixture-> None to async test functions-F -, or a file
with -F <file>. Do NOT rely on multiple -m flags; ensure a blank line
between subject and body to preserve formatting. Example:
git commit --amend -F - <<'EOF' feat: add optimistic updates - Apply overlay immediately and guard for 8s - Reconcile on push ack; revert only on explicit failure EOF
if _LOGGER.isEnabledFor(logging.DEBUG): for expensive operationsTimeoutError (not asyncio.TimeoutError) per Python 3.11+ and Ruff UP041
asyncio.TimeoutError is an alias to builtin TimeoutError in Python 3.11+except TimeoutError: to catch timeouts from asyncio.wait_for()ConfigEntryNotReady for transient setup failures so HA retries with backofftry: response = await api.get(); data = response["temp"] / 10; ...try: response = await api.get(); except ApiError as err: ...; data = response["temp"] / 10raise instead of raise exc when re-raising exceptions to preserve tracebacks.if _LOGGER.isEnabledFor(logging.DEBUG):.asyncio.Task for background operations (_recv_task for WebSocket receiver)websockets.connect(), ws.send(), ws.recv()asyncio.wait_for() with built-in TimeoutErrorhass.async_add_executor_job only if calling truly synchronous/blocking third-party codetime.sleep() - use await asyncio.sleep() insteadself._recv_task: asyncio.Task | None = Noneasyncio.create_task() or hass.async_create_task()task.cancel() and optionally await task to collect CancelledErrorTimeoutError for asyncio.wait_for() timeouts (not asyncio.TimeoutError)OSError for network errors (replaces old WebSocketConnectionClosedException)asyncio.CancelledError for handling cancelled tasksasync with for resources that support it (e.g., async with websockets.connect() as ws)AsyncMock from unittest.mockwebsockets.connect with patch(..., new_callable=AsyncMock)send, recv, close) as AsyncMock objectsasyncio.sleep(0.1) in tests to allow background tasks to process messagesThese patterns violate HA best practices and should never appear in FanSync code:
_attr_translation_key = "fan" not _attr_name = "Fan"entry.runtime_data not hass.data[DOMAIN][entry.entry_id]except (ValueError, KeyError): not except Exception:await asyncio.sleep() not time.sleep()async_redact_data() for api_key, password, tokenIMPORTANT: Run through this checklist before every commit to catch issues early and reduce review cycles. Items below capture common issues found in code reviews.
make check in the venv)make check in the venv)make check in the venv)When running quality checks in the Cursor sandbox environment, use the venv and run:
source venv/bin/activate make check