Metadata-Version: 2.4
Name: kubegate
Version: 0.1.3
Summary: Control Key Automation KUBE gate modules (AVO, Easy, Key Automation, Levada) over BLE and cloud.
Author-email: Frane Bandov <frane.bandov@gmail.com>
License: Apache-2.0
Keywords: kube,avo,easy,levada,key automation,gate,ble,home assistant
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: NOTICE
Requires-Dist: bleak>=0.21
Requires-Dist: bleak-retry-connector>=3.5
Requires-Dist: cryptography>=41
Provides-Extra: cloud
Requires-Dist: aiohttp>=3.9; extra == "cloud"
Provides-Extra: cli
Dynamic: license-file

# kubegate — control your KUBE gate from Python / Home Assistant

Local **BLE** and (soon) cloud control for gate automations built on the
**Key Automation KUBE** WiFi/BLE module — sold under several brands:

> **AVO · Easy · Key Automation · Levada**

Many owners don't realise their "AVO" or "Levada" gate app is the same KUBE
platform underneath. If your gate uses one of these apps, this library talks to it.

This repo hosts the reusable protocol library (`kubegate`). The Home Assistant
integration lives in [`ha-kube`](../ha-kube) and builds on it.

## Status
- ✅ **Local BLE**: handshake, encrypted commands (open / close / pedestrian / light), live status — reverse-engineered and verified against real devices.
- ✅ **Cloud (remote)**: encrypt to the gate's public key + sign with your key, written to the RTDB relay — verified on real hardware.
- ✅ **Account discovery**: log in with your brand account to auto-import gates, passkeys and keys.

## Install
```bash
pip install -e .
```

## Quick start (BLE)
```bash
python -m kubegate.cli scan
python -m kubegate.cli status --addr <ADDR> --passkey 0000000000012345
python -m kubegate.cli open   --addr <ADDR> --passkey 0000000000012345
```

```python
import asyncio
from kubegate.ble import KubeBleDevice

async def main():
    async with KubeBleDevice("<ADDR>", "0000000000012345") as gate:
        await gate.action("open")
        print(gate.status)

asyncio.run(main())
```

## Protocol (short)
```
enckey1 = AES128_ECB(passkey, serial)             # constant per device
enckey2 = AES128_ECB(passkey, nonce XOR enckey1)  # per-connection XOR pad
token   = (nonce XOR enckey1) XOR enckey2          # auth, written to f1170005
frames: @LLLL<body># , body = name or name={json}; whole frame XOR enckey2
action: cact={"cmd":"C30B","val":N}  (N: 8 open · 4 close · 128 pedestrian · 256 light)
```

The `passkey` is a 16-digit, zero-padded number from your account/installation.

## License
Apache-2.0. Not affiliated with Key Automation or any brand listed above.
