Migrate Cert Expiry to has entity name (#98160)
* Migrate Cert Expiry to has entity name * Migrate Cert Expiry to has entity name * Fix entity name
This commit is contained in:
parent
a9b1f23b7f
commit
dd69ba3136
4 changed files with 23 additions and 15 deletions
|
@ -77,6 +77,7 @@ class CertExpiryEntity(CoordinatorEntity[CertExpiryDataUpdateCoordinator]):
|
|||
"""Defines a base Cert Expiry entity."""
|
||||
|
||||
_attr_icon = "mdi:certificate"
|
||||
_attr_has_entity_name = True
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self):
|
||||
|
@ -91,6 +92,7 @@ class SSLCertificateTimestamp(CertExpiryEntity, SensorEntity):
|
|||
"""Implementation of the Cert Expiry timestamp sensor."""
|
||||
|
||||
_attr_device_class = SensorDeviceClass.TIMESTAMP
|
||||
_attr_translation_key = "certificate_expiry"
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
|
@ -98,7 +100,6 @@ class SSLCertificateTimestamp(CertExpiryEntity, SensorEntity):
|
|||
) -> None:
|
||||
"""Initialize a Cert Expiry timestamp sensor."""
|
||||
super().__init__(coordinator)
|
||||
self._attr_name = f"Cert Expiry Timestamp ({coordinator.name})"
|
||||
self._attr_unique_id = f"{coordinator.host}:{coordinator.port}-timestamp"
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, f"{coordinator.host}:{coordinator.port}")},
|
||||
|
|
|
@ -20,5 +20,12 @@
|
|||
"already_configured": "[%key:common::config_flow::abort::already_configured_service%]",
|
||||
"import_failed": "Import from config failed"
|
||||
}
|
||||
},
|
||||
"entity": {
|
||||
"sensor": {
|
||||
"certificate_expiry": {
|
||||
"name": "Cert expiry"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -99,7 +99,7 @@ async def test_unload_config_entry(mock_now, hass: HomeAssistant) -> None:
|
|||
await hass.async_block_till_done()
|
||||
|
||||
assert entry.state is ConfigEntryState.LOADED
|
||||
state = hass.states.get("sensor.cert_expiry_timestamp_example_com")
|
||||
state = hass.states.get("sensor.example_com_cert_expiry")
|
||||
assert state.state == timestamp.isoformat()
|
||||
assert state.attributes.get("error") == "None"
|
||||
assert state.attributes.get("is_valid")
|
||||
|
@ -107,12 +107,12 @@ async def test_unload_config_entry(mock_now, hass: HomeAssistant) -> None:
|
|||
await hass.config_entries.async_unload(entry.entry_id)
|
||||
|
||||
assert entry.state is ConfigEntryState.NOT_LOADED
|
||||
state = hass.states.get("sensor.cert_expiry_timestamp_example_com")
|
||||
state = hass.states.get("sensor.example_com_cert_expiry")
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
await hass.config_entries.async_remove(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("sensor.cert_expiry_timestamp_example_com")
|
||||
state = hass.states.get("sensor.example_com_cert_expiry")
|
||||
assert state is None
|
||||
|
||||
|
||||
|
@ -129,7 +129,7 @@ async def test_delay_load_during_startup(hass: HomeAssistant) -> None:
|
|||
assert hass.state is CoreState.not_running
|
||||
assert entry.state is ConfigEntryState.LOADED
|
||||
|
||||
state = hass.states.get("sensor.cert_expiry_timestamp_example_com")
|
||||
state = hass.states.get("sensor.example_com_cert_expiry")
|
||||
assert state is None
|
||||
|
||||
timestamp = future_timestamp(100)
|
||||
|
@ -142,7 +142,7 @@ async def test_delay_load_during_startup(hass: HomeAssistant) -> None:
|
|||
|
||||
assert hass.state is CoreState.running
|
||||
|
||||
state = hass.states.get("sensor.cert_expiry_timestamp_example_com")
|
||||
state = hass.states.get("sensor.example_com_cert_expiry")
|
||||
assert state.state == timestamp.isoformat()
|
||||
assert state.attributes.get("error") == "None"
|
||||
assert state.attributes.get("is_valid")
|
||||
|
|
|
@ -36,7 +36,7 @@ async def test_async_setup_entry(mock_now, hass: HomeAssistant) -> None:
|
|||
assert await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("sensor.cert_expiry_timestamp_example_com")
|
||||
state = hass.states.get("sensor.example_com_cert_expiry")
|
||||
assert state is not None
|
||||
assert state.state != STATE_UNAVAILABLE
|
||||
assert state.state == timestamp.isoformat()
|
||||
|
@ -62,7 +62,7 @@ async def test_async_setup_entry_bad_cert(hass: HomeAssistant) -> None:
|
|||
assert await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("sensor.cert_expiry_timestamp_example_com")
|
||||
state = hass.states.get("sensor.example_com_cert_expiry")
|
||||
assert state is not None
|
||||
assert state.state != STATE_UNAVAILABLE
|
||||
assert state.attributes.get("error") == "some error"
|
||||
|
@ -90,7 +90,7 @@ async def test_update_sensor(hass: HomeAssistant) -> None:
|
|||
assert await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("sensor.cert_expiry_timestamp_example_com")
|
||||
state = hass.states.get("sensor.example_com_cert_expiry")
|
||||
assert state is not None
|
||||
assert state.state != STATE_UNAVAILABLE
|
||||
assert state.state == timestamp.isoformat()
|
||||
|
@ -105,7 +105,7 @@ async def test_update_sensor(hass: HomeAssistant) -> None:
|
|||
async_fire_time_changed(hass, utcnow() + timedelta(hours=24))
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("sensor.cert_expiry_timestamp_example_com")
|
||||
state = hass.states.get("sensor.example_com_cert_expiry")
|
||||
assert state is not None
|
||||
assert state.state != STATE_UNAVAILABLE
|
||||
assert state.state == timestamp.isoformat()
|
||||
|
@ -134,7 +134,7 @@ async def test_update_sensor_network_errors(hass: HomeAssistant) -> None:
|
|||
assert await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("sensor.cert_expiry_timestamp_example_com")
|
||||
state = hass.states.get("sensor.example_com_cert_expiry")
|
||||
assert state is not None
|
||||
assert state.state != STATE_UNAVAILABLE
|
||||
assert state.state == timestamp.isoformat()
|
||||
|
@ -152,7 +152,7 @@ async def test_update_sensor_network_errors(hass: HomeAssistant) -> None:
|
|||
|
||||
next_update = starting_time + timedelta(hours=48)
|
||||
|
||||
state = hass.states.get("sensor.cert_expiry_timestamp_example_com")
|
||||
state = hass.states.get("sensor.example_com_cert_expiry")
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
with patch("homeassistant.util.dt.utcnow", return_value=next_update), patch(
|
||||
|
@ -162,7 +162,7 @@ async def test_update_sensor_network_errors(hass: HomeAssistant) -> None:
|
|||
async_fire_time_changed(hass, utcnow() + timedelta(hours=48))
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("sensor.cert_expiry_timestamp_example_com")
|
||||
state = hass.states.get("sensor.example_com_cert_expiry")
|
||||
assert state is not None
|
||||
assert state.state != STATE_UNAVAILABLE
|
||||
assert state.state == timestamp.isoformat()
|
||||
|
@ -178,7 +178,7 @@ async def test_update_sensor_network_errors(hass: HomeAssistant) -> None:
|
|||
async_fire_time_changed(hass, utcnow() + timedelta(hours=72))
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("sensor.cert_expiry_timestamp_example_com")
|
||||
state = hass.states.get("sensor.example_com_cert_expiry")
|
||||
assert state is not None
|
||||
assert state.state == STATE_UNKNOWN
|
||||
assert state.attributes.get("error") == "something bad"
|
||||
|
@ -192,5 +192,5 @@ async def test_update_sensor_network_errors(hass: HomeAssistant) -> None:
|
|||
async_fire_time_changed(hass, utcnow() + timedelta(hours=96))
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("sensor.cert_expiry_timestamp_example_com")
|
||||
state = hass.states.get("sensor.example_com_cert_expiry")
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
|
Loading…
Add table
Reference in a new issue