Metadata-Version: 2.4
Name: midea-dishwasher-api
Version: 1.0.0
Summary: Cliente Python para lava-louças Midea (device_type 0xE1, plugin v5) — codec do frame AA + transporte LAN V3.
Project-URL: Homepage, https://github.com/roquerodrigo/midea-dishwasher-api
Project-URL: Repository, https://github.com/roquerodrigo/midea-dishwasher-api
Project-URL: Issues, https://github.com/roquerodrigo/midea-dishwasher-api/issues
Author-email: Rodrigo Roque <rodrigogoncalvesroque@gmail.com>
License: MIT License
        
        Copyright (c) 2026 Rodrigo Roque
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: dishwasher,iot,lan,midea,smart-home
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Home Automation
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.14
Provides-Extra: dev
Requires-Dist: pytest>=8; extra == 'dev'
Provides-Extra: lan
Requires-Dist: cryptography>=42; extra == 'lan'
Description-Content-Type: text/markdown

# midea-dishwasher-api

Cliente Python para lava-louças Midea (`device_type 0xE1`, plugin v5).

Implementa o protocolo de aplicação `AA … E1` e a camada de transporte LAN V3
(handshake 8370 + AES-128-CBC + SHA-256, com framing V2 5A5A interno).

## Instalação

```bash
pip install midea-dishwasher-api[lan]
```

O extra `lan` instala `cryptography`, necessário para falar diretamente com a
máquina via LAN. Sem o extra, o pacote ainda expõe o codec do frame e o
parser de status para uso com transporte próprio (cloud, mock, etc.).

## Uso rápido

```python
from midea_dishwasher_api import BrightLevel, Client, Mode, V3Transport

with V3Transport(
    host="192.168.5.100",
    device_id=151732606394621,
    token=bytes.fromhex("..."),  # 64 bytes
    key=bytes.fromhex("..."),    # 32 bytes
) as transport:
    client = Client(send=transport)

    status = client.query_status()
    print(status.machine_state)   # MachineState.POWER_ON / POWER_OFF
    print(status.cycle_state)     # CycleState.IDLE / WORK / ORDER / ...
    print(status.left_time)       # minutos restantes (apenas em WORK)
    print(status.door_closed)
    print(status.bright_lack)     # secante acabou?

    client.power_on()
    client.start_to_work(mode=Mode.ECO, extra_drying=True)
    client.set_bright(BrightLevel.L3)
    client.cancel_work()
    client.power_off()
```

Os métodos de controle não retornam estado (a máquina demora alguns segundos
para refletir a mudança). Chame `query_status()` quando quiser estado fresco.

## API

### Client

| Método | Efeito |
|---|---|
| `query_status() -> DishwasherStatus` | Lê o estado atual |
| `power_on()` | Liga a máquina |
| `power_off()` | Desliga |
| `cancel_work()` | Cancela ciclo / volta ao idle |
| `start_to_work(mode, extra_drying=False)` | Inicia ciclo |
| `set_bright(level: BrightLevel)` | Ajusta o nível do abrilhantador (1–5) |

### DishwasherStatus

Campos decodificados da resposta:

- `machine_state: MachineState | None` — `POWER_ON` / `POWER_OFF`
- `cycle_state: CycleState | None` — `idle`, `order`, `work`, `error`, ...
- `wash_stage: WashStage | int | None` — `IDLE`, `PRE_WASH`, `MAIN_WASH`, `RINSE`, `DRY`, `FINISH`
- `error_code: ErrorCode | int` — `NONE`, `WATER_SUPPLY`, `HEATING`, `OVERFLOW`, `WATER_VALVE`
- `left_time: int | None` — minutos restantes (preenchido apenas quando `cycle_state == WORK`)
- `door_closed: bool`
- `bright_lack: bool` — secante (rinse aid) acabou

### Modos disponíveis (`Mode`)

`AUTO`, `INTENSIVE`, `NORMAL`, `ECO`, `GLASS`, `NINETY_MIN`, `ONE_HOUR`,
`RAPID`, `SOAK`, `THREE_IN_ONE`, `HYGIENE`, `QUIET`, `PARTY`, `FRUIT`.

## Transporte customizado

`Client` aceita qualquer `Callable[[bytes], bytes]` como `send`. Útil para
testes com transporte mock, integração com cloud, ou pipeline próprio:

```python
def fake_send(frame: bytes) -> bytes:
    return assemble_frame(b"...", 0x02)

client = Client(send=fake_send)
```

## Como obter `token` e `key`

São credenciais por dispositivo emitidas pela cloud da Midea. Use ferramentas
existentes (`midea-msmart`, `midea-beautiful-air`, `midea-discover`) para
extrair a partir da sua conta no app.

## Licença

MIT — ver `LICENSE`.
