Fix error in last online sensor of PlayStation integration (#147844)

* Fix Last online sensor

* set unavailable

* available_fn
This commit is contained in:
Manu 2025-07-01 15:17:10 +02:00 committed by GitHub
parent 7deca35172
commit 651162b8e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -37,6 +37,7 @@ class PlaystationNetworkSensorEntityDescription(SensorEntityDescription):
value_fn: Callable[[PlaystationNetworkData], StateType | datetime]
entity_picture: str | None = None
available_fn: Callable[[PlaystationNetworkData], bool] = lambda _: True
class PlaystationNetworkSensor(StrEnum):
@ -117,6 +118,7 @@ SENSOR_DESCRIPTIONS: tuple[PlaystationNetworkSensorEntityDescription, ...] = (
psn.presence["basicPresence"]["lastAvailableDate"]
)
),
available_fn=lambda psn: "lastAvailableDate" in psn.presence["basicPresence"],
device_class=SensorDeviceClass.TIMESTAMP,
),
)
@ -183,3 +185,12 @@ class PlaystationNetworkSensorEntity(
)
return super().entity_picture
@property
def available(self) -> bool:
"""Return True if entity is available."""
return (
self.entity_description.available_fn(self.coordinator.data)
and super().available
)