Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CONTEXT.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Matching uses **unique_id** patterns (`{entry_id}_relay_*`, `{entry_id}_serial_*

2. **Options flow menus** — some steps use **`vol.In({...})`** instead of **`SelectSelector`** for broader HA compatibility.

3. **Translations** — `options.step.remote_commands` needs **`description`** + **`{hint}`** placeholder. **`options.step.init.data.next`** in `strings.json`. IR/serial command JSON uses **`TextSelector(multiline=True)`** (textarea), not a single-line field. Learn IR uses **`learn_ir`** / **`learn_ir_capture`** with placeholders `{timeout}`, `{command}`, `{detail}`, and **`{ir_hint}`** on `learn_ir` (always pass a non-empty placeholder so HA does not show the raw token). When creating a remote mid-learn, the form key is **`remote_name`** (not `name`) because `CONF_REMOTE_NAME` and `CONF_CMD_NAME` both serialize as `"name"`.
3. **Translations** — Command editing is a list (`remote_command_list` / `serial_command_list`) with **`description`** `{summary}` (always pass a non-empty summary). Add/edit is one form per command; **Import JSON** is the multiline array (`remote_command_import` / `serial_command_import`). **`options.step.init.data.next`** in `strings.json`. Learn IR uses **`learn_ir`** / **`learn_ir_capture`** with placeholders `{timeout}`, `{command}`, `{detail}`, and **`{ir_hint}`** on `learn_ir` (always pass a non-empty placeholder so HA does not show the raw token). When creating a remote mid-learn, the form key is **`remote_name`** (not `name`) because `CONF_REMOTE_NAME` and `CONF_CMD_NAME` both serialize as `"name"`.

4. **Do not use `listen` as a config-flow field key** — Home Assistant does not apply `options.step.*.data.listen` labels; UI shows raw `listen`. Use **`monitor_incoming`** with label *Monitor incoming data (persistent connection)* (plain **`bool`**, same as `append_cr`).

Expand Down Expand Up @@ -98,7 +98,7 @@ Matching uses **unique_id** patterns (`{entry_id}_relay_*`, `{entry_id}_serial_*
## Documentation

- **[`README.md`](README.md)** — user-facing install, configure, API mapping, screenshot gallery.
- **[`docs/images/`](docs/images/)** — committed UI screenshots (integrations, config flow, options with Learn IR, gateway emitters, remotes, LG Infrared example, GC-100).
- **[`docs/images/`](docs/images/)** — committed UI screenshots (integrations, config flow, options with Learn IR, command list / add command / import JSON, gateway emitters, remotes, LG Infrared example, GC-100).
- **[`docs/screenshot-manifest.yaml`](docs/screenshot-manifest.yaml)** — Playwright capture plan (device selectors, paths, actions). Docker HA is on host port **8124**.
- **Cursor skill:** `~/.cursor/skills/ha-integration-screenshots/` — reusable across all HA custom integration repos.

Expand Down
49 changes: 32 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ There is **no `remote` platform** — each JSON command becomes its own **button
|---|---|
| [![LG Infrared](docs/images/lg-infrared-device.png)](docs/images/lg-infrared-device.png) | [![GC-100 gateway](docs/images/gc100-gateway.png)](docs/images/gc100-gateway.png) |

| Command list | Add a command |
|---|---|
| [![Command list](docs/images/command-list.png)](docs/images/command-list.png) | [![Add a command](docs/images/command-form.png)](docs/images/command-form.png) |

## Installation

### Using HACS
Expand Down Expand Up @@ -97,11 +101,11 @@ Open **Configure** on the integration card (gear icon on older layouts):
|--------|---------|
| **IR defaults** | Carrier frequency, repeat, offset, sendir ID policy (auto-increment vs fixed). |
| **Timeouts** | Connect and command timeouts. |
| **Add remote** | Name, module/port (e.g. module `1`, port `2` → connector **1:2**), repeat multiplier, **JSON command list**. |
| **Add remote** | Name, module/port (e.g. module `1`, port `2` → connector **1:2**), repeat multiplier, then one command at a time (or **Import JSON**). |
| **Learn IR command (pinhole)** | Always available in Configure. Pick an existing remote (or enter a name + IR connector to create one) and a command name → Submit → aim the handheld at the iTach **pinhole** within the timeout. Saves a **`full_sendir`** button (rewrites connector to the remote’s module:port). Same name replaces an existing command. |
| **Edit remote** / **Remove remote** | Change or delete a configured remote (entity IDs stay stable on edit). Shown only when at least one remote exists. |
| **Add relay** / **Edit relay** / **Remove relay** | Relay `switch` entities via `setstate` / `getstate`. |
| **Add serial port** / **Edit serial** / **Remove serial** | Serial `text` entity, optional preset **buttons**, **Last received** sensor. |
| **Add serial port** / **Edit serial** / **Remove serial** | Serial `text` entity, optional preset **buttons** (one at a time, or **Import JSON**), **Last received** sensor. |

#### Learn IR (pinhole)

Expand All @@ -116,7 +120,7 @@ The learned line is stored as a **`full_sendir`** command button (connector rewr

### Devices and entities

Each **gateway** is one hub device with diagnostic sensors (**TCP connected**, **Last gateway poll**, **Configured remotes**, optional **Gateway diagnostics**), plus one **`infrared` emitter** per IR connector discovered via `getdevices` (and, on **Global Connect** only, an optional **receiver** when a jack is in `RECEIVER` mode). Each configured **remote** appears as a child device with one **button** per JSON command.
Each **gateway** is one hub device with diagnostic sensors (**TCP connected**, **Last gateway poll**, **Configured remotes**, optional **Gateway diagnostics**), plus one **`infrared` emitter** per IR connector discovered via `getdevices` (and, on **Global Connect** only, an optional **receiver** when a jack is in `RECEIVER` mode). Each configured **remote** appears as a child device with one **button** per command.

![Gateway device](docs/images/gateway-device.png)

Expand All @@ -134,30 +138,41 @@ Each **gateway** is one hub device with diagnostic sensors (**TCP connected**, *

**Diagnostics in the UI:** enable **Gateway diagnostics** (off by default) to see raw `getdevices` / `getversion` text. On the device page use **⋮ → Download diagnostics** for a JSON bundle (entry data/options, coordinator snapshot, live probes).

### Command JSON format
### Commands

Each command is an object:
On **Add remote** or **Edit remote**, after the connector, each button is its own form: name, format (`pronto`, `gc_pairs`, or `full_sendir`), and the code. Leave carrier frequency, repeat, offset, and sendir ID blank to use the remote and gateway defaults. Adding the same name again replaces that command. Renaming or removing a command drops the old button the next time the integration reloads.

| Field | Required | Description |
|--------|----------|-------------|
| `name` | yes | Button entity label; matched case-insensitively in services if needed. |
| `data` | yes | Pronto hex, comma-separated GC pulse pairs, or a full `sendir,...` line (no trailing CR) when using `full_sendir`. |
| `format` | no | `pronto` (alias `pronto_hex`), `gc_pairs` (alias `gc_sendir_tail`), or `full_sendir`. |
| `freq`, `repeat`, `offset`, `command_id` | no | Overrides for that command only. |
![Command list](docs/images/command-list.png)

![Add a command](docs/images/command-form.png)

Example:
**Import JSON** replaces the whole list. Use one array, with a comma between objects:

![Import commands](docs/images/command-import.png)

```json
[
{
"name": "power",
"format": "pronto",
"data": "0000 006D 0000 0022 00AC 00AC 0015 0040"
"name": "PowerOn",
"format": "gc_pairs",
"data": "172,172,22,64,22,64"
},
{
"name": "PowerOff",
"format": "gc_pairs",
"data": "173,173,21,65,21,65"
}
]
```

Serial preset JSON uses `name` and `payload` (see options hint text).
| Field | Required | Description |
|--------|----------|-------------|
| `name` | yes | Button entity label; matched case-insensitively in services if needed. |
| `data` | yes | Pronto hex, comma-separated GC pulse pairs, or a full `sendir,...` line (no trailing CR) when using `full_sendir`. |
| `format` | no | `pronto` (alias `pronto_hex`), `gc_pairs` (alias `gc_sendir_tail`), or `full_sendir`. |
| `freq`, `repeat`, `offset`, `command_id` | no | Overrides for that command only. |

Serial presets use the same list. Each preset is a name and a payload. An empty list keeps the text entity only. Import JSON for presets is an array of `{name, payload}` objects.

### Automations and dashboards

Expand Down Expand Up @@ -191,7 +206,7 @@ Protocol reference: [iTach API (PDF)](https://www.globalcache.com/files/docs/API
- **GC-100** allows only **one** TCP client on port **4998** at a time; avoid iHelp/other tools holding that port while Home Assistant is connected.
- **IR learner** — use **Configure → Learn IR command (pinhole)** (always listed, even with no remotes yet) to capture a `sendir` line and append it to a remote as a **button** (`full_sendir`). With no remotes, the same flow creates one. Services `ir_learner_start` / `ir_learner_stop` and bus events remain for automations; Global Caché’s **iLearn** utility is still useful for advanced editing.
- **`infrared` receivers** / `set_IR RECEIVER` / `receiveIR` are **Global Connect only** (Unified TCP API). On iTach/GC-100/Flex the integration does not probe for RECEIVER or create receiver entities; use emitters plus the **pinhole learner** (`get_IRL`). Raw `set_ir` / `receive_ir` services remain for advanced use but `RECEIVER` is invalid on non–Global Connect hardware.
- Removing a remote, relay, or serial port from options **deletes** its entities from the registry on reload (they are not left as orphaned grey entities).
- Removing a remote, relay, serial port, or one of its commands from options **deletes** the matching entities from the registry on reload (they are not left as orphaned grey entities). Renaming a command does the same for the old button name.

## Development

Expand Down
9 changes: 5 additions & 4 deletions custom_components/globalcache_itach/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.update_coordinator import CoordinatorEntity

from .command_util import ir_send_repeat, stored_int
from .const import (
CONF_CMD_DATA,
CONF_CMD_FORMAT,
Expand Down Expand Up @@ -164,10 +165,10 @@ async def async_press(self) -> None:
self._port,
fmt,
data,
repeat=self._base_repeat,
offset=int(offset) if offset is not None else None,
frequency=int(freq) if freq is not None else None,
command_id=int(cid) if cid is not None else None,
repeat=ir_send_repeat(self._cmd, self._base_repeat),
offset=stored_int(offset),
frequency=stored_int(freq),
command_id=stored_int(cid),
)
except (ServiceValidationError, OSError, TimeoutError) as err:
raise HomeAssistantError(str(err)) from err
Expand Down
Loading
Loading