async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): """Create the Tautulli sensor.""" name = config.get(CONF_NAME) host = config[CONF_HOST] port = config.get(CONF_PORT) path = config.get(CONF_PATH) api_key = config[CONF_API_KEY] monitored_conditions = config.get(CONF_MONITORED_CONDITIONS) user = config.get(CONF_MONITORED_USERS) use_ssl = config[CONF_SSL] verify_ssl = config.get(CONF_VERIFY_SSL) session = async_get_clientsession(hass, verify_ssl) api_client = PyTautulli( api_token=api_key, hostname=host, session=session, verify_ssl=verify_ssl, port=port, ssl=use_ssl, base_api_path=path, ) coordinator = TautulliDataUpdateCoordinator(hass=hass, api_client=api_client) entities = [TautulliSensor(coordinator, name, monitored_conditions, user)] async_add_entities(entities, True)
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): """Create the Tautulli sensor.""" name = config.get(CONF_NAME) host = config[CONF_HOST] port = config.get(CONF_PORT) path = config.get(CONF_PATH) api_key = config[CONF_API_KEY] monitored_conditions = config.get(CONF_MONITORED_CONDITIONS) user = config.get(CONF_MONITORED_USERS) use_ssl = config[CONF_SSL] verify_ssl = config.get(CONF_VERIFY_SSL) session = async_get_clientsession(hass, verify_ssl) tautulli = TautulliData( PyTautulli( api_token=api_key, hostname=host, session=session, verify_ssl=verify_ssl, port=port, ssl=use_ssl, base_api_path=path, )) await tautulli.async_update() if not tautulli.activity or not tautulli.home_stats or not tautulli.users: raise PlatformNotReady sensor = [TautulliSensor(tautulli, name, monitored_conditions, user)] async_add_entities(sensor, True)
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up Tautulli from a config entry.""" host_configuration = PyTautulliHostConfiguration( api_token=entry.data[CONF_API_KEY], url=entry.data[CONF_URL], verify_ssl=entry.data[CONF_VERIFY_SSL], ) api_client = PyTautulli( host_configuration=host_configuration, session=async_get_clientsession(hass, entry.data[CONF_VERIFY_SSL]), ) coordinator = TautulliDataUpdateCoordinator(hass, host_configuration, api_client) await coordinator.async_config_entry_first_refresh() hass.data[DOMAIN] = coordinator await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) return True
async def validate_input(self, user_input: dict[str, Any]) -> str | None: """Try connecting to Tautulli.""" try: api_client = PyTautulli( api_token=user_input[CONF_API_KEY], url=user_input[CONF_URL], session=async_get_clientsession( self.hass, user_input.get(CONF_VERIFY_SSL, True)), verify_ssl=user_input.get(CONF_VERIFY_SSL, True), ) await api_client.async_get_server_info() except exceptions.PyTautulliConnectionException: return "cannot_connect" except exceptions.PyTautulliAuthenticationException: return "invalid_auth" except PyTautulliException: return "unknown" return None
async def async_setup_platform( hass: HomeAssistant, config: ConfigType, async_add_entities: AddEntitiesCallback, discovery_info: DiscoveryInfoType | None = None, ) -> None: """Create the Tautulli sensor.""" name = config[CONF_NAME] host = config[CONF_HOST] port = config[CONF_PORT] path = config[CONF_PATH] api_key = config[CONF_API_KEY] monitored_conditions = config.get(CONF_MONITORED_CONDITIONS, []) users = config.get(CONF_MONITORED_USERS, []) use_ssl = config[CONF_SSL] verify_ssl = config[CONF_VERIFY_SSL] session = async_get_clientsession(hass=hass, verify_ssl=verify_ssl) api_client = PyTautulli( api_token=api_key, hostname=host, session=session, verify_ssl=verify_ssl, port=port, ssl=use_ssl, base_api_path=path, ) coordinator = TautulliDataUpdateCoordinator(hass=hass, api_client=api_client) async_add_entities( new_entities=[ TautulliSensor( coordinator=coordinator, name=name, monitored_conditions=monitored_conditions, usernames=users, ) ], update_before_add=True, )