@@ -14,9 +14,6 @@ HA-Light-Controller is a Home Assistant custom integration providing reliable li
1414control with state verification, automatic retries, and preset management. It ensures
1515lights actually reach their target state after commands are sent. Distributed via HACS.
1616
17- ** Scope** : Focused on core light control with verification/retry and preset management.
18- Notification feature and blueprints removed in v0.2.0.
19-
2017## Environment
2118
2219- ** Python** : 3.14.2 (HA 2025.2+ requires Python 3.13+)
@@ -186,95 +183,23 @@ Tests mock HA modules before import. Key fixtures in `conftest.py`:
186183
187184### Live Testing with HA Dev Server
188185
189- A Docker-based HA instance lives at ` ~/ha-plugin-test-workspace/ ` for integration
190- testing against a real Home Assistant runtime.
191-
192- ** Setup:**
186+ A Podman-based HA instance at ` ~/ha-plugin-test-workspace/ ` enables runtime testing.
187+ Connection details and access token are stored in project memory.
193188
194189``` bash
195- # Start the dev server (HA on http://localhost:8123)
196- podman compose -f ~ /ha-plugin-test-workspace/docker-compose.yml up -d
197-
198- # Deploy current integration code to the dev server
190+ # Deploy and restart
199191cp -r custom_components/ha_light_controller/* \
200192 ~ /ha-plugin-test-workspace/ha-config/custom_components/ha_light_controller/
201-
202- # Restart HA to pick up changes
203193podman restart ha-plugin-test
204-
205- # Tail logs to verify loading
206- podman logs -f ha-plugin-test 2>&1 | grep ha_light_controller
207- ```
208-
209- ** Environment details:**
210-
211- - Runtime: Podman (rootless containers)
212- - Container: ` ha-plugin-test ` (image: ` ghcr.io/home-assistant/home-assistant:stable ` )
213- - Config dir: ` ~/ha-plugin-test-workspace/ha-config/ ` (mounted as ` /config ` )
214- - The ` demo ` integration provides test light entities (` light.ceiling_lights ` , etc.)
215- - REST API enabled on port 8123
216- - Debug logging enabled for ` custom_components.ha_light_controller `
217- - Login: ` admin ` / ` admin `
218- - Long-lived access token name: ` Claude Code Dev ` (value stored in project memory)
219-
220- ** Common verification commands:**
221-
222- ``` bash
223- # Check integration loaded (HA_TOKEN is the long-lived access token)
224- curl -s http://localhost:8123/api/states \
225- -H " Authorization: Bearer $HA_TOKEN " | python -m json.tool
226-
227- # Call a service
228- curl -X POST http://localhost:8123/api/services/ha_light_controller/ensure_state \
229- -H " Authorization: Bearer $HA_TOKEN " \
230- -H " Content-Type: application/json" \
231- -d ' {"entity_id": "light.ceiling_lights", "state": "on", "brightness_pct": 50}'
232-
233- # Verify entity cleanup (e.g., after preset deletion)
234- curl -s http://localhost:8123/api/states \
235- -H " Authorization: Bearer $HA_TOKEN " \
236- | python -c " import sys,json; [print(s['entity_id']) for s in json.load(sys.stdin) if 'preset' in s['entity_id']]"
237194```
238195
239- ** Workflow:** Unit tests (` make test ` ) validate logic in isolation. Live testing
240- validates HA runtime behavior that mocks can't cover — entity lifecycle, service
241- registration persistence across reloads, config flow UI, and entity registry cleanup.
242-
243- ## Documentation Style
244-
245- Target technically proficient Home Assistant users:
246-
247- - Use proper HA terminology (` entities ` , ` services ` , ` ConfigEntry ` )
248- - Prefer code examples over prose
249- - Skip basic explanations (don't explain what HACS is)
250-
251- ## Code Principles
252-
253- Two requirements govern all code in this repository:
254-
255- ### 1. Readability
256-
257- - ** Prefer flat over nested** - Avoid deep nesting (3+ levels). Extract helpers instead.
258- - ** Name for intent** - Variables and functions should describe what they do, not how.
259- - ** Consistent patterns** - Similar operations should use identical patterns throughout.
260- - ** Minimal comments** - Code should be self-explanatory. Comments explain "why", not
261- "what".
262-
263- ### 2. Simplicity
264-
265- - ** No speculative handling** - Only handle edge cases that actually occur. Delete code
266- for hypothetical scenarios.
267- - ** DRY without over-abstraction** - Extract repeated code, but don't create
268- abstractions for single-use cases.
269- - ** Delete, don't deprecate** - Remove unused code entirely. No commented-out code or
270- compatibility shims.
271- - ** Fail early, fail clearly** - Validate inputs at boundaries, then trust internal
272- state.
196+ Unit tests validate logic in isolation. Live testing validates HA runtime behavior that
197+ mocks can't cover — entity lifecycle, service registration persistence across reloads,
198+ config flow UI, and entity registry cleanup.
273199
274- ### Anti-patterns to Avoid
200+ ## Code Style
275201
276- - Defensive coding for impossible cases
277- - Multiple validation points for the same data
278- - Redundant lookups within the same scope
279- - Overly broad exception handling (` except Exception ` )
280- - State persistence via instance variables when dataflow would be clearer
202+ - Prefer flat over nested (3+ levels → extract helpers)
203+ - Consistent patterns — similar operations use identical structure throughout
204+ - Delete, don't deprecate — no commented-out code or compatibility shims
205+ - Fail early, fail clearly — validate at boundaries, trust internal state
0 commit comments