Move Ping binary sensor attributes to sensor entities (#112004)
* Move Ping binary sensor attributes to sensor entities * Process code review * Update snapshot
This commit is contained in:
parent
6a243d6705
commit
25551fa938
11 changed files with 366 additions and 22 deletions
|
@ -18,11 +18,11 @@ import homeassistant.helpers.config_validation as cv
|
|||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from . import PingDomainData
|
||||
from .const import CONF_IMPORTED_BY, CONF_PING_COUNT, DEFAULT_PING_COUNT, DOMAIN
|
||||
from .coordinator import PingUpdateCoordinator
|
||||
from .entity import PingEntity
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -84,20 +84,18 @@ async def async_setup_entry(
|
|||
async_add_entities([PingBinarySensor(entry, data.coordinators[entry.entry_id])])
|
||||
|
||||
|
||||
class PingBinarySensor(CoordinatorEntity[PingUpdateCoordinator], BinarySensorEntity):
|
||||
class PingBinarySensor(PingEntity, BinarySensorEntity):
|
||||
"""Representation of a Ping Binary sensor."""
|
||||
|
||||
_attr_device_class = BinarySensorDeviceClass.CONNECTIVITY
|
||||
_attr_available = False
|
||||
_attr_name = None
|
||||
|
||||
def __init__(
|
||||
self, config_entry: ConfigEntry, coordinator: PingUpdateCoordinator
|
||||
) -> None:
|
||||
"""Initialize the Ping Binary sensor."""
|
||||
super().__init__(coordinator)
|
||||
|
||||
self._attr_name = config_entry.title
|
||||
self._attr_unique_id = config_entry.entry_id
|
||||
super().__init__(coordinator, config_entry.entry_id)
|
||||
|
||||
# if this was imported just enable it when it was enabled before
|
||||
if CONF_IMPORTED_BY in config_entry.data:
|
||||
|
@ -113,11 +111,9 @@ class PingBinarySensor(CoordinatorEntity[PingUpdateCoordinator], BinarySensorEnt
|
|||
@property
|
||||
def extra_state_attributes(self) -> dict[str, Any] | None:
|
||||
"""Return the state attributes of the ICMP checo request."""
|
||||
if self.coordinator.data.data is None:
|
||||
return None
|
||||
return {
|
||||
ATTR_ROUND_TRIP_TIME_AVG: self.coordinator.data.data["avg"],
|
||||
ATTR_ROUND_TRIP_TIME_MAX: self.coordinator.data.data["max"],
|
||||
ATTR_ROUND_TRIP_TIME_MDEV: self.coordinator.data.data["mdev"],
|
||||
ATTR_ROUND_TRIP_TIME_MIN: self.coordinator.data.data["min"],
|
||||
ATTR_ROUND_TRIP_TIME_AVG: self.coordinator.data.data.get("avg"),
|
||||
ATTR_ROUND_TRIP_TIME_MAX: self.coordinator.data.data.get("max"),
|
||||
ATTR_ROUND_TRIP_TIME_MDEV: self.coordinator.data.data.get("mdev"),
|
||||
ATTR_ROUND_TRIP_TIME_MIN: self.coordinator.data.data.get("min"),
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue