|
| 1 | +"""File for models used in responses from config entries.""" |
| 2 | + |
| 3 | +import asyncio |
| 4 | +from enum import Enum |
| 5 | +from typing import Any, Container, Dict, Optional, Tuple, Union |
| 6 | + |
| 7 | +from .base import BaseModel |
| 8 | + |
| 9 | + |
| 10 | +class FlowResultType(Enum): |
| 11 | + """Result type for a data entry flow.""" |
| 12 | + |
| 13 | + FORM = "form" |
| 14 | + CREATE_ENTRY = "create_entry" |
| 15 | + ABORT = "abort" |
| 16 | + EXTERNAL_STEP = "external" |
| 17 | + EXTERNAL_STEP_DONE = "external_done" |
| 18 | + SHOW_PROGRESS = "progress" |
| 19 | + SHOW_PROGRESS_DONE = "progress_done" |
| 20 | + MENU = "menu" |
| 21 | + |
| 22 | + |
| 23 | +class DiscoveryKey(BaseModel): |
| 24 | + """Serializable discovery key.""" |
| 25 | + |
| 26 | + domain: str |
| 27 | + key: Union[str, Tuple[str, ...]] |
| 28 | + version: int |
| 29 | + |
| 30 | + |
| 31 | +class FlowContext(BaseModel): |
| 32 | + """Base flow context""" |
| 33 | + |
| 34 | + show_advanced_options: Union[bool, None] = None |
| 35 | + source: str |
| 36 | + |
| 37 | + |
| 38 | +class ConfigFlowContext(FlowContext): |
| 39 | + """Context for config flow.""" |
| 40 | + |
| 41 | + alternative_domain: Optional[str] = None |
| 42 | + configuration_url: Optional[str] = None |
| 43 | + confirm_only: Optional[bool] = None |
| 44 | + discovery_key: DiscoveryKey |
| 45 | + entry_id: Optional[str] = None |
| 46 | + title_placeholders: Optional[Dict[str, str]] = None |
| 47 | + unique_id: Optional[str] = None |
| 48 | + |
| 49 | + |
| 50 | +class FlowResult(BaseModel): |
| 51 | + """Base flow result .""" |
| 52 | + |
| 53 | + context: ConfigFlowContext |
| 54 | + data_schema: Optional[Any] = None |
| 55 | + data: Optional[Dict[str, Any]] = None |
| 56 | + description_placeholders: Optional[Dict[str, str]] = None |
| 57 | + description: Optional[str] = None |
| 58 | + errors: Optional[Dict[str, str]] = None |
| 59 | + extra: Optional[str] = None |
| 60 | + flow_id: str |
| 61 | + handler: str |
| 62 | + last_step: Optional[bool] = None |
| 63 | + menu_options: Optional[Container[str]] = None |
| 64 | + preview: Optional[str] = None |
| 65 | + progress_action: Optional[str] = None |
| 66 | + progress_task: Optional[asyncio.Task[Any]] = None |
| 67 | + reason: Optional[str] = None |
| 68 | + required: Optional[bool] = None |
| 69 | + result: Optional[Any] = None |
| 70 | + step_id: Optional[str] = None |
| 71 | + title: Optional[str] = None |
| 72 | + translation_domain: Optional[str] = None |
| 73 | + type: Optional[FlowResultType] = None |
| 74 | + url: Optional[str] = None |
| 75 | + |
| 76 | + |
| 77 | +class DisableEnableResult(BaseModel): |
| 78 | + """Result from a disable/enable config entry call.""" |
| 79 | + |
| 80 | + require_restart: bool |
| 81 | + |
| 82 | + |
| 83 | +class IntegrationTypes(Enum): |
| 84 | + """Types of integrations.""" |
| 85 | + |
| 86 | + ENTITY = "entity" |
| 87 | + DEVICE = "device" |
| 88 | + HARDWARE = "hardware" |
| 89 | + HELPER = "helper" |
| 90 | + HUB = "hub" |
| 91 | + SERVICE = "service" |
| 92 | + SYSTEM = "system" |
| 93 | + VIRTUAL = "virtual" |
| 94 | + |
| 95 | + |
| 96 | +class ConfigEntryState(str, Enum): |
| 97 | + """Config entry state.""" |
| 98 | + |
| 99 | + LOADED = "loaded" |
| 100 | + SETUP_ERROR = "setup_error" |
| 101 | + MIGRATION_ERROR = "migration_error" |
| 102 | + SETUP_RETRY = "setup_retry" |
| 103 | + NOT_LOADED = "not_loaded" |
| 104 | + FAILED_UNLOAD = "failed_unload" |
| 105 | + SETUP_IN_PROGRESS = "setup_in_progress" |
| 106 | + UNLOAD_IN_PROGRESS = "unload_in_progress" |
| 107 | + |
| 108 | + |
| 109 | +class ConfigEntryDisabler(Enum): |
| 110 | + """What disabled a config entry.""" |
| 111 | + |
| 112 | + USER = "user" |
| 113 | + |
| 114 | + |
| 115 | +class ConfigEntry(BaseModel): |
| 116 | + """A configuration entry. This is the model that Home Assistant returns, but not what is used internally.""" |
| 117 | + |
| 118 | + created_at: float |
| 119 | + entry_id: str |
| 120 | + domain: str |
| 121 | + modified_at: float |
| 122 | + title: str |
| 123 | + source: str |
| 124 | + state: ConfigEntryState |
| 125 | + supports_options: bool |
| 126 | + supports_remove_device: bool |
| 127 | + supports_unload: bool |
| 128 | + supports_reconfigure: bool |
| 129 | + supported_subentry_types: Dict[str, Dict[str, bool]] |
| 130 | + pref_disable_new_entities: bool |
| 131 | + pref_disable_polling: bool |
| 132 | + disabled_by: Optional[ConfigEntryDisabler] |
| 133 | + reason: Optional[str] |
| 134 | + error_reason_translation_key: Optional[str] |
| 135 | + error_reason_translation_placeholders: Optional[Dict[str, Any]] |
| 136 | + num_subentries: int |
| 137 | + |
| 138 | + |
| 139 | +class ConfigSubEntry(BaseModel): |
| 140 | + """A configuration sub-entry. This is the model that Home Assistant returns, but not what is used internally.""" |
| 141 | + |
| 142 | + subentry_id: str |
| 143 | + subentry_type: str |
| 144 | + title: str |
| 145 | + unique_id: Optional[str] |
| 146 | + |
| 147 | + |
| 148 | +class ConfigEntryChange(str, Enum): |
| 149 | + """What was changed in a config entry.""" |
| 150 | + |
| 151 | + ADDED = "added" |
| 152 | + REMOVED = "removed" |
| 153 | + UPDATED = "updated" |
| 154 | + |
| 155 | + |
| 156 | +class ConfigEntryEvent(BaseModel): |
| 157 | + type: Optional[ConfigEntryChange] |
| 158 | + entry: ConfigEntry |
0 commit comments