mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Move cert_expiry base entity to separate module (#126478)
This commit is contained in:
parent
49c9f843f8
commit
bed3fcfd43
23
homeassistant/components/cert_expiry/entity.py
Normal file
23
homeassistant/components/cert_expiry/entity.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
"""Counter for the days until an HTTPS (TLS) certificate will expire."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
|
from .coordinator import CertExpiryDataUpdateCoordinator
|
||||||
|
|
||||||
|
|
||||||
|
class CertExpiryEntity(CoordinatorEntity[CertExpiryDataUpdateCoordinator]):
|
||||||
|
"""Defines a base Cert Expiry entity."""
|
||||||
|
|
||||||
|
_attr_has_entity_name = True
|
||||||
|
|
||||||
|
@property
|
||||||
|
def extra_state_attributes(self) -> dict[str, Any]:
|
||||||
|
"""Return additional sensor state attributes."""
|
||||||
|
return {
|
||||||
|
"is_valid": self.coordinator.is_cert_valid,
|
||||||
|
"error": str(self.coordinator.cert_error),
|
||||||
|
}
|
@ -3,7 +3,6 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from typing import Any
|
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
@ -20,10 +19,11 @@ from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
|||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.event import async_call_later
|
from homeassistant.helpers.event import async_call_later
|
||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
|
||||||
|
|
||||||
from . import CertExpiryConfigEntry, CertExpiryDataUpdateCoordinator
|
from . import CertExpiryConfigEntry
|
||||||
from .const import DEFAULT_PORT, DOMAIN
|
from .const import DEFAULT_PORT, DOMAIN
|
||||||
|
from .coordinator import CertExpiryDataUpdateCoordinator
|
||||||
|
from .entity import CertExpiryEntity
|
||||||
|
|
||||||
SCAN_INTERVAL = timedelta(hours=12)
|
SCAN_INTERVAL = timedelta(hours=12)
|
||||||
|
|
||||||
@ -73,20 +73,6 @@ async def async_setup_entry(
|
|||||||
async_add_entities(sensors, True)
|
async_add_entities(sensors, True)
|
||||||
|
|
||||||
|
|
||||||
class CertExpiryEntity(CoordinatorEntity[CertExpiryDataUpdateCoordinator]):
|
|
||||||
"""Defines a base Cert Expiry entity."""
|
|
||||||
|
|
||||||
_attr_has_entity_name = True
|
|
||||||
|
|
||||||
@property
|
|
||||||
def extra_state_attributes(self) -> dict[str, Any]:
|
|
||||||
"""Return additional sensor state attributes."""
|
|
||||||
return {
|
|
||||||
"is_valid": self.coordinator.is_cert_valid,
|
|
||||||
"error": str(self.coordinator.cert_error),
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class SSLCertificateTimestamp(CertExpiryEntity, SensorEntity):
|
class SSLCertificateTimestamp(CertExpiryEntity, SensorEntity):
|
||||||
"""Implementation of the Cert Expiry timestamp sensor."""
|
"""Implementation of the Cert Expiry timestamp sensor."""
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user