mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Add date platform (#81948)
This commit is contained in:
50
tests/testing_config/custom_components/test/date.py
Normal file
50
tests/testing_config/custom_components/test/date.py
Normal file
@@ -0,0 +1,50 @@
|
||||
"""Provide a mock date platform.
|
||||
|
||||
Call init before using it in your tests to ensure clean test data.
|
||||
"""
|
||||
from datetime import date
|
||||
|
||||
from homeassistant.components.date import DateEntity
|
||||
|
||||
from tests.common import MockEntity
|
||||
|
||||
UNIQUE_DATE = "unique_date"
|
||||
|
||||
ENTITIES = []
|
||||
|
||||
|
||||
class MockDateEntity(MockEntity, DateEntity):
|
||||
"""Mock date class."""
|
||||
|
||||
@property
|
||||
def native_value(self):
|
||||
"""Return the native value of this date."""
|
||||
return self._handle("native_value")
|
||||
|
||||
def set_value(self, value: date) -> None:
|
||||
"""Change the date."""
|
||||
self._values["native_value"] = value
|
||||
|
||||
|
||||
def init(empty=False):
|
||||
"""Initialize the platform with entities."""
|
||||
global ENTITIES
|
||||
|
||||
ENTITIES = (
|
||||
[]
|
||||
if empty
|
||||
else [
|
||||
MockDateEntity(
|
||||
name="test",
|
||||
unique_id=UNIQUE_DATE,
|
||||
native_value=date(2020, 1, 1),
|
||||
),
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_platform(
|
||||
hass, config, async_add_entities_callback, discovery_info=None
|
||||
):
|
||||
"""Return mock entities."""
|
||||
async_add_entities_callback(ENTITIES)
|
||||
Reference in New Issue
Block a user