hass-core/tests/components/teslemetry/__init__.py
Brett Adams 219cb7a788
Add additional sensors to Teslemetry (#112555)
* Add more sensors

* Fix coverage

* Dont do this rename yet

* Fix case

* Update snapshot

* Add icons

* Remove unused icons

* Update snapshot

* Remove last_value logic from TimeSensor

* Apply suggestions from code review

Co-authored-by: G Johansson <goran.johansson@shiftit.se>

* Update constant case

* Remove useless test

* Add refresh test back

* Add assertion to post coordinator refresh

---------

Co-authored-by: G Johansson <goran.johansson@shiftit.se>
2024-03-16 11:54:37 +01:00

65 lines
2 KiB
Python

"""Tests for the Teslemetry integration."""
from unittest.mock import patch
from syrupy import SnapshotAssertion
from homeassistant.components.teslemetry.const import DOMAIN
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
from .const import CONFIG
from tests.common import MockConfigEntry
async def setup_platform(hass: HomeAssistant, platforms: list[Platform] | None = None):
"""Set up the Teslemetry platform."""
mock_entry = MockConfigEntry(
domain=DOMAIN,
data=CONFIG,
)
mock_entry.add_to_hass(hass)
if platforms is None:
await hass.config_entries.async_setup(mock_entry.entry_id)
await hass.async_block_till_done()
else:
with patch("homeassistant.components.teslemetry.PLATFORMS", platforms):
await hass.config_entries.async_setup(mock_entry.entry_id)
await hass.async_block_till_done()
return mock_entry
def assert_entities(
hass: HomeAssistant,
entry_id: str,
entity_registry: er.EntityRegistry,
snapshot: SnapshotAssertion,
) -> None:
"""Test that all entities match their snapshot."""
entity_entries = er.async_entries_for_config_entry(entity_registry, entry_id)
assert entity_entries
for entity_entry in entity_entries:
assert entity_entry == snapshot(name=f"{entity_entry.entity_id}-entry")
assert (state := hass.states.get(entity_entry.entity_id))
assert state == snapshot(name=f"{entity_entry.entity_id}-state")
def assert_entities_alt(
hass: HomeAssistant,
entry_id: str,
entity_registry: er.EntityRegistry,
snapshot: SnapshotAssertion,
) -> None:
"""Test that all entities match their alt snapshot."""
entity_entries = er.async_entries_for_config_entry(entity_registry, entry_id)
assert entity_entries
for entity_entry in entity_entries:
assert (state := hass.states.get(entity_entry.entity_id))
assert state == snapshot(name=f"{entity_entry.entity_id}-statealt")