1
0
mirror of https://github.com/home-assistant/core.git synced 2026-04-28 12:43:44 +01:00

Use setup_test_component_platform helper for time entity component tests instead of hass.components (#114411)

This commit is contained in:
Jan-Philipp Benecke
2024-03-29 07:34:00 +01:00
committed by GitHub
parent ae635a5586
commit a102230498
3 changed files with 30 additions and 66 deletions

View File

@@ -1,51 +0,0 @@
"""Provide a mock time platform.
Call init before using it in your tests to ensure clean test data.
"""
from datetime import time
from homeassistant.components.time import TimeEntity
from tests.common import MockEntity
UNIQUE_TIME = "unique_time"
ENTITIES = []
class MockTimeEntity(MockEntity, TimeEntity):
"""Mock time class."""
@property
def native_value(self):
"""Return the native value of this time."""
return self._handle("native_value")
def set_value(self, value: time) -> None:
"""Change the time."""
self._values["native_value"] = value
def init(empty=False):
"""Initialize the platform with entities."""
global ENTITIES
ENTITIES = (
[]
if empty
else [
MockTimeEntity(
name="test",
unique_id=UNIQUE_TIME,
native_value=time(1, 2, 3),
),
]
)
async def async_setup_platform(
hass, config, async_add_entities_callback, discovery_info=None
):
"""Return mock entities."""
async_add_entities_callback(ENTITIES)