This commit is contained in:
G Johansson 2024-12-17 19:46:38 +00:00 committed by Franck Nijhof
parent 50e4311416
commit f1f45d6b5b
8 changed files with 65 additions and 7 deletions

View File

@ -3,7 +3,9 @@
from __future__ import annotations from __future__ import annotations
from collections.abc import Callable, Coroutine, Mapping from collections.abc import Callable, Coroutine, Mapping
from datetime import timedelta
from functools import partial from functools import partial
import logging
from typing import Any, cast from typing import Any, cast
import voluptuous as vol import voluptuous as vol
@ -13,6 +15,7 @@ from homeassistant.const import CONF_ENTITIES, CONF_TYPE
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import HomeAssistantError from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import entity_registry as er, selector from homeassistant.helpers import entity_registry as er, selector
from homeassistant.helpers.entity_platform import EntityPlatform
from homeassistant.helpers.schema_config_entry_flow import ( from homeassistant.helpers.schema_config_entry_flow import (
SchemaCommonFlowHandler, SchemaCommonFlowHandler,
SchemaConfigFlowHandler, SchemaConfigFlowHandler,
@ -48,6 +51,8 @@ _STATISTIC_MEASURES = [
"sum", "sum",
] ]
_LOGGER = logging.getLogger(__name__)
async def basic_group_options_schema( async def basic_group_options_schema(
domain: str | list[str], handler: SchemaCommonFlowHandler | None domain: str | list[str], handler: SchemaCommonFlowHandler | None
@ -424,6 +429,15 @@ def ws_start_preview(
) )
preview_entity.hass = hass preview_entity.hass = hass
preview_entity.registry_entry = entity_registry_entry preview_entity.registry_entry = entity_registry_entry
preview_entity.platform = EntityPlatform(
hass=hass,
logger=_LOGGER,
domain=group_type,
platform_name=DOMAIN,
platform=None,
scan_interval=timedelta(hours=1),
entity_namespace=None,
)
connection.send_result(msg["id"]) connection.send_result(msg["id"])
connection.subscriptions[msg["id"]] = preview_entity.async_start_preview( connection.subscriptions[msg["id"]] = preview_entity.async_start_preview(

View File

@ -3,15 +3,17 @@
from __future__ import annotations from __future__ import annotations
from collections.abc import Mapping from collections.abc import Mapping
from datetime import timedelta
from typing import Any, cast from typing import Any, cast
import voluptuous as vol import voluptuous as vol
from homeassistant.components import websocket_api from homeassistant.components import websocket_api
from homeassistant.components.sensor import SensorDeviceClass from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN, SensorDeviceClass
from homeassistant.const import CONF_NAME, Platform from homeassistant.const import CONF_NAME, Platform
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import HomeAssistantError from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.entity_platform import EntityPlatform
from homeassistant.helpers.schema_config_entry_flow import ( from homeassistant.helpers.schema_config_entry_flow import (
SchemaCommonFlowHandler, SchemaCommonFlowHandler,
SchemaConfigFlowHandler, SchemaConfigFlowHandler,
@ -36,7 +38,7 @@ from .const import (
DEFAULT_NAME, DEFAULT_NAME,
DOMAIN, DOMAIN,
) )
from .sensor import MoldIndicator from .sensor import _LOGGER, MoldIndicator
async def validate_input( async def validate_input(
@ -168,6 +170,15 @@ def ws_start_preview(
None, None,
) )
preview_entity.hass = hass preview_entity.hass = hass
preview_entity.platform = EntityPlatform(
hass=hass,
logger=_LOGGER,
domain=SENSOR_DOMAIN,
platform_name=DOMAIN,
platform=None,
scan_interval=timedelta(hours=1),
entity_namespace=None,
)
connection.send_result(msg["id"]) connection.send_result(msg["id"])
connection.subscriptions[msg["id"]] = preview_entity.async_start_preview( connection.subscriptions[msg["id"]] = preview_entity.async_start_preview(

View File

@ -1,5 +1,6 @@
"""OwnTracks Message handlers.""" """OwnTracks Message handlers."""
from datetime import timedelta
import json import json
import logging import logging
@ -9,6 +10,7 @@ from nacl.secret import SecretBox
from homeassistant.components import zone as zone_comp from homeassistant.components import zone as zone_comp
from homeassistant.components.device_tracker import SourceType from homeassistant.components.device_tracker import SourceType
from homeassistant.const import ATTR_LATITUDE, ATTR_LONGITUDE, STATE_HOME from homeassistant.const import ATTR_LATITUDE, ATTR_LONGITUDE, STATE_HOME
from homeassistant.helpers.entity_platform import EntityPlatform
from homeassistant.util import decorator, slugify from homeassistant.util import decorator, slugify
from .helper import supports_encryption from .helper import supports_encryption
@ -317,6 +319,15 @@ async def async_handle_waypoint(hass, name_base, waypoint):
) )
zone.hass = hass zone.hass = hass
zone.entity_id = entity_id zone.entity_id = entity_id
zone.platform = EntityPlatform(
hass=hass,
logger=_LOGGER,
domain="zone",
platform_name="owntracks",
platform=None,
scan_interval=timedelta(seconds=15),
entity_namespace=None,
)
zone.async_write_ha_state() zone.async_write_ha_state()

View File

@ -14,6 +14,7 @@ from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
from homeassistant.const import CONF_ENTITY_ID, CONF_NAME from homeassistant.const import CONF_ENTITY_ID, CONF_NAME
from homeassistant.core import HomeAssistant, callback, split_entity_id from homeassistant.core import HomeAssistant, callback, split_entity_id
from homeassistant.exceptions import HomeAssistantError from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.entity_platform import EntityPlatform
from homeassistant.helpers.schema_config_entry_flow import ( from homeassistant.helpers.schema_config_entry_flow import (
SchemaCommonFlowHandler, SchemaCommonFlowHandler,
SchemaConfigFlowHandler, SchemaConfigFlowHandler,
@ -37,6 +38,7 @@ from homeassistant.helpers.selector import (
from . import DOMAIN from . import DOMAIN
from .sensor import ( from .sensor import (
_LOGGER,
CONF_KEEP_LAST_SAMPLE, CONF_KEEP_LAST_SAMPLE,
CONF_MAX_AGE, CONF_MAX_AGE,
CONF_PERCENTILE, CONF_PERCENTILE,
@ -232,6 +234,15 @@ async def ws_start_preview(
msg["user_input"].get(CONF_PERCENTILE), msg["user_input"].get(CONF_PERCENTILE),
) )
preview_entity.hass = hass preview_entity.hass = hass
preview_entity.platform = EntityPlatform(
hass=hass,
logger=_LOGGER,
domain=SENSOR_DOMAIN,
platform_name=DOMAIN,
platform=None,
scan_interval=timedelta(hours=1),
entity_namespace=None,
)
connection.send_result(msg["id"]) connection.send_result(msg["id"])
connection.subscriptions[msg["id"]] = await preview_entity.async_start_preview( connection.subscriptions[msg["id"]] = await preview_entity.async_start_preview(

View File

@ -3,6 +3,7 @@
from __future__ import annotations from __future__ import annotations
from collections.abc import Mapping from collections.abc import Mapping
from datetime import timedelta
from typing import Any from typing import Any
import voluptuous as vol import voluptuous as vol
@ -13,6 +14,7 @@ from homeassistant.const import CONF_ENTITY_ID, CONF_NAME
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import HomeAssistantError from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import selector from homeassistant.helpers import selector
from homeassistant.helpers.entity_platform import EntityPlatform
from homeassistant.helpers.schema_config_entry_flow import ( from homeassistant.helpers.schema_config_entry_flow import (
SchemaCommonFlowHandler, SchemaCommonFlowHandler,
SchemaConfigFlowHandler, SchemaConfigFlowHandler,
@ -20,7 +22,7 @@ from homeassistant.helpers.schema_config_entry_flow import (
SchemaFlowFormStep, SchemaFlowFormStep,
) )
from .binary_sensor import ThresholdSensor from .binary_sensor import _LOGGER, ThresholdSensor
from .const import CONF_HYSTERESIS, CONF_LOWER, CONF_UPPER, DEFAULT_HYSTERESIS, DOMAIN from .const import CONF_HYSTERESIS, CONF_LOWER, CONF_UPPER, DEFAULT_HYSTERESIS, DOMAIN
@ -140,6 +142,15 @@ def ws_start_preview(
None, None,
) )
preview_entity.hass = hass preview_entity.hass = hass
preview_entity.platform = EntityPlatform(
hass=hass,
logger=_LOGGER,
domain=SENSOR_DOMAIN,
platform_name=DOMAIN,
platform=None,
scan_interval=timedelta(hours=1),
entity_namespace=None,
)
connection.send_result(msg["id"]) connection.send_result(msg["id"])
connection.subscriptions[msg["id"]] = preview_entity.async_start_preview( connection.subscriptions[msg["id"]] = preview_entity.async_start_preview(

View File

@ -211,6 +211,7 @@ def media_player_entity(
media_player.hass = hass media_player.hass = hass
media_player.platform = MockEntityPlatform(hass) media_player.platform = MockEntityPlatform(hass)
media_player.entity_id = "media_player.zone_3" media_player.entity_id = "media_player.zone_3"
media_player.platform = MockEntityPlatform(hass)
return media_player return media_player
@ -274,7 +275,6 @@ async def test_update(
hass: HomeAssistant, media_player_entity: MediaPlayerEntity hass: HomeAssistant, media_player_entity: MediaPlayerEntity
) -> None: ) -> None:
"""Test updating values from blackbird.""" """Test updating values from blackbird."""
assert media_player_entity.state == STATE_ON assert media_player_entity.state == STATE_ON
assert media_player_entity.source == "one" assert media_player_entity.source == "one"

View File

@ -36,8 +36,6 @@ def test_kira_sensor_callback(
assert sensor.name == "kira" assert sensor.name == "kira"
sensor.hass = hass
codeName = "FAKE_CODE" codeName = "FAKE_CODE"
deviceName = "FAKE_DEVICE" deviceName = "FAKE_DEVICE"
codeTuple = (codeName, deviceName) codeTuple = (codeName, deviceName)

View File

@ -39,6 +39,7 @@ from .common import (
) )
from tests.common import ( from tests.common import (
MockEntityPlatform,
MockModule, MockModule,
async_mock_service, async_mock_service,
mock_integration, mock_integration,
@ -58,9 +59,10 @@ class DefaultEntity(tts.TextToSpeechEntity):
_attr_default_language = DEFAULT_LANG _attr_default_language = DEFAULT_LANG
async def test_default_entity_attributes() -> None: async def test_default_entity_attributes(hass: HomeAssistant) -> None:
"""Test default entity attributes.""" """Test default entity attributes."""
entity = DefaultEntity() entity = DefaultEntity()
entity.platform = MockEntityPlatform(hass)
assert entity.hass is None assert entity.hass is None
assert entity.default_language == DEFAULT_LANG assert entity.default_language == DEFAULT_LANG