Add missing hass type in tests/helpers (#124039)
This commit is contained in:
parent
2cd4456762
commit
56b4a7f291
8 changed files with 146 additions and 61 deletions
|
@ -873,7 +873,9 @@ async def test_implementation_provider(hass: HomeAssistant, local_impl) -> None:
|
||||||
|
|
||||||
provider_source = []
|
provider_source = []
|
||||||
|
|
||||||
async def async_provide_implementation(hass, domain):
|
async def async_provide_implementation(
|
||||||
|
hass: HomeAssistant, domain: str
|
||||||
|
) -> list[config_entry_oauth2_flow.AbstractOAuth2Implementation]:
|
||||||
"""Mock implementation provider."""
|
"""Mock implementation provider."""
|
||||||
return provider_source
|
return provider_source
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,8 @@ from homeassistant.const import Platform
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers import discovery
|
from homeassistant.helpers import discovery
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||||
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
|
|
||||||
from tests.common import MockModule, MockPlatform, mock_integration, mock_platform
|
from tests.common import MockModule, MockPlatform, mock_integration, mock_platform
|
||||||
|
|
||||||
|
@ -115,7 +117,7 @@ async def test_circular_import(hass: HomeAssistant) -> None:
|
||||||
component_calls = []
|
component_calls = []
|
||||||
platform_calls = []
|
platform_calls = []
|
||||||
|
|
||||||
def component_setup(hass, config):
|
def component_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
"""Set up mock component."""
|
"""Set up mock component."""
|
||||||
discovery.load_platform(
|
discovery.load_platform(
|
||||||
hass, Platform.SWITCH, "test_circular", {"key": "value"}, config
|
hass, Platform.SWITCH, "test_circular", {"key": "value"}, config
|
||||||
|
@ -123,7 +125,12 @@ async def test_circular_import(hass: HomeAssistant) -> None:
|
||||||
component_calls.append(1)
|
component_calls.append(1)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def setup_platform(hass, config, add_entities_callback, discovery_info=None):
|
def setup_platform(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config: ConfigType,
|
||||||
|
add_entities_callback: AddEntitiesCallback,
|
||||||
|
discovery_info: DiscoveryInfoType | None = None,
|
||||||
|
) -> None:
|
||||||
"""Set up mock platform."""
|
"""Set up mock platform."""
|
||||||
platform_calls.append("disc" if discovery_info else "component")
|
platform_calls.append("disc" if discovery_info else "component")
|
||||||
|
|
||||||
|
@ -162,14 +169,14 @@ async def test_1st_discovers_2nd_component(hass: HomeAssistant) -> None:
|
||||||
"""
|
"""
|
||||||
component_calls = []
|
component_calls = []
|
||||||
|
|
||||||
async def component1_setup(hass, config):
|
async def component1_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
"""Set up mock component."""
|
"""Set up mock component."""
|
||||||
await discovery.async_discover(
|
await discovery.async_discover(
|
||||||
hass, "test_component2", {}, "test_component2", {}
|
hass, "test_component2", {}, "test_component2", {}
|
||||||
)
|
)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def component2_setup(hass, config):
|
def component2_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
"""Set up mock component."""
|
"""Set up mock component."""
|
||||||
component_calls.append(1)
|
component_calls.append(1)
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -16,6 +16,7 @@ import pytest
|
||||||
from syrupy.assertion import SnapshotAssertion
|
from syrupy.assertion import SnapshotAssertion
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_ATTRIBUTION,
|
ATTR_ATTRIBUTION,
|
||||||
ATTR_DEVICE_CLASS,
|
ATTR_DEVICE_CLASS,
|
||||||
|
@ -34,6 +35,7 @@ from homeassistant.core import (
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers import device_registry as dr, entity, entity_registry as er
|
from homeassistant.helpers import device_registry as dr, entity, entity_registry as er
|
||||||
from homeassistant.helpers.entity_component import async_update_entity
|
from homeassistant.helpers.entity_component import async_update_entity
|
||||||
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import UNDEFINED, UndefinedType
|
from homeassistant.helpers.typing import UNDEFINED, UndefinedType
|
||||||
|
|
||||||
from tests.common import (
|
from tests.common import (
|
||||||
|
@ -981,10 +983,13 @@ async def _test_friendly_name(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test friendly name."""
|
"""Test friendly name."""
|
||||||
|
|
||||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
async def async_setup_entry(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: ConfigEntry,
|
||||||
|
async_add_entities: AddEntitiesCallback,
|
||||||
|
) -> None:
|
||||||
"""Mock setup entry method."""
|
"""Mock setup entry method."""
|
||||||
async_add_entities([ent])
|
async_add_entities([ent])
|
||||||
return True
|
|
||||||
|
|
||||||
platform = MockPlatform(async_setup_entry=async_setup_entry)
|
platform = MockPlatform(async_setup_entry=async_setup_entry)
|
||||||
config_entry = MockConfigEntry(entry_id="super-mock-id")
|
config_entry = MockConfigEntry(entry_id="super-mock-id")
|
||||||
|
@ -1306,10 +1311,13 @@ async def test_entity_name_translation_placeholder_errors(
|
||||||
"""Return all backend translations."""
|
"""Return all backend translations."""
|
||||||
return translations[language]
|
return translations[language]
|
||||||
|
|
||||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
async def async_setup_entry(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: ConfigEntry,
|
||||||
|
async_add_entities: AddEntitiesCallback,
|
||||||
|
) -> None:
|
||||||
"""Mock setup entry method."""
|
"""Mock setup entry method."""
|
||||||
async_add_entities([ent])
|
async_add_entities([ent])
|
||||||
return True
|
|
||||||
|
|
||||||
ent = MockEntity(
|
ent = MockEntity(
|
||||||
unique_id="qwer",
|
unique_id="qwer",
|
||||||
|
@ -1531,7 +1539,11 @@ async def test_friendly_name_updated(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test friendly name is updated when device or entity registry updates."""
|
"""Test friendly name is updated when device or entity registry updates."""
|
||||||
|
|
||||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
async def async_setup_entry(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: ConfigEntry,
|
||||||
|
async_add_entities: AddEntitiesCallback,
|
||||||
|
) -> None:
|
||||||
"""Mock setup entry method."""
|
"""Mock setup entry method."""
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
[
|
[
|
||||||
|
@ -1547,7 +1559,6 @@ async def test_friendly_name_updated(
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
return True
|
|
||||||
|
|
||||||
platform = MockPlatform(async_setup_entry=async_setup_entry)
|
platform = MockPlatform(async_setup_entry=async_setup_entry)
|
||||||
config_entry = MockConfigEntry(entry_id="super-mock-id")
|
config_entry = MockConfigEntry(entry_id="super-mock-id")
|
||||||
|
|
|
@ -10,6 +10,7 @@ from unittest.mock import ANY, AsyncMock, Mock, patch
|
||||||
import pytest
|
import pytest
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import EVENT_HOMEASSISTANT_STARTED, PERCENTAGE, EntityCategory
|
from homeassistant.const import EVENT_HOMEASSISTANT_STARTED, PERCENTAGE, EntityCategory
|
||||||
from homeassistant.core import (
|
from homeassistant.core import (
|
||||||
CoreState,
|
CoreState,
|
||||||
|
@ -33,6 +34,7 @@ from homeassistant.helpers.entity_component import (
|
||||||
DEFAULT_SCAN_INTERVAL,
|
DEFAULT_SCAN_INTERVAL,
|
||||||
EntityComponent,
|
EntityComponent,
|
||||||
)
|
)
|
||||||
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
|
|
||||||
|
@ -855,10 +857,13 @@ async def test_setup_entry(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test we can setup an entry."""
|
"""Test we can setup an entry."""
|
||||||
|
|
||||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
async def async_setup_entry(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: ConfigEntry,
|
||||||
|
async_add_entities: AddEntitiesCallback,
|
||||||
|
) -> None:
|
||||||
"""Mock setup entry method."""
|
"""Mock setup entry method."""
|
||||||
async_add_entities([MockEntity(name="test1", unique_id="unique")])
|
async_add_entities([MockEntity(name="test1", unique_id="unique")])
|
||||||
return True
|
|
||||||
|
|
||||||
platform = MockPlatform(async_setup_entry=async_setup_entry)
|
platform = MockPlatform(async_setup_entry=async_setup_entry)
|
||||||
config_entry = MockConfigEntry(entry_id="super-mock-id")
|
config_entry = MockConfigEntry(entry_id="super-mock-id")
|
||||||
|
@ -1138,7 +1143,11 @@ async def test_device_info_called(
|
||||||
model="via",
|
model="via",
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
async def async_setup_entry(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: ConfigEntry,
|
||||||
|
async_add_entities: AddEntitiesCallback,
|
||||||
|
) -> None:
|
||||||
"""Mock setup entry method."""
|
"""Mock setup entry method."""
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
[
|
[
|
||||||
|
@ -1163,7 +1172,6 @@ async def test_device_info_called(
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
return True
|
|
||||||
|
|
||||||
platform = MockPlatform(async_setup_entry=async_setup_entry)
|
platform = MockPlatform(async_setup_entry=async_setup_entry)
|
||||||
entity_platform = MockEntityPlatform(
|
entity_platform = MockEntityPlatform(
|
||||||
|
@ -1207,7 +1215,11 @@ async def test_device_info_not_overrides(
|
||||||
assert device.manufacturer == "test-manufacturer"
|
assert device.manufacturer == "test-manufacturer"
|
||||||
assert device.model == "test-model"
|
assert device.model == "test-model"
|
||||||
|
|
||||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
async def async_setup_entry(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: ConfigEntry,
|
||||||
|
async_add_entities: AddEntitiesCallback,
|
||||||
|
) -> None:
|
||||||
"""Mock setup entry method."""
|
"""Mock setup entry method."""
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
[
|
[
|
||||||
|
@ -1222,7 +1234,6 @@ async def test_device_info_not_overrides(
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
return True
|
|
||||||
|
|
||||||
platform = MockPlatform(async_setup_entry=async_setup_entry)
|
platform = MockPlatform(async_setup_entry=async_setup_entry)
|
||||||
entity_platform = MockEntityPlatform(
|
entity_platform = MockEntityPlatform(
|
||||||
|
@ -1257,7 +1268,11 @@ async def test_device_info_homeassistant_url(
|
||||||
model="via",
|
model="via",
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
async def async_setup_entry(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: ConfigEntry,
|
||||||
|
async_add_entities: AddEntitiesCallback,
|
||||||
|
) -> None:
|
||||||
"""Mock setup entry method."""
|
"""Mock setup entry method."""
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
[
|
[
|
||||||
|
@ -1271,7 +1286,6 @@ async def test_device_info_homeassistant_url(
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
return True
|
|
||||||
|
|
||||||
platform = MockPlatform(async_setup_entry=async_setup_entry)
|
platform = MockPlatform(async_setup_entry=async_setup_entry)
|
||||||
entity_platform = MockEntityPlatform(
|
entity_platform = MockEntityPlatform(
|
||||||
|
@ -1306,7 +1320,11 @@ async def test_device_info_change_to_no_url(
|
||||||
configuration_url="homeassistant://config/mqtt",
|
configuration_url="homeassistant://config/mqtt",
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
async def async_setup_entry(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: ConfigEntry,
|
||||||
|
async_add_entities: AddEntitiesCallback,
|
||||||
|
) -> None:
|
||||||
"""Mock setup entry method."""
|
"""Mock setup entry method."""
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
[
|
[
|
||||||
|
@ -1320,7 +1338,6 @@ async def test_device_info_change_to_no_url(
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
return True
|
|
||||||
|
|
||||||
platform = MockPlatform(async_setup_entry=async_setup_entry)
|
platform = MockPlatform(async_setup_entry=async_setup_entry)
|
||||||
entity_platform = MockEntityPlatform(
|
entity_platform = MockEntityPlatform(
|
||||||
|
@ -1375,10 +1392,13 @@ async def test_entity_disabled_by_device(
|
||||||
unique_id="disabled", device_info=DeviceInfo(connections=connections)
|
unique_id="disabled", device_info=DeviceInfo(connections=connections)
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
async def async_setup_entry(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: ConfigEntry,
|
||||||
|
async_add_entities: AddEntitiesCallback,
|
||||||
|
) -> None:
|
||||||
"""Mock setup entry method."""
|
"""Mock setup entry method."""
|
||||||
async_add_entities([entity_disabled])
|
async_add_entities([entity_disabled])
|
||||||
return True
|
|
||||||
|
|
||||||
platform = MockPlatform(async_setup_entry=async_setup_entry)
|
platform = MockPlatform(async_setup_entry=async_setup_entry)
|
||||||
config_entry = MockConfigEntry(entry_id="super-mock-id", domain=DOMAIN)
|
config_entry = MockConfigEntry(entry_id="super-mock-id", domain=DOMAIN)
|
||||||
|
@ -1855,13 +1875,16 @@ async def test_setup_entry_with_entities_that_block_forever(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test we cancel adding entities when we reach the timeout."""
|
"""Test we cancel adding entities when we reach the timeout."""
|
||||||
|
|
||||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
async def async_setup_entry(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: ConfigEntry,
|
||||||
|
async_add_entities: AddEntitiesCallback,
|
||||||
|
) -> None:
|
||||||
"""Mock setup entry method."""
|
"""Mock setup entry method."""
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
[MockBlockingEntity(name="test1", unique_id="unique")],
|
[MockBlockingEntity(name="test1", unique_id="unique")],
|
||||||
update_before_add=update_before_add,
|
update_before_add=update_before_add,
|
||||||
)
|
)
|
||||||
return True
|
|
||||||
|
|
||||||
platform = MockPlatform(async_setup_entry=async_setup_entry)
|
platform = MockPlatform(async_setup_entry=async_setup_entry)
|
||||||
config_entry = MockConfigEntry(entry_id="super-mock-id")
|
config_entry = MockConfigEntry(entry_id="super-mock-id")
|
||||||
|
@ -1900,13 +1923,16 @@ async def test_cancellation_is_not_blocked(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test cancellation is not blocked while adding entities."""
|
"""Test cancellation is not blocked while adding entities."""
|
||||||
|
|
||||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
async def async_setup_entry(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: ConfigEntry,
|
||||||
|
async_add_entities: AddEntitiesCallback,
|
||||||
|
) -> None:
|
||||||
"""Mock setup entry method."""
|
"""Mock setup entry method."""
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
[MockCancellingEntity(name="test1", unique_id="unique")],
|
[MockCancellingEntity(name="test1", unique_id="unique")],
|
||||||
update_before_add=update_before_add,
|
update_before_add=update_before_add,
|
||||||
)
|
)
|
||||||
return True
|
|
||||||
|
|
||||||
platform = MockPlatform(async_setup_entry=async_setup_entry)
|
platform = MockPlatform(async_setup_entry=async_setup_entry)
|
||||||
config_entry = MockConfigEntry(entry_id="super-mock-id")
|
config_entry = MockConfigEntry(entry_id="super-mock-id")
|
||||||
|
@ -1994,7 +2020,11 @@ async def test_entity_name_influences_entity_id(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test entity_id is influenced by entity name."""
|
"""Test entity_id is influenced by entity name."""
|
||||||
|
|
||||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
async def async_setup_entry(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: ConfigEntry,
|
||||||
|
async_add_entities: AddEntitiesCallback,
|
||||||
|
) -> None:
|
||||||
"""Mock setup entry method."""
|
"""Mock setup entry method."""
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
[
|
[
|
||||||
|
@ -2011,7 +2041,6 @@ async def test_entity_name_influences_entity_id(
|
||||||
],
|
],
|
||||||
update_before_add=update_before_add,
|
update_before_add=update_before_add,
|
||||||
)
|
)
|
||||||
return True
|
|
||||||
|
|
||||||
platform = MockPlatform(async_setup_entry=async_setup_entry)
|
platform = MockPlatform(async_setup_entry=async_setup_entry)
|
||||||
config_entry = MockConfigEntry(entry_id="super-mock-id")
|
config_entry = MockConfigEntry(entry_id="super-mock-id")
|
||||||
|
@ -2079,12 +2108,15 @@ async def test_translated_entity_name_influences_entity_id(
|
||||||
"""Return all backend translations."""
|
"""Return all backend translations."""
|
||||||
return translations[language]
|
return translations[language]
|
||||||
|
|
||||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
async def async_setup_entry(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: ConfigEntry,
|
||||||
|
async_add_entities: AddEntitiesCallback,
|
||||||
|
) -> None:
|
||||||
"""Mock setup entry method."""
|
"""Mock setup entry method."""
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
[TranslatedEntity(has_entity_name)], update_before_add=update_before_add
|
[TranslatedEntity(has_entity_name)], update_before_add=update_before_add
|
||||||
)
|
)
|
||||||
return True
|
|
||||||
|
|
||||||
platform = MockPlatform(async_setup_entry=async_setup_entry)
|
platform = MockPlatform(async_setup_entry=async_setup_entry)
|
||||||
config_entry = MockConfigEntry(entry_id="super-mock-id")
|
config_entry = MockConfigEntry(entry_id="super-mock-id")
|
||||||
|
@ -2164,10 +2196,13 @@ async def test_translated_device_class_name_influences_entity_id(
|
||||||
"""Return all backend translations."""
|
"""Return all backend translations."""
|
||||||
return translations[language]
|
return translations[language]
|
||||||
|
|
||||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
async def async_setup_entry(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: ConfigEntry,
|
||||||
|
async_add_entities: AddEntitiesCallback,
|
||||||
|
) -> None:
|
||||||
"""Mock setup entry method."""
|
"""Mock setup entry method."""
|
||||||
async_add_entities([TranslatedDeviceClassEntity(device_class, has_entity_name)])
|
async_add_entities([TranslatedDeviceClassEntity(device_class, has_entity_name)])
|
||||||
return True
|
|
||||||
|
|
||||||
platform = MockPlatform(async_setup_entry=async_setup_entry)
|
platform = MockPlatform(async_setup_entry=async_setup_entry)
|
||||||
config_entry = MockConfigEntry(entry_id="super-mock-id")
|
config_entry = MockConfigEntry(entry_id="super-mock-id")
|
||||||
|
@ -2223,10 +2258,13 @@ async def test_device_name_defaulting_config_entry(
|
||||||
_attr_unique_id = "qwer"
|
_attr_unique_id = "qwer"
|
||||||
_attr_device_info = device_info
|
_attr_device_info = device_info
|
||||||
|
|
||||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
async def async_setup_entry(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: ConfigEntry,
|
||||||
|
async_add_entities: AddEntitiesCallback,
|
||||||
|
) -> None:
|
||||||
"""Mock setup entry method."""
|
"""Mock setup entry method."""
|
||||||
async_add_entities([DeviceNameEntity()])
|
async_add_entities([DeviceNameEntity()])
|
||||||
return True
|
|
||||||
|
|
||||||
platform = MockPlatform(async_setup_entry=async_setup_entry)
|
platform = MockPlatform(async_setup_entry=async_setup_entry)
|
||||||
config_entry = MockConfigEntry(title=config_entry_title, entry_id="super-mock-id")
|
config_entry = MockConfigEntry(title=config_entry_title, entry_id="super-mock-id")
|
||||||
|
@ -2276,10 +2314,13 @@ async def test_device_type_error_checking(
|
||||||
_attr_unique_id = "qwer"
|
_attr_unique_id = "qwer"
|
||||||
_attr_device_info = device_info
|
_attr_device_info = device_info
|
||||||
|
|
||||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
async def async_setup_entry(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: ConfigEntry,
|
||||||
|
async_add_entities: AddEntitiesCallback,
|
||||||
|
) -> None:
|
||||||
"""Mock setup entry method."""
|
"""Mock setup entry method."""
|
||||||
async_add_entities([DeviceNameEntity()])
|
async_add_entities([DeviceNameEntity()])
|
||||||
return True
|
|
||||||
|
|
||||||
platform = MockPlatform(async_setup_entry=async_setup_entry)
|
platform = MockPlatform(async_setup_entry=async_setup_entry)
|
||||||
config_entry = MockConfigEntry(
|
config_entry = MockConfigEntry(
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
from types import ModuleType
|
from types import ModuleType
|
||||||
|
from typing import Any
|
||||||
from unittest.mock import Mock, patch
|
from unittest.mock import Mock, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -29,7 +30,9 @@ async def test_process_integration_platforms_with_wait(hass: HomeAssistant) -> N
|
||||||
|
|
||||||
processed = []
|
processed = []
|
||||||
|
|
||||||
async def _process_platform(hass, domain, platform):
|
async def _process_platform(
|
||||||
|
hass: HomeAssistant, domain: str, platform: Any
|
||||||
|
) -> None:
|
||||||
"""Process platform."""
|
"""Process platform."""
|
||||||
processed.append((domain, platform))
|
processed.append((domain, platform))
|
||||||
|
|
||||||
|
@ -67,7 +70,9 @@ async def test_process_integration_platforms(hass: HomeAssistant) -> None:
|
||||||
|
|
||||||
processed = []
|
processed = []
|
||||||
|
|
||||||
async def _process_platform(hass, domain, platform):
|
async def _process_platform(
|
||||||
|
hass: HomeAssistant, domain: str, platform: Any
|
||||||
|
) -> None:
|
||||||
"""Process platform."""
|
"""Process platform."""
|
||||||
processed.append((domain, platform))
|
processed.append((domain, platform))
|
||||||
|
|
||||||
|
@ -107,7 +112,9 @@ async def test_process_integration_platforms_import_fails(
|
||||||
|
|
||||||
processed = []
|
processed = []
|
||||||
|
|
||||||
async def _process_platform(hass, domain, platform):
|
async def _process_platform(
|
||||||
|
hass: HomeAssistant, domain: str, platform: Any
|
||||||
|
) -> None:
|
||||||
"""Process platform."""
|
"""Process platform."""
|
||||||
processed.append((domain, platform))
|
processed.append((domain, platform))
|
||||||
|
|
||||||
|
@ -150,7 +157,9 @@ async def test_process_integration_platforms_import_fails_after_registered(
|
||||||
|
|
||||||
processed = []
|
processed = []
|
||||||
|
|
||||||
async def _process_platform(hass, domain, platform):
|
async def _process_platform(
|
||||||
|
hass: HomeAssistant, domain: str, platform: Any
|
||||||
|
) -> None:
|
||||||
"""Process platform."""
|
"""Process platform."""
|
||||||
processed.append((domain, platform))
|
processed.append((domain, platform))
|
||||||
|
|
||||||
|
@ -242,7 +251,9 @@ async def test_broken_integration(
|
||||||
|
|
||||||
processed = []
|
processed = []
|
||||||
|
|
||||||
async def _process_platform(hass, domain, platform):
|
async def _process_platform(
|
||||||
|
hass: HomeAssistant, domain: str, platform: Any
|
||||||
|
) -> None:
|
||||||
"""Process platform."""
|
"""Process platform."""
|
||||||
processed.append((domain, platform))
|
processed.append((domain, platform))
|
||||||
|
|
||||||
|
@ -265,7 +276,9 @@ async def test_process_integration_platforms_no_integrations(
|
||||||
|
|
||||||
processed = []
|
processed = []
|
||||||
|
|
||||||
async def _process_platform(hass, domain, platform):
|
async def _process_platform(
|
||||||
|
hass: HomeAssistant, domain: str, platform: Any
|
||||||
|
) -> None:
|
||||||
"""Process platform."""
|
"""Process platform."""
|
||||||
processed.append((domain, platform))
|
processed.append((domain, platform))
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
"""Test significant change helper."""
|
"""Test significant change helper."""
|
||||||
|
|
||||||
|
from types import MappingProxyType
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.sensor import SensorDeviceClass
|
from homeassistant.components.sensor import SensorDeviceClass
|
||||||
|
@ -67,8 +70,14 @@ async def test_significant_change_extra(
|
||||||
assert checker.async_is_significant_change(State(ent_id, "100", attrs), extra_arg=1)
|
assert checker.async_is_significant_change(State(ent_id, "100", attrs), extra_arg=1)
|
||||||
|
|
||||||
def extra_significant_check(
|
def extra_significant_check(
|
||||||
hass, old_state, old_attrs, old_extra_arg, new_state, new_attrs, new_extra_arg
|
hass: HomeAssistant,
|
||||||
):
|
old_state: str,
|
||||||
|
old_attrs: dict | MappingProxyType,
|
||||||
|
old_extra_arg: Any,
|
||||||
|
new_state: str,
|
||||||
|
new_attrs: dict | MappingProxyType,
|
||||||
|
new_extra_arg: Any,
|
||||||
|
) -> bool | None:
|
||||||
return old_extra_arg != new_extra_arg
|
return old_extra_arg != new_extra_arg
|
||||||
|
|
||||||
checker.extra_significant_check = extra_significant_check
|
checker.extra_significant_check = extra_significant_check
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
"""Test singleton helper."""
|
"""Test singleton helper."""
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
from unittest.mock import Mock
|
from unittest.mock import Mock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import singleton
|
from homeassistant.helpers import singleton
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,11 +16,11 @@ def mock_hass():
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("result", [object(), {}, []])
|
@pytest.mark.parametrize("result", [object(), {}, []])
|
||||||
async def test_singleton_async(mock_hass, result) -> None:
|
async def test_singleton_async(mock_hass: HomeAssistant, result: Any) -> None:
|
||||||
"""Test singleton with async function."""
|
"""Test singleton with async function."""
|
||||||
|
|
||||||
@singleton.singleton("test_key")
|
@singleton.singleton("test_key")
|
||||||
async def something(hass):
|
async def something(hass: HomeAssistant) -> Any:
|
||||||
return result
|
return result
|
||||||
|
|
||||||
result1 = await something(mock_hass)
|
result1 = await something(mock_hass)
|
||||||
|
@ -30,11 +32,11 @@ async def test_singleton_async(mock_hass, result) -> None:
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("result", [object(), {}, []])
|
@pytest.mark.parametrize("result", [object(), {}, []])
|
||||||
def test_singleton(mock_hass, result) -> None:
|
def test_singleton(mock_hass: HomeAssistant, result: Any) -> None:
|
||||||
"""Test singleton with function."""
|
"""Test singleton with function."""
|
||||||
|
|
||||||
@singleton.singleton("test_key")
|
@singleton.singleton("test_key")
|
||||||
def something(hass):
|
def something(hass: HomeAssistant) -> Any:
|
||||||
return result
|
return result
|
||||||
|
|
||||||
result1 = something(mock_hass)
|
result1 = something(mock_hass)
|
||||||
|
|
|
@ -14,7 +14,7 @@ async def test_at_start_when_running_awaitable(hass: HomeAssistant) -> None:
|
||||||
|
|
||||||
calls = []
|
calls = []
|
||||||
|
|
||||||
async def cb_at_start(hass):
|
async def cb_at_start(hass: HomeAssistant) -> None:
|
||||||
"""Home Assistant is started."""
|
"""Home Assistant is started."""
|
||||||
calls.append(1)
|
calls.append(1)
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ async def test_at_start_when_running_callback(
|
||||||
calls = []
|
calls = []
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def cb_at_start(hass):
|
def cb_at_start(hass: HomeAssistant) -> None:
|
||||||
"""Home Assistant is started."""
|
"""Home Assistant is started."""
|
||||||
calls.append(1)
|
calls.append(1)
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ async def test_at_start_when_starting_awaitable(hass: HomeAssistant) -> None:
|
||||||
|
|
||||||
calls = []
|
calls = []
|
||||||
|
|
||||||
async def cb_at_start(hass):
|
async def cb_at_start(hass: HomeAssistant) -> None:
|
||||||
"""Home Assistant is started."""
|
"""Home Assistant is started."""
|
||||||
calls.append(1)
|
calls.append(1)
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ async def test_at_start_when_starting_callback(
|
||||||
calls = []
|
calls = []
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def cb_at_start(hass):
|
def cb_at_start(hass: HomeAssistant) -> None:
|
||||||
"""Home Assistant is started."""
|
"""Home Assistant is started."""
|
||||||
calls.append(1)
|
calls.append(1)
|
||||||
|
|
||||||
|
@ -116,7 +116,7 @@ async def test_cancelling_at_start_when_running(
|
||||||
|
|
||||||
calls = []
|
calls = []
|
||||||
|
|
||||||
async def cb_at_start(hass):
|
async def cb_at_start(hass: HomeAssistant) -> None:
|
||||||
"""Home Assistant is started."""
|
"""Home Assistant is started."""
|
||||||
calls.append(1)
|
calls.append(1)
|
||||||
|
|
||||||
|
@ -137,7 +137,7 @@ async def test_cancelling_at_start_when_starting(hass: HomeAssistant) -> None:
|
||||||
calls = []
|
calls = []
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def cb_at_start(hass):
|
def cb_at_start(hass: HomeAssistant) -> None:
|
||||||
"""Home Assistant is started."""
|
"""Home Assistant is started."""
|
||||||
calls.append(1)
|
calls.append(1)
|
||||||
|
|
||||||
|
@ -156,7 +156,7 @@ async def test_at_started_when_running_awaitable(hass: HomeAssistant) -> None:
|
||||||
|
|
||||||
calls = []
|
calls = []
|
||||||
|
|
||||||
async def cb_at_start(hass):
|
async def cb_at_start(hass: HomeAssistant) -> None:
|
||||||
"""Home Assistant is started."""
|
"""Home Assistant is started."""
|
||||||
calls.append(1)
|
calls.append(1)
|
||||||
|
|
||||||
|
@ -181,7 +181,7 @@ async def test_at_started_when_running_callback(
|
||||||
calls = []
|
calls = []
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def cb_at_start(hass):
|
def cb_at_start(hass: HomeAssistant) -> None:
|
||||||
"""Home Assistant is started."""
|
"""Home Assistant is started."""
|
||||||
calls.append(1)
|
calls.append(1)
|
||||||
|
|
||||||
|
@ -205,7 +205,7 @@ async def test_at_started_when_starting_awaitable(hass: HomeAssistant) -> None:
|
||||||
|
|
||||||
calls = []
|
calls = []
|
||||||
|
|
||||||
async def cb_at_start(hass):
|
async def cb_at_start(hass: HomeAssistant) -> None:
|
||||||
"""Home Assistant is started."""
|
"""Home Assistant is started."""
|
||||||
calls.append(1)
|
calls.append(1)
|
||||||
|
|
||||||
|
@ -231,7 +231,7 @@ async def test_at_started_when_starting_callback(
|
||||||
calls = []
|
calls = []
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def cb_at_start(hass):
|
def cb_at_start(hass: HomeAssistant) -> None:
|
||||||
"""Home Assistant is started."""
|
"""Home Assistant is started."""
|
||||||
calls.append(1)
|
calls.append(1)
|
||||||
|
|
||||||
|
@ -263,7 +263,7 @@ async def test_cancelling_at_started_when_running(
|
||||||
|
|
||||||
calls = []
|
calls = []
|
||||||
|
|
||||||
async def cb_at_start(hass):
|
async def cb_at_start(hass: HomeAssistant) -> None:
|
||||||
"""Home Assistant is started."""
|
"""Home Assistant is started."""
|
||||||
calls.append(1)
|
calls.append(1)
|
||||||
|
|
||||||
|
@ -284,7 +284,7 @@ async def test_cancelling_at_started_when_starting(hass: HomeAssistant) -> None:
|
||||||
calls = []
|
calls = []
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def cb_at_start(hass):
|
def cb_at_start(hass: HomeAssistant) -> None:
|
||||||
"""Home Assistant is started."""
|
"""Home Assistant is started."""
|
||||||
calls.append(1)
|
calls.append(1)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue