1 """unifiprotect.repairs."""
3 from __future__
import annotations
5 from typing
import cast
7 from uiprotect
import ProtectApiClient
8 from uiprotect.data
import Bootstrap, Camera, ModelType
9 from uiprotect.data.types
import FirmwareReleaseChannel
10 import voluptuous
as vol
12 from homeassistant
import data_entry_flow
18 from .const
import CONF_ALLOW_EA
19 from .data
import UFPConfigEntry, async_get_data_for_entry_id
20 from .utils
import async_create_api_client
24 """Handler for an issue fixing flow."""
26 _api: ProtectApiClient
27 _entry: UFPConfigEntry
29 def __init__(self, *, api: ProtectApiClient, entry: UFPConfigEntry) ->
None:
38 issue_registry = ir.async_get(self.hass)
39 description_placeholders = {}
40 if issue := issue_registry.async_get_issue(self.handler, self.issue_id):
41 description_placeholders = issue.translation_placeholders
or {}
42 if issue.learn_more_url:
43 description_placeholders[
"learn_more"] = issue.learn_more_url
45 return description_placeholders
49 """Handler for an issue fixing flow."""
52 self, user_input: dict[str, str] |
None =
None
54 """Handle the first step of a fix flow."""
59 self, user_input: dict[str, str] |
None =
None
61 """Handle the confirm step of a fix flow."""
62 if user_input
is None:
66 data_schema=vol.Schema({}),
67 description_placeholders=placeholders,
70 nvr = await self.
_api_api.get_nvr()
71 if nvr.release_channel != FirmwareReleaseChannel.RELEASE:
73 await self.hass.config_entries.async_reload(self.
_entry_entry.entry_id)
77 self, user_input: dict[str, str] |
None =
None
79 """Handle the confirm step of a fix flow."""
80 if user_input
is not None:
82 options[CONF_ALLOW_EA] =
True
83 self.hass.config_entries.async_update_entry(self.
_entry_entry, options=options)
89 data_schema=vol.Schema({}),
90 description_placeholders=placeholders,
95 """Handler for an issue fixing flow."""
98 self, user_input: dict[str, str] |
None =
None
100 """Handle the first step of a fix flow."""
105 self, user_input: dict[str, str] |
None =
None
107 """Handle the first step of a fix flow."""
109 if user_input
is None:
113 data_schema=vol.Schema({}),
114 description_placeholders=placeholders,
117 self.
_entry_entry.async_start_reauth(self.hass)
122 """Handler for an issue fixing flow."""
125 _camera: Camera |
None
126 _bootstrap: Bootstrap |
None
131 api: ProtectApiClient,
132 entry: UFPConfigEntry,
137 super().
__init__(api=api, entry=entry)
145 if self.
_camera_camera
is not None:
146 description_placeholders[
"camera"] = self.
_camera_camera.display_name
148 return description_placeholders
157 if self.
_camera_camera
is None:
160 assert self.
_camera_camera
is not None
166 user = bootstrap.users.get(bootstrap.auth_user_id)
167 if not user
or not camera.can_write(user):
170 channel = camera.channels[0]
171 channel.is_rtsp_enabled =
True
173 ModelType.CAMERA, camera.id, {
"channels": camera.unifi_dict()[
"channels"]}
177 self, user_input: dict[str, str] |
None =
None
179 """Handle the first step of a fix flow."""
184 self, user_input: dict[str, str] |
None =
None
186 """Handle the first step of a fix flow."""
188 if user_input
is None:
194 data_schema=vol.Schema({}),
195 description_placeholders=placeholders,
198 updated_camera = await self.
_api_api.get_camera(self.
_camera_id_camera_id)
199 if not any(c.is_rtsp_enabled
for c
in updated_camera.channels):
202 updated_camera = await self.
_api_api.get_camera(self.
_camera_id_camera_id)
203 if any(c.is_rtsp_enabled
for c
in updated_camera.channels):
204 await self.hass.config_entries.async_reload(self.
_entry_entry.entry_id)
209 self, user_input: dict[str, str] |
None =
None
211 """Handle the confirm step of a fix flow."""
212 if user_input
is not None:
218 data_schema=vol.Schema({}),
219 description_placeholders=placeholders,
225 hass: HomeAssistant, entry: ConfigEntry
226 ) -> ProtectApiClient:
227 """Get or create an API client."""
236 data: dict[str, str | int | float |
None] |
None,
241 and "entry_id" in data
242 and (entry := hass.config_entries.async_get_entry(cast(str, data[
"entry_id"])))
245 if issue_id ==
"ea_channel_warning":
247 if issue_id ==
"cloud_user":
249 if issue_id.startswith(
"rtsp_disabled_"):
251 api=api, entry=entry, camera_id=cast(str, data[
"camera_id"])
data_entry_flow.FlowResult async_step_confirm(self, dict[str, str]|None user_input=None)
data_entry_flow.FlowResult async_step_init(self, dict[str, str]|None user_input=None)
data_entry_flow.FlowResult async_step_confirm(self, dict[str, str]|None user_input=None)
data_entry_flow.FlowResult async_step_start(self, dict[str, str]|None user_input=None)
data_entry_flow.FlowResult async_step_init(self, dict[str, str]|None user_input=None)
None __init__(self, *ProtectApiClient api, UFPConfigEntry entry)
dict[str, str] _async_get_placeholders(self)
data_entry_flow.FlowResult async_step_init(self, dict[str, str]|None user_input=None)
data_entry_flow.FlowResult async_step_confirm(self, dict[str, str]|None user_input=None)
Bootstrap _get_boostrap(self)
None __init__(self, *ProtectApiClient api, UFPConfigEntry entry, str camera_id)
dict[str, str] _async_get_placeholders(self)
data_entry_flow.FlowResult async_step_start(self, dict[str, str]|None user_input=None)
_FlowResultT async_show_form(self, *str|None step_id=None, vol.Schema|None data_schema=None, dict[str, str]|None errors=None, Mapping[str, str]|None description_placeholders=None, bool|None last_step=None, str|None preview=None)
_FlowResultT async_create_entry(self, *str|None title=None, Mapping[str, Any] data, str|None description=None, Mapping[str, str]|None description_placeholders=None)
str|None update_device(HomeAssistant hass, ConfigEntry config_entry, ConfigType config)
ProtectData|None async_get_data_for_entry_id(HomeAssistant hass, str entry_id)
ProtectApiClient _async_get_or_create_api_client(HomeAssistant hass, ConfigEntry entry)
RepairsFlow async_create_fix_flow(HomeAssistant hass, str issue_id, dict[str, str|int|float|None]|None data)
ProtectApiClient async_create_api_client(HomeAssistant hass, UFPConfigEntry entry)