Skip to content

Commit

Permalink
Move Playstation Plus Entity to Sensor Platform
Browse files Browse the repository at this point in the history
  • Loading branch information
JackJPowell committed Dec 1, 2024
1 parent 1eef373 commit 5b00d9e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion custom_components/playstation_network/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
PLATFORMS: list[Platform] = [
Platform.MEDIA_PLAYER,
Platform.SENSOR,
Platform.BINARY_SENSOR,
# Platform.BINARY_SENSOR,
Platform.IMAGE,
]

Expand Down
2 changes: 1 addition & 1 deletion custom_components/playstation_network/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self, coordinator) -> None:

ImageEntity.__init__(self, coordinator.hass)
self._attr_has_entity_name = True
self._attr_name = "Playstation Avatar"
self._attr_name = "Avatar"
self._attr_icon = "mdi:face-man-profile"
self._attr_image_url = self.get_avatar()
self._attr_image_last_updated = dt_util.utcnow()
Expand Down
2 changes: 1 addition & 1 deletion custom_components/playstation_network/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"dependencies": ["network"],
"documentation": "https://github.com/JackJPowell/hass-psn",
"homekit": {},
"integration_type": "device",
"integration_type": "service",
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/JackJPowell/hass-psn/issues",
"requirements": ["PSNAWP-HA==2.2.2"],
Expand Down
17 changes: 17 additions & 0 deletions custom_components/playstation_network/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ class PsnSensorEntityDescription(SensorEntityDescription):
description: str = ""


def get_ps_plus_status(coordinator_data: any) -> str:
if coordinator_data.get("profile", {}).get("isPlus"):
return "Active"
return "Inactive"


def get_status(coordinator_data: any) -> str:
"""Returns online status"""
match coordinator_data.get("platform").get("onlineStatus"):
Expand Down Expand Up @@ -168,6 +174,17 @@ def get_trophy_attr(coordinator_data: any) -> dict[str, str]:
value_fn=get_status,
attributes_fn=get_status_attr,
),
PsnSensorEntityDescription(
key="has_playstation_plus",
device_class=SensorDeviceClass.ENUM,
name="Playstation Plus",
icon="mdi:gamepad-outline",
options=["Active", "Inactive"],
entity_registry_enabled_default=True,
has_entity_name=True,
unique_id="has_playstation_plus",
value_fn=get_ps_plus_status,
),
)

PSN_ADDITIONAL_SENSOR: tuple[PsnSensorEntityDescription, ...] = (
Expand Down

0 comments on commit 5b00d9e

Please sign in to comment.