Always setup demo platforms with device support from config entry (#94586)
* Always setup demo platforms with device support from config entry * Adjust test fixutres * Update tests depending on the demo integration
This commit is contained in:
parent
1b8c72e644
commit
9a3077d64a
54 changed files with 491 additions and 351 deletions
|
@ -5,22 +5,19 @@ from datetime import datetime, timezone
|
|||
|
||||
from homeassistant.components.datetime import DateTimeEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import DEVICE_DEFAULT_NAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
from . import DOMAIN
|
||||
|
||||
|
||||
async def async_setup_platform(
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up the Demo date/time entity."""
|
||||
"""Set up the demo datetime platform."""
|
||||
async_add_entities(
|
||||
[
|
||||
DemoDateTime(
|
||||
|
@ -34,24 +31,16 @@ async def async_setup_platform(
|
|||
)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Demo config entry."""
|
||||
await async_setup_platform(hass, {}, async_add_entities)
|
||||
|
||||
|
||||
class DemoDateTime(DateTimeEntity):
|
||||
"""Representation of a Demo date/time entity."""
|
||||
|
||||
_attr_has_entity_name = True
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
unique_id: str,
|
||||
name: str,
|
||||
device_name: str,
|
||||
state: datetime,
|
||||
icon: str,
|
||||
assumed_state: bool,
|
||||
|
@ -59,7 +48,6 @@ class DemoDateTime(DateTimeEntity):
|
|||
"""Initialize the Demo date/time entity."""
|
||||
self._attr_assumed_state = assumed_state
|
||||
self._attr_icon = icon
|
||||
self._attr_name = name or DEVICE_DEFAULT_NAME
|
||||
self._attr_native_value = state
|
||||
self._attr_unique_id = unique_id
|
||||
|
||||
|
@ -68,7 +56,7 @@ class DemoDateTime(DateTimeEntity):
|
|||
# Serial numbers are unique identifiers within a specific domain
|
||||
(DOMAIN, unique_id)
|
||||
},
|
||||
name=self.name,
|
||||
name=device_name,
|
||||
)
|
||||
|
||||
async def async_set_value(self, value: datetime) -> None:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue