Skip to content

Commit 36ba933

Browse files
chrisdpurcellclaude
andcommitted
chore: streamline CLAUDE.md, add HACS info.md, clean up hacs.json
Condense dev server docs (details in project memory), simplify code style section, add HACS store description page, remove deprecated render_readme key. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 632791a commit 36ba933

3 files changed

Lines changed: 62 additions & 88 deletions

File tree

CLAUDE.md

Lines changed: 11 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ HA-Light-Controller is a Home Assistant custom integration providing reliable li
1414
control with state verification, automatic retries, and preset management. It ensures
1515
lights 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
199191
cp -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
203193
podman 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

hacs.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
22
"name": "Light Controller",
3-
"homeassistant": "2025.2.0",
4-
"render_readme": true
3+
"homeassistant": "2025.2.0"
54
}

info.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
HA Light Controller adds state verification and automatic retries to light commands.
2+
When you call `light.turn_on`, Home Assistant sends the command once and assumes
3+
success. This integration verifies that entities actually reached the target state and
4+
retries if they didn't.
5+
6+
This solves the common problem of lights occasionally missing commands due to network
7+
congestion, Zigbee/Z-Wave mesh issues, or unresponsive devices. Instead of building
8+
retry logic into every script and automation, HA Light Controller handles verification
9+
centrally with configurable tolerances and backoff strategies.
10+
11+
## How It Works
12+
13+
1. Sends the light command (on/off, brightness, color, etc.)
14+
2. Waits a configurable delay for the state to update
15+
3. Verifies entity attributes match target values within tolerance
16+
4. Retries with exponential backoff if verification fails
17+
5. Optionally logs success to the Home Assistant logbook
18+
19+
## Key Features
20+
21+
- **State verification** - Confirms entities reached target brightness, color, and
22+
temperature within configurable tolerances
23+
- **Automatic retries** - Configurable retry attempts with exponential backoff
24+
- **Group expansion** - Automatically expands `light.*` and `group.*` entities to
25+
individual lights
26+
- **Per-entity overrides** - Set different attributes for each light in a single service
27+
call via the `targets` parameter
28+
- **Presets** - Store light configurations as button entities for one-tap activation
29+
30+
## Quick Start
31+
32+
```yaml
33+
service: ha_light_controller.ensure_state
34+
data:
35+
entities:
36+
- light.living_room_ceiling
37+
- light.living_room_lamp
38+
brightness_pct: 80
39+
color_temp_kelvin: 3000
40+
```
41+
42+
## Services
43+
44+
| Service | Description |
45+
|---|---|
46+
| `ensure_state` | Control lights with verification and retries |
47+
| `activate_preset` | Activate a saved preset by name or ID |
48+
| `create_preset` | Create a preset programmatically |
49+
| `create_preset_from_current` | Capture current light states as a preset |
50+
| `delete_preset` | Delete a preset by ID |

0 commit comments

Comments
 (0)