Files
sirmrak 15a97be8e2 Оптимизация и модернизация __init__.py
— aiohttp вместо requests: реальный async, единая ClientSession, connection pooling
— async file I/O через executor (write_bytes, mkdir, cleanup)
— asyncio.gather для параллельного опроса событий
— asyncio.wait_for(timeout=5) на FFmpeg check
— CameraTokenInfo dataclass вместо dict
— yarl.URL для безопасной кодировки query-параметров
— Общие _api_get/_api_post, уменьшение дублирования
— CONF_ARCHIVE_DURATION вынесена в настройки
— Удалена бессмысленная ветка в get_intercoms_info
— _close_session() cleanup при unload
— sensor.py: archive_url → archive_path
— Обновлены переводы и config_flow для archive_duration
2026-06-28 17:14:49 +03:00

73 lines
2.1 KiB
Python

import voluptuous as vol
from homeassistant.config_entries import (
ConfigEntry,
ConfigFlow,
OptionsFlowWithConfigEntry,
)
from homeassistant.core import callback
from . import (
CONF_NAME,
CONF_TOKEN,
CONF_CAMERA_IMAGE_REFRESH_INTERVAL,
CONF_SCREENSHOT_QUALITY,
CONF_LOG_LEVEL,
CONF_EVENTS_ENABLED,
CONF_EVENTS_REFRESH_INTERVAL,
CONF_EVENT_TIME_LAG,
CONF_PRE_EVENT_SECONDS,
CONF_EVENT_SCREENSHOT_QUALITY,
CONF_EVENT_SENSOR_ENABLED,
CONF_ARCHIVE_PATH,
CONF_ARCHIVE_COPIES,
CONF_ARCHIVE_DURATION,
CONF_SCREENSHOT_COPIES,
DATA_SCHEMA,
OPTIONS_SCHEMA,
DOMAIN,
)
class RTKeyOptionsFlow(OptionsFlowWithConfigEntry):
async def async_step_init(self, user_input=None):
if user_input is not None:
return self.async_create_entry(
title=self.config_entry.data.get(CONF_NAME, "RT Key"),
data=user_input,
)
current_options = dict(self.options)
if CONF_TOKEN not in current_options and CONF_TOKEN in self.config_entry.data:
current_options[CONF_TOKEN] = self.config_entry.data[CONF_TOKEN]
return self.async_show_form(
step_id="init",
data_schema=self.add_suggested_values_to_schema(
vol.Schema(OPTIONS_SCHEMA), current_options
),
)
class RTKeyConfigFlow(ConfigFlow, domain=DOMAIN):
VERSION = 1
MINOR_VERSION = 1
@staticmethod
@callback
def async_get_options_flow(config_entry: ConfigEntry) -> RTKeyOptionsFlow:
return RTKeyOptionsFlow(config_entry)
async def async_step_user(self, user_input=None):
if user_input is not None:
return self.async_create_entry(
title=user_input.get(CONF_NAME, "RT Key"),
data=user_input,
options=user_input,
)
return self.async_show_form(
step_id="user",
data_schema=self.add_suggested_values_to_schema(
vol.Schema(DATA_SCHEMA).extend(OPTIONS_SCHEMA),
{},
),
)