Add config flow to Uptime (#67408)

This commit is contained in:
Franck Nijhof 2022-03-12 12:36:08 +01:00 committed by GitHub
parent 23b8229143
commit 0467dc55fe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 308 additions and 20 deletions

View file

@ -1,11 +1,27 @@
"""The tests for the uptime sensor platform."""
import pytest
from homeassistant.setup import async_setup_component
from homeassistant.components.sensor import SensorDeviceClass
from homeassistant.const import ATTR_DEVICE_CLASS
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
from tests.common import MockConfigEntry
async def test_uptime_sensor_name_change(hass):
"""Test uptime sensor with different name."""
config = {"sensor": {"platform": "uptime", "name": "foobar"}}
assert await async_setup_component(hass, "sensor", config)
await hass.async_block_till_done()
assert hass.states.get("sensor.foobar")
@pytest.mark.freeze_time("2022-03-01 00:00:00+00:00")
async def test_uptime_sensor(
hass: HomeAssistant,
init_integration: MockConfigEntry,
) -> None:
"""Test Uptime sensor."""
state = hass.states.get("sensor.uptime")
assert state
assert state.state == "2022-03-01T00:00:00+00:00"
assert state.attributes["friendly_name"] == "Uptime"
assert state.attributes[ATTR_DEVICE_CLASS] == SensorDeviceClass.TIMESTAMP
entity_registry = er.async_get(hass)
entry = entity_registry.async_get("sensor.uptime")
assert entry
assert entry.unique_id == init_integration.entry_id