Metadata-Version: 2.1
Name: rubetek_socket_api
Version: 0.0.1
Summary: API wrapper for controlling the Rubetek RE-3305 smart socket.
Author-email: regenara <jakebv.22@gmail.com>
License: MIT License
        
        Copyright (c) 2024 regenara
        
        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.
        
Project-URL: repository, https://github.com/regenara/rubetek_socket_api
Project-URL: homepage, https://github.com/regenara/rubetek_socket_api
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: certifi==2025.1.31
Requires-Dist: pydantic==2.10.6
Requires-Dist: aiohttp==3.10.11

# Rubetek Socket API

### Описание / Description 
Эта библиотека предоставляет API-обертку для управления умной розеткой Rubetek RE-3305. Возможность работы с другими моделями не проверялась, но, вероятно, поддерживается.
<br>This library provides an API wrapper for controlling the Rubetek RE-3305 smart socket. Compatibility with other models has not been tested but is likely supported.

## Установка / Installation
```bash
pip install rubetek-socket-api
```

## Авторизация / Authorization

### Получение refresh token, client id и client secret / Obtaining refresh token, client id and client secret
Чтобы получить `refresh_token`, `client_id` и `client_secret`, перехватите запросы из мобильного приложения Rubetek. Я использовал Android-устройство и [HTTP Toolkit](https://httptoolkit.com/). Перехватывать запросы нужно в только что установленном или предварительно разлогиненном приложении.
<br>To retrieve `refresh_token`, `client_id`, and `client_secret`, intercept requests from the Rubetek mobile app. I used an Android device and [HTTP Toolkit](https://httptoolkit.com/). Requests should be captured in a freshly installed or previously logged-out application.
<details>
  <summary>Показать изображения / Show images</summary>

![refresh_token](https://raw.githubusercontent.com/regenara/rubetek_socket_api/master/images/refresh_token.jpg)
*Refresh Token*

![client_id & client_secret](https://raw.githubusercontent.com/regenara/rubetek_socket_api/master/images/client.jpg)
*Client ID & Client Secret*
</details>

### Авторизация через refresh token (рекомендуется) / Authorization via refresh token (recommended)
```python
import asyncio

from rubetek_socket_api import RubetekSocketAPI

REFRESH_TOKEN = 'your_refresh_token'

async def main():
    rubetek_api = RubetekSocketAPI(refresh_token=REFRESH_TOKEN)
    user_info = await rubetek_api.get_user()
    print(user_info)
```

### Авторизация через код (не рекомендуется) / Authorization via code (not recommended)
```python
import asyncio

from rubetek_socket_api import RubetekSocketAPI

CLIENT_ID = 'your_client_id'
CLIENT_SECRET = 'your_client_secret'
PHONE = 'your_phone'
EMAIL = 'your_email'

async def sms_auth():
    rubetek_api = RubetekSocketAPI(client_id=CLIENT_ID, client_secret=CLIENT_SECRET)
    await rubetek_api.send_code(phone=PHONE)
    code = input('Enter the code: ')
    await rubetek_api.change_code_to_access_token(code=code, phone=PHONE)
    print(f'Refresh Token: {rubetek_api.refresh_token}')  # Save refresh token
    user_info = await rubetek_api.get_user()
    print(user_info)

async def email_auth():
    rubetek_api = RubetekSocketAPI(client_id=CLIENT_ID, client_secret=CLIENT_SECRET)
    await rubetek_api.send_code(email=EMAIL)
    code = input('Enter the code: ')
    await rubetek_api.change_code_to_access_token(code=code, email=EMAIL)
    print(f'Refresh Token: {rubetek_api.refresh_token}')  # Save refresh token
    user_info = await rubetek_api.get_user()
    print(user_info)
```

## Использование / Usage
```python
import asyncio

from rubetek_socket_api import RubetekSocketAPI

async def main():
    rubetek_api = RubetekSocketAPI(...)  # Выберите подходящий метод авторизации / Choose the appropriate authentication method
    houses = await rubetek_api.get_houses()
    house_id = houses[0].id
    devices = await rubetek_api.get_house_devices(house_id=house_id)
    device_id = devices[0].id
    device = await rubetek_api.get_device(house_id=house_id, device_id=device_id)
    
    print(
        f'Status (on/off): {device.state.relay_on}',
        f'RGB level: {device.state.rgb_level}',
        f'Online status: {device.online}',
        f'Sleep timer (minutes): {device.state.relay_mode}',
        sep='\n'
    )
    
    await rubetek_api.set_rgb_level(house_id=house_id, device_id=device_id, value=100)
    await rubetek_api.set_on_off(house_id=house_id, device_id=device_id, value=not device.state.relay_on)
    await rubetek_api.set_disable_timer(house_id=house_id, device_id=device_id, value=60)

    await rubetek_api.close()

asyncio.run(main())
```

