Development guidelines for building Home Assistant custom components with Python 3.13+, pytest testing, type safety, and pre-commit hooks. Focused on the ResMed myAir CPAP data integration.
Development skill for building and maintaining the Home Assistant custom component that integrates with ResMed's myAir service to pull daily CPAP data.
This skill guides development of a Home Assistant custom component following official Home Assistant developer standards, modern Python practices (3.13+), comprehensive pytest testing, and strict type safety.
**Integration purpose:** Pull daily CPAP data from ResMed's myAir service using an undocumented API and expose it as Home Assistant sensors.
**Folder structure:**
1. **Follow Home Assistant documentation:** All development must align with https://developers.home-assistant.io/docs/
2. **Explain as you code:** Provide clear, actionable explanations for what you're doing
3. **Incremental changes:** Focus on one conceptual change at a time, especially for public API or multi-module changes
4. **Maintain coding style:** Always preserve the project's existing code style and conventions
5. **Transparency on deviations:** When you cannot follow a guideline, explicitly state which rule is not being followed and why (e.g., missing permissions, conflicting instructions, safety policy)
**Type annotations:**
**Documentation:**
**Code organization:**
**Tooling:**
**Primary tools:** `pre-commit` and `pytest` (not tox)
Run code quality checks:
```bash
pre-commit run --all-files
```
Run full test suite (default):
```bash
pytest
```
Run targeted tests (only when explicitly requested):
```bash
pytest tests/test_specific_module.py
```
**Important:** Always run pytest and pre-commit in the repository venv (`./.venv`) unless user specifies otherwise.
**Fail-safe for missing dependencies:**
If test runs fail due to missing dev/test dependencies:
1. Attempt to install missing packages into `./.venv` if permitted, or
2. Report missing package(s) with exact `pip install` command and fail gracefully
- Use `MockConfigEntry` for config entries (provided by the plugin)
- Don't create custom utilities when plugin provides them
- Delete legacy placeholder tests when parameterizing
- Remove related placeholder comments
Example full run:
```bash
pytest
```
Example focused run (only when requested):
```bash
pytest tests/test_sensor.py::test_specific_case
```
The agent will only create branches or open pull requests when:
1. The user explicitly requests it, OR
2. The user includes the hashtag `#github-pull-request_copilot-coding-agent`
Before submitting changes:
When adding a new sensor entity:
1. Create sensor class in `custom_components/resmed_myair/sensor.py`
2. Add type hints and docstrings
3. Define constants in `const.py`
4. Create comprehensive test module `tests/test_sensor.py`
5. Use `MockConfigEntry` from pytest-homeassistant-custom-component
6. Parameterize similar test cases
7. Run `pre-commit run --all-files`
8. Run `pytest` and verify ≥80% coverage
9. Ensure all tests pass with no warnings
**Using MockConfigEntry:**
```python
from pytest_homeassistant_custom_component.common import MockConfigEntry
def test_sensor_setup(hass):
"""Test sensor platform setup."""
entry = MockConfigEntry(
domain="resmed_myair",
data={"username": "test", "password": "test"}
)
# ... rest of test
```
**Parameterized tests:**
```python
@pytest.mark.parametrize(
"input_value,expected_output",
[
(100, "100%"),
(0, "0%"),
(None, "Unknown"),
],
)
def test_format_percentage(input_value, expected_output):
"""Test percentage formatting with various inputs."""
assert format_percentage(input_value) == expected_output
```
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/home-assistant-resmed-myair-integration-development/raw