Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions homeassistant/components/playstation_network/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
SensorDeviceClass,
SensorEntity,
SensorEntityDescription,
SensorStateClass,
)
from homeassistant.const import PERCENTAGE
from homeassistant.core import HomeAssistant
Expand Down Expand Up @@ -61,6 +62,7 @@ class PlaystationNetworkSensor(StrEnum):
value_fn=(
lambda psn: psn.trophy_summary.trophy_level if psn.trophy_summary else None
),
state_class=SensorStateClass.MEASUREMENT,
),
PlaystationNetworkSensorEntityDescription(
key=PlaystationNetworkSensor.TROPHY_LEVEL_PROGRESS,
Expand All @@ -69,6 +71,7 @@ class PlaystationNetworkSensor(StrEnum):
lambda psn: psn.trophy_summary.progress if psn.trophy_summary else None
),
native_unit_of_measurement=PERCENTAGE,
state_class=SensorStateClass.MEASUREMENT,
),
PlaystationNetworkSensorEntityDescription(
key=PlaystationNetworkSensor.EARNED_TROPHIES_PLATINUM,
Expand All @@ -80,6 +83,7 @@ class PlaystationNetworkSensor(StrEnum):
else None
)
),
state_class=SensorStateClass.MEASUREMENT,
),
PlaystationNetworkSensorEntityDescription(
key=PlaystationNetworkSensor.EARNED_TROPHIES_GOLD,
Expand All @@ -89,6 +93,7 @@ class PlaystationNetworkSensor(StrEnum):
psn.trophy_summary.earned_trophies.gold if psn.trophy_summary else None
)
),
state_class=SensorStateClass.MEASUREMENT,
),
PlaystationNetworkSensorEntityDescription(
key=PlaystationNetworkSensor.EARNED_TROPHIES_SILVER,
Expand All @@ -100,6 +105,7 @@ class PlaystationNetworkSensor(StrEnum):
else None
)
),
state_class=SensorStateClass.MEASUREMENT,
),
PlaystationNetworkSensorEntityDescription(
key=PlaystationNetworkSensor.EARNED_TROPHIES_BRONZE,
Expand All @@ -111,6 +117,7 @@ class PlaystationNetworkSensor(StrEnum):
else None
)
),
state_class=SensorStateClass.MEASUREMENT,
),
PlaystationNetworkSensorEntityDescription(
key=PlaystationNetworkSensor.ONLINE_ID,
Expand Down
34 changes: 34 additions & 0 deletions homeassistant/components/splunk/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,40 @@ async def async_step_import(
data=import_config,
)

async def async_step_reconfigure(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Handle reconfiguration of the Splunk integration."""
errors: dict[str, str] = {}

if user_input is not None:
errors = await self._async_validate_input(user_input)

if not errors:
return self.async_update_reload_and_abort(
self._get_reconfigure_entry(),
data_updates=user_input,
title=f"{user_input[CONF_HOST]}:{user_input[CONF_PORT]}",
)

return self.async_show_form(
step_id="reconfigure",
data_schema=self.add_suggested_values_to_schema(
vol.Schema(
{
vol.Required(CONF_TOKEN): str,
vol.Required(CONF_HOST): str,
vol.Optional(CONF_PORT, default=DEFAULT_PORT): int,
vol.Optional(CONF_SSL, default=False): bool,
vol.Optional(CONF_VERIFY_SSL, default=True): bool,
vol.Optional(CONF_NAME): str,
}
),
self._get_reconfigure_entry().data,
),
errors=errors,
)

async def async_step_reauth(
self, entry_data: Mapping[str, Any]
) -> ConfigFlowResult:
Expand Down
6 changes: 1 addition & 5 deletions homeassistant/components/splunk/quality_scale.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,7 @@ rules:
status: exempt
comment: |
Integration does not create entities.
reconfiguration-flow:
status: todo
comment: |
Consider adding reconfiguration flow to allow users to update host, port, entity filter, and SSL settings without deleting and re-adding the config entry.

reconfiguration-flow: done
# Platinum
async-dependency:
status: todo
Expand Down
20 changes: 20 additions & 0 deletions homeassistant/components/splunk/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
"invalid_config": "The YAML configuration is invalid and cannot be imported. Please check your configuration.yaml file.",
"reauth_successful": "[%key:common::config_flow::abort::reauth_successful%]",
"reconfigure_successful": "[%key:common::config_flow::abort::reconfigure_successful%]",
"single_instance_allowed": "[%key:common::config_flow::abort::single_instance_allowed%]",
"unknown": "[%key:common::config_flow::error::unknown%]"
},
Expand All @@ -26,6 +27,25 @@
"description": "The Splunk token is no longer valid. Please enter a new HTTP Event Collector token.",
"title": "Reauthenticate Splunk"
},
"reconfigure": {
"data": {
"host": "[%key:common::config_flow::data::host%]",
"name": "[%key:common::config_flow::data::name%]",
"port": "[%key:common::config_flow::data::port%]",
"ssl": "[%key:common::config_flow::data::ssl%]",
"token": "HTTP Event Collector token",
"verify_ssl": "[%key:common::config_flow::data::verify_ssl%]"
},
"data_description": {
"host": "[%key:component::splunk::config::step::user::data_description::host%]",
"name": "[%key:component::splunk::config::step::user::data_description::name%]",
"port": "[%key:component::splunk::config::step::user::data_description::port%]",
"ssl": "[%key:component::splunk::config::step::user::data_description::ssl%]",
"token": "[%key:component::splunk::config::step::user::data_description::token%]",
"verify_ssl": "[%key:component::splunk::config::step::user::data_description::verify_ssl%]"
},
"description": "Update your Splunk HTTP Event Collector connection settings."
},
"user": {
"data": {
"host": "[%key:common::config_flow::data::host%]",
Expand Down
43 changes: 27 additions & 16 deletions homeassistant/components/xbox/api.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
"""API for xbox bound to Home Assistant OAuth."""

from http import HTTPStatus

from aiohttp.client_exceptions import ClientResponseError
from httpx import AsyncClient
from aiohttp import ClientError
from httpx import AsyncClient, HTTPStatusError, RequestError
from pythonxbox.authentication.manager import AuthenticationManager
from pythonxbox.authentication.models import OAuth2TokenResponse
from pythonxbox.common.exceptions import AuthenticationException

from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
from homeassistant.exceptions import (
ConfigEntryAuthFailed,
ConfigEntryNotReady,
OAuth2TokenRequestReauthError,
OAuth2TokenRequestTransientError,
)
from homeassistant.helpers.config_entry_oauth2_flow import OAuth2Session
from homeassistant.util.dt import utc_from_timestamp

Expand All @@ -30,24 +34,31 @@ async def refresh_tokens(self) -> None:
if not self._oauth_session.valid_token:
try:
await self._oauth_session.async_ensure_token_valid()
except ClientResponseError as e:
if (
HTTPStatus.BAD_REQUEST
<= e.status
< HTTPStatus.INTERNAL_SERVER_ERROR
):
raise ConfigEntryAuthFailed(
translation_domain=DOMAIN,
translation_key="auth_exception",
) from e
except OAuth2TokenRequestReauthError as e:
raise ConfigEntryAuthFailed(
translation_domain=DOMAIN,
translation_key="auth_exception",
) from e
except (OAuth2TokenRequestTransientError, ClientError) as e:
raise ConfigEntryNotReady(
translation_domain=DOMAIN,
translation_key="request_exception",
) from e
self.oauth = self._get_oauth_token()

# This will skip the OAuth refresh and only refresh User and XSTS tokens
await super().refresh_tokens()
try:
await super().refresh_tokens()
except AuthenticationException as e:
raise ConfigEntryAuthFailed(
translation_domain=DOMAIN,
translation_key="auth_exception",
) from e
except (RequestError, HTTPStatusError) as e:
raise ConfigEntryNotReady(
translation_domain=DOMAIN,
translation_key="request_exception",
) from e

def _get_oauth_token(self) -> OAuth2TokenResponse:
tokens = {**self._oauth_session.token}
Expand Down
4 changes: 4 additions & 0 deletions homeassistant/components/xbox/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ def title_logo(_: Person, title: Title | None) -> str | None:
key=XboxSensor.GAMER_SCORE,
translation_key=XboxSensor.GAMER_SCORE,
value_fn=lambda x, _: x.gamer_score,
state_class=SensorStateClass.MEASUREMENT,
),
XboxSensorEntityDescription(
key=XboxSensor.ACCOUNT_TIER,
Expand Down Expand Up @@ -187,11 +188,13 @@ def title_logo(_: Person, title: Title | None) -> str | None:
key=XboxSensor.FOLLOWING,
translation_key=XboxSensor.FOLLOWING,
value_fn=lambda x, _: x.detail.following_count if x.detail else None,
state_class=SensorStateClass.MEASUREMENT,
),
XboxSensorEntityDescription(
key=XboxSensor.FOLLOWER,
translation_key=XboxSensor.FOLLOWER,
value_fn=lambda x, _: x.detail.follower_count if x.detail else None,
state_class=SensorStateClass.MEASUREMENT,
),
XboxSensorEntityDescription(
key=XboxSensor.NOW_PLAYING,
Expand All @@ -204,6 +207,7 @@ def title_logo(_: Person, title: Title | None) -> str | None:
key=XboxSensor.FRIENDS,
translation_key=XboxSensor.FRIENDS,
value_fn=lambda x, _: x.detail.friend_count if x.detail else None,
state_class=SensorStateClass.MEASUREMENT,
),
XboxSensorEntityDescription(
key=XboxSensor.IN_PARTY,
Expand Down
Loading
Loading