Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: JackJPowell/hass-psn
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.7.0-beta.6
Choose a base ref
...
head repository: JackJPowell/hass-psn
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
  • 9 commits
  • 5 files changed
  • 3 contributors

Commits on Dec 13, 2024

  1. Copy the full SHA
    68719b6 View commit details

Commits on Dec 18, 2024

  1. Copy the full SHA
    655367e View commit details
  2. Merge pull request #27 from JackJPowell/about-me-sensor

    About Me as top level sensor
    JackJPowell authored Dec 18, 2024
    Copy the full SHA
    9315f37 View commit details

Commits on Dec 30, 2024

  1. Update sensor.py

    Added "play_duration_hrs" to display the play_duration in total hours.
    Edited "convert_time" to properly display the play_duration in total and formatted time.
    nichtlegacy authored Dec 30, 2024
    Copy the full SHA
    a3c73e5 View commit details

Commits on Jan 4, 2025

  1. Update README.md

    JackJPowell authored Jan 4, 2025
    Copy the full SHA
    fcf1ad2 View commit details

Commits on Jan 12, 2025

  1. Create fr.json

    add French translation
    barto95100 authored and JackJPowell committed Jan 12, 2025
    Copy the full SHA
    d567e57 View commit details
  2. Update fr.json

    barto95100 authored and JackJPowell committed Jan 12, 2025
    Copy the full SHA
    089cdb5 View commit details
  3. Copy the full SHA
    857b410 View commit details
  4. Merge pull request #30 from nichtlegacy:patch-1

    Update sensor.py
    JackJPowell authored Jan 12, 2025
    Copy the full SHA
    84c19d7 View commit details
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![GitHub Release](https://img.shields.io/github/v/release/jackjpowell/hass-psn)
![GitHub Downloads (all assets, all releases)](https://img.shields.io/github/downloads/jackjpowell/hass-psn/total)
<a href="#"><img src="https://img.shields.io/maintenance/yes/2024.svg"></a>
<a href="#"><img src="https://img.shields.io/maintenance/yes/2025.svg"></a>
[![Buy Me A Coffee](https://img.shields.io/badge/Buy_Me_A_Coffee&nbsp;☕-FFDD00?logo=buy-me-a-coffee&logoColor=white&labelColor=grey)](https://buymeacoffee.com/jackpowell)

<picture>
20 changes: 19 additions & 1 deletion custom_components/playstation_network/__init__.py
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@
from psnawp_api.core.psnawp_exceptions import PSNAWPAuthenticationError
from psnawp_api.psnawp import PSNAWP

from .const import DOMAIN, PSN_API, PSN_COORDINATOR
from .const import DOMAIN, PSN_API, PSN_COORDINATOR, CONF_EXPOSE_ATTRIBUTES_AS_ENTITIES
from .coordinator import PsnCoordinator

PLATFORMS: list[Platform] = [
@@ -95,6 +95,10 @@ def async_migrate_entity_entry(entry: er.RegistryEntry) -> dict[str, Any] | None
_migrate_device_identifiers(hass, entry.entry_id, coordinator)
hass.config_entries.async_update_entry(entry, version=2)

if entry.version < 3:
_remove_option_sensor(hass, entry, coordinator)
hass.config_entries.async_update_entry(entry, version=3)

await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
entry.async_on_unload(entry.add_update_listener(update_listener))
return True
@@ -132,3 +136,17 @@ def _migrate_device_identifiers(
"migrate identifier '%s' to '%s'", device.identifiers, new_identifier
)
dev_reg.async_update_device(device.id, new_identifiers=new_identifier)


def _remove_option_sensor(
hass: HomeAssistant, entry: ConfigEntry, coordinator: PsnCoordinator
) -> None:
if entry.options.get(CONF_EXPOSE_ATTRIBUTES_AS_ENTITIES) is True:
entity_registry = er.async_get(hass)
entity_id = entity_registry.async_get_entity_id(
"sensor",
DOMAIN,
f"{coordinator.data.get("username").lower()}_psn_about_me_attr",
)
if entity_id:
entity_registry.async_remove(entity_id)
2 changes: 1 addition & 1 deletion custom_components/playstation_network/manifest.json
Original file line number Diff line number Diff line change
@@ -11,5 +11,5 @@
"issue_tracker": "https://github.com/JackJPowell/hass-psn/issues",
"requirements": ["PSNAWP-HA==2.2.2"],
"ssdp": [],
"version": "0.7.0"
"version": "0.7.1"
}
48 changes: 33 additions & 15 deletions custom_components/playstation_network/sensor.py
Original file line number Diff line number Diff line change
@@ -114,20 +114,36 @@ def get_status_attr(coordinator_data: any) -> dict[str, str]:
break

attrs["play_count"] = title_stats.play_count
attrs["play_duration"] = convert_time(duration=title_stats.play_duration)

formatted_duration, hours_duration = convert_time(
duration=title_stats.play_duration
)
attrs["play_duration"] = formatted_duration
attrs["play_duration_hours"] = hours_duration

return attrs


def convert_time(duration: datetime) -> str:
def convert_time(duration: datetime) -> tuple[str, str]:
minutes, seconds = divmod(duration.seconds, 60)
hours, minutes = divmod(minutes, 60)

"""Calculate total hours including days"""
total_hours = duration.days * 24 + hours
total_minutes = minutes

"""Original formatted string"""
if duration.days > 1:
return f"{duration.days} Days {hours}h"
formatted_time = f"{duration.days} Days {hours}h"
elif duration.days == 1:
return f"{duration.days} Day {hours}h"
formatted_time = f"{duration.days} Day {hours}h"
else:
return f"{hours}h {minutes}m"
formatted_time = f"{hours}h {minutes}m"

"""Hours format with minutes"""
hours_format = f"{total_hours}h {total_minutes}min"

return formatted_time, hours_format


def get_trophy_attr(coordinator_data: any) -> dict[str, str]:
@@ -185,6 +201,16 @@ def get_trophy_attr(coordinator_data: any) -> dict[str, str]:
unique_id="has_playstation_plus",
value_fn=get_ps_plus_status,
),
PsnSensorEntityDescription(
key="about_me",
native_unit_of_measurement=None,
name="About Me",
icon="mdi:comment-text-outline",
entity_registry_enabled_default=True,
has_entity_name=True,
unique_id="about_me",
value_fn=lambda data: data.get("profile").get("aboutMe"),
),
)

PSN_ADDITIONAL_SENSOR: tuple[PsnSensorEntityDescription, ...] = (
@@ -198,16 +224,6 @@ def get_trophy_attr(coordinator_data: any) -> dict[str, str]:
unique_id="psn_title_name_attr",
value_fn=lambda data: data.get("name"),
),
PsnSensorEntityDescription(
key="about_me",
native_unit_of_measurement=None,
name="About Me",
icon="mdi:information-outline",
entity_registry_enabled_default=True,
has_entity_name=True,
unique_id="psn_about_me_attr",
value_fn=lambda data: data.get("about_me"),
),
PsnSensorEntityDescription(
key="platform",
native_unit_of_measurement=None,
@@ -420,6 +436,8 @@ def extra_state_attributes(self) -> dict[str, str]:
"""Return the state attributes of the entity."""
if self.coordinator.data.get("title_metadata").get("npTitleId") is not None:
return self.entity_description.attributes_fn(self.coordinator.data)
if self.entity_description.key == "trophy_summary":
return self.entity_description.attributes_fn(self.coordinator.data)


class PsnAttributeSensor(PSNEntity, SensorEntity):
37 changes: 37 additions & 0 deletions custom_components/playstation_network/translations/fr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"config": {
"abort": {
"already_configured": "L'appareil est déjà configuré",
"already_in_progress": "L'appareil est en attente de configuration.",
"reauth_successful": "La réauthentification a réussi."
},
"error": {
"cannot_connect": "La connexion a échoué",
"invalid_auth": "Authentification invalide.",
"unknown": "Erreur inattendue"
},
"step": {
"user": {
"data": {
"npsso": "Code NPSSO"
}
},
"reauth_confirm": {
"data": {
"npsso": "Code NPSSO"
},
"title": "Réauthentification avec un nouveau code de l'ONSSP"
}
}
},
"options": {
"step": {
"entities": {
"title": "Option Playstation Network",
"data": {
"attributes_as_entities": "Créer des attributs supplémentaires en tant qu'entités"
}
}
}
}
}