一键导入
hsem-canonical-helpers
Activate at the start of any code change to ensure canonical helpers and patterns are used instead of re-implementing them inline.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Activate at the start of any code change to ensure canonical helpers and patterns are used instead of re-implementing them inline.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Activate before every commit and PR to run the full HSEM quality gate pipeline — lint, typing, quality checks, and tests.
Activate after every code change to verify all documentation files that describe the changed behaviour are updated and consistent with the implementation.
Activate when making changes that touch Home Assistant integration surfaces — config flows, entities, translations, services, device info, async patterns, or platform setup.
Activate when writing or reviewing Home Assistant integration code to ensure Bronze and Silver quality tier standards — HA constants, entity patterns, coordinator usage, config flow, and async correctness.
Activate when adding, modifying, or using any Huawei Solar inverter/battery sensor entity in HSEM. Follow the full wiring protocol from const.py through coordinator.py.
Activate when making any change to the HSEM planner layer — engine, cost function, SoC simulation, candidate generation, slot population, MILP optimizer, or safety gates.
| name | hsem-canonical-helpers |
| description | Activate at the start of any code change to ensure canonical helpers and patterns are used instead of re-implementing them inline. |
Activate this skill when writing any code that may need efficiency conversion, discharge recommendations, threshold calculation, or logging. These helpers exist for a reason — never re-implement them inline.
clamp_efficiency(pct)Location: custom_components/hsem/utils/misc.py
from custom_components.hsem.utils.misc import clamp_efficiency
charge_eff = clamp_efficiency(charge_efficiency_pct) # returns fraction 0.01-1.0
Never inline max(min(..., 100.0), 1.0) / 100.0.
DISCHARGE_RECS, CHARGE_RECSLocation: custom_components/hsem/utils/recommendations.py
from custom_components.hsem.utils.recommendations import DISCHARGE_RECS, CHARGE_RECS
if slot.recommendation in DISCHARGE_RECS:
...
These are canonical frozensets. Never redefine them locally.
calculate_recommended_threshold(...)Location: custom_components/hsem/utils/misc.py
from custom_components.hsem.utils.misc import calculate_recommended_threshold
threshold = calculate_recommended_threshold(
purchase_price=purchase_price,
cycle_cost_per_kwh=cycle_cost_per_kwh,
charge_efficiency_pct=charge_efficiency_pct,
discharge_efficiency_pct=discharge_efficiency_pct,
capacity_loss_pct=capacity_loss_pct,
grid_fee=grid_fee,
)
Never use cycle_cost * 0.30 as a proxy for the discharge threshold.
HSEM_LOGGERLocation: custom_components/hsem/utils/logger.py
from custom_components.hsem.utils.logger import HSEM_LOGGER
Use for ALL planner code. Never use logging.getLogger(__name__) in planner files.
When creating log statements, never use runtime string formatting — use % placeholders and the extra argument:
HSEM_LOGGER.debug("Processing slot %d with price %.4f", slot_index, price)
Location: custom_components/hsem/utils/sensornames.py
All HA entity name constants live here. Never hardcode sensor names elsewhere.
# Production code — epsilon guard (NEVER == or !=)
if abs(value) > 1e-9: # instead of: if value != 0
if abs(a - b) < 1e-9: # instead of: if a == b
# Test code — pytest.approx()
assert result == pytest.approx(expected, rel=1e-6)
| Layer | Location | Key files |
|---|---|---|
| Planner | custom_components/hsem/planner/ | engine.py, cost_function.py, soc_simulation.py, candidate_generator.py, candidate_selector.py, slot_population.py, charge_scheduler.py, discharge_scheduler.py, milp_optimizer.py, ev_planner.py |
| ML | custom_components/hsem/ml/ | consumption_predictor.py, history_reader.py, populator.py |
| Utils | custom_components/hsem/utils/ | recommendations.py, misc.py, sensornames.py, prices.py, huawei.py, logger.py, solar_corrector.py, dynamic_floor.py, capacity_learner.py, charge_rate_learner.py, prediction_tracker.py, weekday_profile.py, ev_mode_resolver.py |
If a utility function is used in 2+ modules, it belongs in utils/. Before writing any utility:
utils/misc.py and other utils/*.py modules for existing implementations_function_name()), but refactor to utils if needs growThe MILP in milp_optimizer.py uses 8*n LP variables for battery-only. With EV co-optimisation, it grows to 8n + 2n·E + E where E is the number of active EVs.
Always uses the mandatory 2x denominator. Never change this without updating the spec and all affected tests.
Hard limit: 30 KB per file in planner/ and utils/. Check: wc -c custom_components/hsem/planner/*.py