1 """Config flow for Roku."""
3 from __future__
import annotations
7 from urllib.parse
import urlparse
9 from rokuecp
import Roku, RokuError
10 import voluptuous
as vol
23 from .const
import CONF_PLAY_MEDIA_APP_ID, DEFAULT_PLAY_MEDIA_APP_ID, DOMAIN
25 DATA_SCHEMA = vol.Schema({vol.Required(CONF_HOST): str})
27 ERROR_CANNOT_CONNECT =
"cannot_connect"
28 ERROR_UNKNOWN =
"unknown"
30 _LOGGER = logging.getLogger(__name__)
33 async
def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> dict[str, Any]:
34 """Validate the user input allows us to connect.
36 Data has the keys from DATA_SCHEMA with values provided by the user.
39 roku = Roku(data[CONF_HOST], session=session)
40 device = await roku.update()
43 "title": device.info.name,
44 "serial_number": device.info.serial_number,
49 """Handle a Roku config flow."""
53 discovery_info: dict[str, Any]
56 """Set up the instance."""
60 def _show_form(self, errors: dict[str, Any] |
None =
None) -> ConfigFlowResult:
61 """Show the form to the user."""
64 data_schema=DATA_SCHEMA,
69 self, user_input: dict[str, Any] |
None =
None
70 ) -> ConfigFlowResult:
71 """Handle a flow initialized by the user."""
80 _LOGGER.debug(
"Roku Error", exc_info=
True)
81 errors[
"base"] = ERROR_CANNOT_CONNECT
84 _LOGGER.exception(
"Unknown error trying to connect")
93 self, discovery_info: zeroconf.ZeroconfServiceInfo
94 ) -> ConfigFlowResult:
95 """Handle a flow initialized by homekit discovery."""
106 _LOGGER.debug(
"Roku Error", exc_info=
True)
109 _LOGGER.exception(
"Unknown error trying to connect")
114 updates={CONF_HOST: discovery_info.host},
117 self.context.
update({
"title_placeholders": {
"name": info[
"title"]}})
123 self, discovery_info: ssdp.SsdpServiceInfo
124 ) -> ConfigFlowResult:
125 """Handle a flow initialized by discovery."""
126 host = urlparse(discovery_info.ssdp_location).hostname
127 name = discovery_info.upnp[ssdp.ATTR_UPNP_FRIENDLY_NAME]
128 serial_number = discovery_info.upnp[ssdp.ATTR_UPNP_SERIAL]
133 self.context.
update({
"title_placeholders": {
"name": name}})
140 _LOGGER.debug(
"Roku Error", exc_info=
True)
143 _LOGGER.exception(
"Unknown error trying to connect")
149 self, user_input: dict |
None =
None
150 ) -> ConfigFlowResult:
151 """Handle user-confirmation of discovered device."""
152 if user_input
is None:
154 step_id=
"discovery_confirm",
155 description_placeholders={
"name": self.
discovery_infodiscovery_info[CONF_NAME]},
167 config_entry: ConfigEntry,
168 ) -> RokuOptionsFlowHandler:
169 """Create the options flow."""
174 """Handle Roku options."""
177 self, user_input: dict[str, Any] |
None =
None
178 ) -> ConfigFlowResult:
179 """Manage Roku options."""
180 if user_input
is not None:
185 data_schema=vol.Schema(
188 CONF_PLAY_MEDIA_APP_ID,
190 CONF_PLAY_MEDIA_APP_ID, DEFAULT_PLAY_MEDIA_APP_ID
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_homekit(self, zeroconf.ZeroconfServiceInfo discovery_info)
ConfigFlowResult async_step_ssdp(self, ssdp.SsdpServiceInfo discovery_info)
ConfigFlowResult async_step_discovery_confirm(self, dict|None user_input=None)
ConfigFlowResult _show_form(self, dict[str, Any]|None errors=None)
RokuOptionsFlowHandler async_get_options_flow(ConfigEntry config_entry)
ConfigFlowResult async_step_init(self, dict[str, Any]|None user_input=None)
None _abort_if_unique_id_configured(self, dict[str, Any]|None updates=None, bool reload_on_update=True, *str error="already_configured")
ConfigEntry|None async_set_unique_id(self, str|None unique_id=None, *bool raise_on_progress=True)
ConfigFlowResult async_create_entry(self, *str title, Mapping[str, Any] data, str|None description=None, Mapping[str, str]|None description_placeholders=None, Mapping[str, Any]|None options=None)
ConfigFlowResult async_abort(self, *str reason, Mapping[str, str]|None description_placeholders=None)
None _async_abort_entries_match(self, dict[str, Any]|None match_dict=None)
ConfigFlowResult 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)
ConfigEntry config_entry(self)
None config_entry(self, ConfigEntry value)
_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)
_FlowResultT async_abort(self, *str reason, Mapping[str, str]|None description_placeholders=None)
IssData update(pyiss.ISS iss)
dict[str, Any] validate_input(HomeAssistant hass, dict[str, Any] data)
aiohttp.ClientSession async_get_clientsession(HomeAssistant hass, bool verify_ssl=True, socket.AddressFamily family=socket.AF_UNSPEC, ssl_util.SSLCipherList ssl_cipher=ssl_util.SSLCipherList.PYTHON_DEFAULT)