1
0
mirror of https://github.com/home-assistant/core.git synced 2026-04-27 12:14:35 +01:00

Add datetime platform (#81943)

Co-authored-by: Franck Nijhof <frenck@frenck.nl>
Co-authored-by: Franck Nijhof <git@frenck.dev>
This commit is contained in:
Raman Gupta
2023-05-29 17:24:15 -04:00
committed by GitHub
parent 940942a74a
commit 24290e5d08
17 changed files with 468 additions and 30 deletions

View File

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