mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 06:07:17 +00:00
Fix error in last online sensor of PlayStation integration (#147844)
* Fix Last online sensor * set unavailable * available_fn
This commit is contained in:
parent
7deca35172
commit
651162b8e7
@ -37,6 +37,7 @@ class PlaystationNetworkSensorEntityDescription(SensorEntityDescription):
|
|||||||
|
|
||||||
value_fn: Callable[[PlaystationNetworkData], StateType | datetime]
|
value_fn: Callable[[PlaystationNetworkData], StateType | datetime]
|
||||||
entity_picture: str | None = None
|
entity_picture: str | None = None
|
||||||
|
available_fn: Callable[[PlaystationNetworkData], bool] = lambda _: True
|
||||||
|
|
||||||
|
|
||||||
class PlaystationNetworkSensor(StrEnum):
|
class PlaystationNetworkSensor(StrEnum):
|
||||||
@ -117,6 +118,7 @@ SENSOR_DESCRIPTIONS: tuple[PlaystationNetworkSensorEntityDescription, ...] = (
|
|||||||
psn.presence["basicPresence"]["lastAvailableDate"]
|
psn.presence["basicPresence"]["lastAvailableDate"]
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
|
available_fn=lambda psn: "lastAvailableDate" in psn.presence["basicPresence"],
|
||||||
device_class=SensorDeviceClass.TIMESTAMP,
|
device_class=SensorDeviceClass.TIMESTAMP,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@ -183,3 +185,12 @@ class PlaystationNetworkSensorEntity(
|
|||||||
)
|
)
|
||||||
|
|
||||||
return super().entity_picture
|
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
|
||||||
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user