-
Notifications
You must be signed in to change notification settings - Fork 0
Developer Guide
The integration follows a straightforward data flow:
const.py → model.py → sensor.py → Lovelace cards
-
const.pycentralizes domain names, storage keys, service constants, and shared attribute names. -
model.pyholds the cycle calculation logic and normalized model generation. -
sensor.pyexposes Home Assistant sensor state and attributes for dashboards and automations. -
__init__.pywires the integration together, registers services, serves frontend resources, and handles setup/teardown. -
www/*.jsrenders the frontend cards based on the sensor attributes.
| Path | Purpose |
|---|---|
custom_components/menstruation_cycle/__init__.py |
Integration setup, service registration, resource registration |
custom_components/menstruation_cycle/config_flow.py |
UI-based setup flow |
custom_components/menstruation_cycle/const.py |
Shared constants and public contract keys |
custom_components/menstruation_cycle/model.py |
Domain logic for cycle calculations |
custom_components/menstruation_cycle/sensor.py |
Sensor entity implementation |
custom_components/menstruation_cycle/storage.py |
Persistent storage and normalization |
custom_components/menstruation_cycle/services.yaml |
Service descriptions for Home Assistant UI |
custom_components/menstruation_cycle/statistics.py |
Analytics helpers and doctor-report generation |
custom_components/menstruation_cycle/www/*.js |
Lovelace custom cards and shared assets |
tests/*.js, tests/*.py
|
Lightweight frontend and backend regression tests |
DOMAIN = "menstruation_cycle" is the integration namespace used for:
- config-entry storage in
hass.data - service names such as
menstruation_cycle.refresh_cycle_model - HTTP paths like
/menstruation_cycle/... - dispatcher signals and resource registration keys
STORAGE_KEY = "menstruation_cycle.history" is used by storage.py for persisted profile data. Stored blocks include:
historyperiod_duration_dayssymptom_historyproduct_usagepregnancy_datamenarche_datapre_menarche_datamenopause_datanoncycle_datacycle_length_override
STORAGE_KEY_LEGACY = "menstruation_gauge.history" allows migration from the older domain naming. MenstruationStorage.async_load() checks the current store first, then the legacy store.
__init__.py registers the domain services. Service definitions live in services.yaml, but the actual behavior and validation live in Python.
__init__.py builds versioned resource URLs from manifest.json and registers the JS bundles as Lovelace module resources. This keeps HACS installs easier and reduces manual resource setup.
-
manifest.jsonis required so Home Assistant can load the integration at all. -
hacs.jsonmakes the repository discoverable and correctly classified in HACS. -
__init__.py,sensor.py, andconfig_flow.pyseparate setup, entity exposure, and UI configuration. -
storage.pykeeps history and related data persistent across restarts. -
model.pyisolates domain calculations from Home Assistant-specific code. -
www/*.jscontains the Lovelace resources served under/menstruation_cycle/.... -
services.yamldocuments backend services in the Home Assistant service UI.
- Keep changes focused and small.
- Preserve backward compatibility where practical, especially for legacy card names and stored data.
- Update README or wiki pages when user-facing behavior changes.
- Prefer extending existing patterns instead of introducing parallel implementations.
- Follow existing Python and JavaScript style in nearby files.
- Reuse constants from
const.pyinstead of repeating raw strings. - Keep UI labels and service names aligned with translations and
services.yaml. - Avoid changing unrelated formatting while working on a narrow fix.
- Add the new JS file under
custom_components/menstruation_cycle/www/. - Register the custom element and
window.customCardsmetadata. - Add the resource to the Lovelace resource tuple in
__init__.py. - Add or update tests in
/testsfor rendering or config behavior. - Document the card in
Cards-Documentation.md.
- Define the service constant in
const.py. - Add the service schema and handler in
__init__.py. - Document it in
services.yamlso it appears correctly in Home Assistant UI. - Add backend tests when the logic is non-trivial.
- Add usage docs in
Services-&-Automations.md.
Current tests are lightweight and close to the changed surface:
- JavaScript card tests can be run directly with
node tests/<file>.test.js - Backend behavior is covered by targeted Python tests in
/tests - For docs-only changes, validate markdown structure, links, and affected examples manually
- Forgetting to register a new frontend resource in
__init__.py - Breaking compatibility with the older
menstruation_gaugenaming where migration support still matters - Updating frontend config options without updating editor UI or docs
- Assuming cache refresh is enough when a backend restart is required
- Adding new service behavior without reflecting it in
services.yaml
- richer symptom overlays in the heatmap
- more clinical export/reporting options
- broader household planning workflows
- additional frontend editors and visualizations
- expanded regression coverage for newer service areas