diff --git a/homeassistant/components/demo/__init__.py b/homeassistant/components/demo/__init__.py index b40e1ede232..98226d68030 100644 --- a/homeassistant/components/demo/__init__.py +++ b/homeassistant/components/demo/__init__.py @@ -48,6 +48,7 @@ COMPONENTS_WITH_CONFIG_ENTRY_DEMO_PLATFORM = [ Platform.UPDATE, Platform.VACUUM, Platform.WATER_HEATER, + Platform.WEATHER, ] COMPONENTS_WITH_DEMO_PLATFORM = [ @@ -56,7 +57,6 @@ COMPONENTS_WITH_DEMO_PLATFORM = [ Platform.NOTIFY, Platform.IMAGE_PROCESSING, Platform.DEVICE_TRACKER, - Platform.WEATHER, ] CONFIG_SCHEMA = cv.empty_config_schema(DOMAIN) diff --git a/homeassistant/components/demo/air_quality.py b/homeassistant/components/demo/air_quality.py index c63729f2cd6..d1a56112497 100644 --- a/homeassistant/components/demo/air_quality.py +++ b/homeassistant/components/demo/air_quality.py @@ -5,19 +5,6 @@ from homeassistant.components.air_quality import AirQualityEntity from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback -from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType - - -async def async_setup_platform( - hass: HomeAssistant, - config: ConfigType, - async_add_entities: AddEntitiesCallback, - discovery_info: DiscoveryInfoType | None = None, -) -> None: - """Set up the Air Quality.""" - async_add_entities( - [DemoAirQuality("Home", 14, 23, 100), DemoAirQuality("Office", 4, 16, None)] - ) async def async_setup_entry( @@ -26,7 +13,9 @@ async def async_setup_entry( async_add_entities: AddEntitiesCallback, ) -> None: """Set up the Demo config entry.""" - await async_setup_platform(hass, {}, async_add_entities) + async_add_entities( + [DemoAirQuality("Home", 14, 23, 100), DemoAirQuality("Office", 4, 16, None)] + ) class DemoAirQuality(AirQualityEntity): diff --git a/homeassistant/components/demo/alarm_control_panel.py b/homeassistant/components/demo/alarm_control_panel.py index 3a94aaa7c29..1c15e9d5b7e 100644 --- a/homeassistant/components/demo/alarm_control_panel.py +++ b/homeassistant/components/demo/alarm_control_panel.py @@ -19,16 +19,14 @@ from homeassistant.const import ( ) from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback -from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType -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 alarm control panel platform.""" + """Set up the Demo config entry.""" async_add_entities( [ ManualAlarm( # type:ignore[no-untyped-call] @@ -75,12 +73,3 @@ 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) diff --git a/homeassistant/components/demo/fan.py b/homeassistant/components/demo/fan.py index 5c8cc849285..211389a5466 100644 --- a/homeassistant/components/demo/fan.py +++ b/homeassistant/components/demo/fan.py @@ -7,7 +7,6 @@ from homeassistant.components.fan import FanEntity, FanEntityFeature from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback -from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType PRESET_MODE_AUTO = "auto" PRESET_MODE_SMART = "smart" @@ -20,13 +19,12 @@ FULL_SUPPORT = ( LIMITED_SUPPORT = FanEntityFeature.SET_SPEED -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 fan platform.""" + """Set up the Demo config entry.""" async_add_entities( [ DemoPercentageFan( @@ -88,15 +86,6 @@ 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 BaseDemoFan(FanEntity): """A demonstration fan component that uses legacy fan speeds.""" diff --git a/homeassistant/components/demo/humidifier.py b/homeassistant/components/demo/humidifier.py index 2e16a04e171..a63e3e1983f 100644 --- a/homeassistant/components/demo/humidifier.py +++ b/homeassistant/components/demo/humidifier.py @@ -12,18 +12,16 @@ from homeassistant.components.humidifier import ( from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback -from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType SUPPORT_FLAGS = HumidifierEntityFeature(0) -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 humidifier devices.""" + """Set up the Demo humidifier devices config entry.""" async_add_entities( [ DemoHumidifier( @@ -52,15 +50,6 @@ async def async_setup_platform( ) -async def async_setup_entry( - hass: HomeAssistant, - config_entry: ConfigEntry, - async_add_entities: AddEntitiesCallback, -) -> None: - """Set up the Demo humidifier devices config entry.""" - await async_setup_platform(hass, {}, async_add_entities) - - class DemoHumidifier(HumidifierEntity): """Representation of a demo humidifier device.""" diff --git a/homeassistant/components/demo/image_processing.py b/homeassistant/components/demo/image_processing.py index 21322f49718..71ea9d97bf6 100644 --- a/homeassistant/components/demo/image_processing.py +++ b/homeassistant/components/demo/image_processing.py @@ -10,14 +10,14 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType -def setup_platform( +async def async_setup_platform( hass: HomeAssistant, config: ConfigType, - add_entities: AddEntitiesCallback, + async_add_entities: AddEntitiesCallback, discovery_info: DiscoveryInfoType | None = None, ) -> None: """Set up the demo image processing platform.""" - add_entities( + async_add_entities( [ DemoImageProcessingFace("camera.demo_camera", "Demo Face"), ] diff --git a/homeassistant/components/demo/lock.py b/homeassistant/components/demo/lock.py index e75c2074aab..3a6780ce30e 100644 --- a/homeassistant/components/demo/lock.py +++ b/homeassistant/components/demo/lock.py @@ -15,35 +15,24 @@ from homeassistant.const import ( ) from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback -from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType LOCK_UNLOCK_DELAY = 2 # Used to give a realistic lock/unlock experience in frontend -async def async_setup_platform( - hass: HomeAssistant, - config: ConfigType, - async_add_entities: AddEntitiesCallback, - discovery_info: DiscoveryInfoType | None = None, -) -> None: - """Set up the Demo lock platform.""" - async_add_entities( - [ - DemoLock("Front Door", STATE_LOCKED), - DemoLock("Kitchen Door", STATE_UNLOCKED), - DemoLock("Poorly Installed Door", STATE_UNLOCKED, False, True), - DemoLock("Openable Lock", STATE_LOCKED, True), - ] - ) - - 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) + async_add_entities( + [ + DemoLock("Front Door", STATE_LOCKED), + DemoLock("Kitchen Door", STATE_UNLOCKED), + DemoLock("Poorly Installed Door", STATE_UNLOCKED, False, True), + DemoLock("Openable Lock", STATE_LOCKED, True), + ] + ) class DemoLock(LockEntity): diff --git a/homeassistant/components/demo/media_player.py b/homeassistant/components/demo/media_player.py index 9d335c34cdb..35bd35a2245 100644 --- a/homeassistant/components/demo/media_player.py +++ b/homeassistant/components/demo/media_player.py @@ -15,17 +15,15 @@ from homeassistant.components.media_player import ( from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback -from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType import homeassistant.util.dt as dt_util -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 media player demo platform.""" + """Set up the Demo config entry.""" async_add_entities( [ DemoYoutubePlayer( @@ -44,15 +42,6 @@ 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) - - SOUND_MODE_LIST = ["Music", "Movie"] DEFAULT_SOUND_MODE = "Music" diff --git a/homeassistant/components/demo/remote.py b/homeassistant/components/demo/remote.py index f2c1ce11b0a..40df72b073b 100644 --- a/homeassistant/components/demo/remote.py +++ b/homeassistant/components/demo/remote.py @@ -9,7 +9,6 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.const import DEVICE_DEFAULT_NAME from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback -from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType async def async_setup_entry( @@ -18,17 +17,7 @@ async def async_setup_entry( async_add_entities: AddEntitiesCallback, ) -> None: """Set up the Demo config entry.""" - setup_platform(hass, {}, async_add_entities) - - -def setup_platform( - hass: HomeAssistant, - config: ConfigType, - add_entities_callback: AddEntitiesCallback, - discovery_info: DiscoveryInfoType | None = None, -) -> None: - """Set up the demo remotes.""" - add_entities_callback( + async_add_entities( [ DemoRemote("Remote One", False, None), DemoRemote("Remote Two", True, "mdi:remote"), diff --git a/homeassistant/components/demo/siren.py b/homeassistant/components/demo/siren.py index 0720114861c..3b3c3dfc610 100644 --- a/homeassistant/components/demo/siren.py +++ b/homeassistant/components/demo/siren.py @@ -7,18 +7,16 @@ from homeassistant.components.siren import SirenEntity, SirenEntityFeature from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback -from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType SUPPORT_FLAGS = SirenEntityFeature.TURN_OFF | SirenEntityFeature.TURN_ON -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 siren devices.""" + """Set up the Demo siren devices config entry.""" async_add_entities( [ DemoSiren(name="Siren"), @@ -32,15 +30,6 @@ async def async_setup_platform( ) -async def async_setup_entry( - hass: HomeAssistant, - config_entry: ConfigEntry, - async_add_entities: AddEntitiesCallback, -) -> None: - """Set up the Demo siren devices config entry.""" - await async_setup_platform(hass, {}, async_add_entities) - - class DemoSiren(SirenEntity): """Representation of a demo siren device.""" diff --git a/homeassistant/components/demo/vacuum.py b/homeassistant/components/demo/vacuum.py index 11b69272775..83216ebdba6 100644 --- a/homeassistant/components/demo/vacuum.py +++ b/homeassistant/components/demo/vacuum.py @@ -19,7 +19,6 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant from homeassistant.helpers import event from homeassistant.helpers.entity_platform import AddEntitiesCallback -from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType SUPPORT_MINIMAL_SERVICES = VacuumEntityFeature.TURN_ON | VacuumEntityFeature.TURN_OFF @@ -79,16 +78,6 @@ async def async_setup_entry( async_add_entities: AddEntitiesCallback, ) -> None: """Set up the Demo config entry.""" - await async_setup_platform(hass, {}, async_add_entities) - - -async def async_setup_platform( - hass: HomeAssistant, - config: ConfigType, - async_add_entities: AddEntitiesCallback, - discovery_info: DiscoveryInfoType | None = None, -) -> None: - """Set up the Demo vacuums.""" async_add_entities( [ DemoVacuum(DEMO_VACUUM_COMPLETE, SUPPORT_ALL_SERVICES), diff --git a/homeassistant/components/demo/water_heater.py b/homeassistant/components/demo/water_heater.py index 0ab175691f8..beb46c5d8ad 100644 --- a/homeassistant/components/demo/water_heater.py +++ b/homeassistant/components/demo/water_heater.py @@ -11,7 +11,6 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback -from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType SUPPORT_FLAGS_HEATER = ( WaterHeaterEntityFeature.TARGET_TEMPERATURE @@ -21,13 +20,12 @@ SUPPORT_FLAGS_HEATER = ( ) -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 water_heater devices.""" + """Set up the Demo config entry.""" async_add_entities( [ DemoWaterHeater( @@ -40,15 +38,6 @@ 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 DemoWaterHeater(WaterHeaterEntity): """Representation of a demo water_heater device.""" diff --git a/homeassistant/components/demo/weather.py b/homeassistant/components/demo/weather.py index 758b5075041..a990e26c658 100644 --- a/homeassistant/components/demo/weather.py +++ b/homeassistant/components/demo/weather.py @@ -27,7 +27,6 @@ from homeassistant.const import UnitOfPressure, UnitOfSpeed, UnitOfTemperature from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.event import async_track_time_interval -from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType import homeassistant.util.dt as dt_util CONDITION_CLASSES: dict[str, list[str]] = { @@ -61,17 +60,7 @@ async def async_setup_entry( async_add_entities: AddEntitiesCallback, ) -> None: """Set up the Demo config entry.""" - setup_platform(hass, {}, async_add_entities) - - -def setup_platform( - hass: HomeAssistant, - config: ConfigType, - add_entities: AddEntitiesCallback, - discovery_info: DiscoveryInfoType | None = None, -) -> None: - """Set up the Demo weather.""" - add_entities( + async_add_entities( [ DemoWeather( "South", diff --git a/tests/components/demo/test_fan.py b/tests/components/demo/test_fan.py index 9c1b84313f6..58a8c99ea3c 100644 --- a/tests/components/demo/test_fan.py +++ b/tests/components/demo/test_fan.py @@ -1,4 +1,6 @@ """Test cases around the demo fan platform.""" +from unittest.mock import patch + import pytest from homeassistant.components import fan @@ -15,6 +17,7 @@ from homeassistant.const import ( SERVICE_TURN_ON, STATE_OFF, STATE_ON, + Platform, ) from homeassistant.core import HomeAssistant from homeassistant.setup import async_setup_component @@ -31,8 +34,18 @@ FANS_WITH_PRESET_MODES = FULL_FAN_ENTITY_IDS + [ PERCENTAGE_MODEL_FANS = ["fan.percentage_full_fan", "fan.percentage_limited_fan"] +@pytest.fixture +async def fan_only() -> None: + """Enable only the datetime platform.""" + with patch( + "homeassistant.components.demo.COMPONENTS_WITH_CONFIG_ENTRY_DEMO_PLATFORM", + [Platform.FAN], + ): + yield + + @pytest.fixture(autouse=True) -async def setup_comp(hass, disable_platforms): +async def setup_comp(hass: HomeAssistant, fan_only: None): """Initialize components.""" assert await async_setup_component(hass, fan.DOMAIN, {"fan": {"platform": "demo"}}) await hass.async_block_till_done() diff --git a/tests/components/demo/test_humidifier.py b/tests/components/demo/test_humidifier.py index 13aeb5724b9..97647f0a90f 100644 --- a/tests/components/demo/test_humidifier.py +++ b/tests/components/demo/test_humidifier.py @@ -1,5 +1,7 @@ """The tests for the demo humidifier component.""" +from unittest.mock import patch + import pytest import voluptuous as vol @@ -22,6 +24,7 @@ from homeassistant.const import ( SERVICE_TURN_ON, STATE_OFF, STATE_ON, + Platform, ) from homeassistant.core import HomeAssistant from homeassistant.setup import async_setup_component @@ -31,8 +34,18 @@ ENTITY_HYGROSTAT = "humidifier.hygrostat" ENTITY_HUMIDIFIER = "humidifier.humidifier" +@pytest.fixture +async def humidifier_only() -> None: + """Enable only the datetime platform.""" + with patch( + "homeassistant.components.demo.COMPONENTS_WITH_CONFIG_ENTRY_DEMO_PLATFORM", + [Platform.HUMIDIFIER], + ): + yield + + @pytest.fixture(autouse=True) -async def setup_demo_humidifier(hass, disable_platforms): +async def setup_demo_humidifier(hass: HomeAssistant, humidifier_only: None): """Initialize setup demo humidifier.""" assert await async_setup_component( hass, DOMAIN, {"humidifier": {"platform": "demo"}} diff --git a/tests/components/demo/test_lock.py b/tests/components/demo/test_lock.py index 377f9f2d765..f72f5b01c19 100644 --- a/tests/components/demo/test_lock.py +++ b/tests/components/demo/test_lock.py @@ -15,7 +15,7 @@ from homeassistant.components.lock import ( STATE_UNLOCKED, STATE_UNLOCKING, ) -from homeassistant.const import ATTR_ENTITY_ID, EVENT_STATE_CHANGED +from homeassistant.const import ATTR_ENTITY_ID, EVENT_STATE_CHANGED, Platform from homeassistant.core import HomeAssistant from homeassistant.setup import async_setup_component @@ -27,8 +27,18 @@ POORLY_INSTALLED = "lock.poorly_installed_door" OPENABLE_LOCK = "lock.openable_lock" +@pytest.fixture +async def lock_only() -> None: + """Enable only the datetime platform.""" + with patch( + "homeassistant.components.demo.COMPONENTS_WITH_CONFIG_ENTRY_DEMO_PLATFORM", + [Platform.LOCK], + ): + yield + + @pytest.fixture(autouse=True) -async def setup_comp(hass, disable_platforms): +async def setup_comp(hass: HomeAssistant, lock_only: None): """Set up demo component.""" assert await async_setup_component( hass, LOCK_DOMAIN, {LOCK_DOMAIN: {"platform": DOMAIN}} diff --git a/tests/components/demo/test_media_player.py b/tests/components/demo/test_media_player.py index 1681cdb9101..ff6274af1b5 100644 --- a/tests/components/demo/test_media_player.py +++ b/tests/components/demo/test_media_player.py @@ -13,6 +13,7 @@ from homeassistant.const import ( STATE_OFF, STATE_PAUSED, STATE_PLAYING, + Platform, ) from homeassistant.core import HomeAssistant from homeassistant.helpers.aiohttp_client import DATA_CLIENTSESSION @@ -26,6 +27,11 @@ TEST_ENTITY_ID = "media_player.walkman" @pytest.fixture(autouse=True) def autouse_disable_platforms(disable_platforms): """Auto use the disable_platforms fixture.""" + with patch( + "homeassistant.components.demo.COMPONENTS_WITH_CONFIG_ENTRY_DEMO_PLATFORM", + [Platform.MEDIA_PLAYER], + ): + yield @pytest.fixture(name="mock_media_seek") diff --git a/tests/components/demo/test_remote.py b/tests/components/demo/test_remote.py index d1e5b4007ca..5fafffae372 100644 --- a/tests/components/demo/test_remote.py +++ b/tests/components/demo/test_remote.py @@ -1,4 +1,6 @@ """The tests for the demo remote component.""" +from unittest.mock import patch + import pytest import homeassistant.components.remote as remote @@ -9,6 +11,7 @@ from homeassistant.const import ( SERVICE_TURN_ON, STATE_OFF, STATE_ON, + Platform, ) from homeassistant.core import HomeAssistant from homeassistant.setup import async_setup_component @@ -17,8 +20,18 @@ ENTITY_ID = "remote.remote_one" SERVICE_SEND_COMMAND = "send_command" +@pytest.fixture +async def remote_only() -> None: + """Enable only the datetime platform.""" + with patch( + "homeassistant.components.demo.COMPONENTS_WITH_CONFIG_ENTRY_DEMO_PLATFORM", + [Platform.REMOTE], + ): + yield + + @pytest.fixture(autouse=True) -async def setup_component(hass, disable_platforms): +async def setup_component(hass: HomeAssistant, remote_only: None): """Initialize components.""" assert await async_setup_component( hass, remote.DOMAIN, {"remote": {"platform": "demo"}} diff --git a/tests/components/demo/test_siren.py b/tests/components/demo/test_siren.py index 8051aaf5b20..1434248599c 100644 --- a/tests/components/demo/test_siren.py +++ b/tests/components/demo/test_siren.py @@ -16,6 +16,7 @@ from homeassistant.const import ( SERVICE_TURN_ON, STATE_OFF, STATE_ON, + Platform, ) from homeassistant.core import HomeAssistant from homeassistant.setup import async_setup_component @@ -24,8 +25,18 @@ ENTITY_SIREN = "siren.siren" ENTITY_SIREN_WITH_ALL_FEATURES = "siren.siren_with_all_features" +@pytest.fixture +async def siren_only() -> None: + """Enable only the datetime platform.""" + with patch( + "homeassistant.components.demo.COMPONENTS_WITH_CONFIG_ENTRY_DEMO_PLATFORM", + [Platform.SIREN], + ): + yield + + @pytest.fixture(autouse=True) -async def setup_demo_siren(hass, disable_platforms): +async def setup_demo_siren(hass: HomeAssistant, siren_only: None): """Initialize setup demo siren.""" assert await async_setup_component(hass, DOMAIN, {"siren": {"platform": "demo"}}) await hass.async_block_till_done() diff --git a/tests/components/demo/test_vacuum.py b/tests/components/demo/test_vacuum.py index 711d0217f2d..cc0fcfeb2d2 100644 --- a/tests/components/demo/test_vacuum.py +++ b/tests/components/demo/test_vacuum.py @@ -1,5 +1,6 @@ """The tests for the Demo vacuum platform.""" from datetime import timedelta +from unittest.mock import patch import pytest @@ -35,6 +36,7 @@ from homeassistant.const import ( CONF_PLATFORM, STATE_OFF, STATE_ON, + Platform, ) from homeassistant.core import HomeAssistant from homeassistant.exceptions import HomeAssistantError @@ -52,8 +54,18 @@ ENTITY_VACUUM_NONE = f"{DOMAIN}.{DEMO_VACUUM_NONE}".lower() ENTITY_VACUUM_STATE = f"{DOMAIN}.{DEMO_VACUUM_STATE}".lower() +@pytest.fixture +async def vacuum_only() -> None: + """Enable only the datetime platform.""" + with patch( + "homeassistant.components.demo.COMPONENTS_WITH_CONFIG_ENTRY_DEMO_PLATFORM", + [Platform.VACUUM], + ): + yield + + @pytest.fixture(autouse=True) -async def setup_demo_vacuum(hass, disable_platforms): +async def setup_demo_vacuum(hass: HomeAssistant, vacuum_only: None): """Initialize setup demo vacuum.""" assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "demo"}}) await hass.async_block_till_done() diff --git a/tests/components/demo/test_water_heater.py b/tests/components/demo/test_water_heater.py index cc91f57d872..6b133297e34 100644 --- a/tests/components/demo/test_water_heater.py +++ b/tests/components/demo/test_water_heater.py @@ -1,8 +1,11 @@ """The tests for the demo water_heater component.""" +from unittest.mock import patch + import pytest import voluptuous as vol from homeassistant.components import water_heater +from homeassistant.const import Platform from homeassistant.core import HomeAssistant from homeassistant.setup import async_setup_component from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM @@ -13,8 +16,18 @@ ENTITY_WATER_HEATER = "water_heater.demo_water_heater" ENTITY_WATER_HEATER_CELSIUS = "water_heater.demo_water_heater_celsius" +@pytest.fixture +async def water_heater_only() -> None: + """Enable only the datetime platform.""" + with patch( + "homeassistant.components.demo.COMPONENTS_WITH_CONFIG_ENTRY_DEMO_PLATFORM", + [Platform.WATER_HEATER], + ): + yield + + @pytest.fixture(autouse=True) -async def setup_comp(hass, disable_platforms): +async def setup_comp(hass: HomeAssistant, water_heater_only: None): """Set up demo component.""" hass.config.units = US_CUSTOMARY_SYSTEM assert await async_setup_component( diff --git a/tests/components/demo/test_weather.py b/tests/components/demo/test_weather.py index ced801a4d46..bb91535192c 100644 --- a/tests/components/demo/test_weather.py +++ b/tests/components/demo/test_weather.py @@ -1,6 +1,7 @@ """The tests for the demo weather component.""" import datetime from typing import Any +from unittest.mock import patch from freezegun.api import FrozenDateTimeFactory import pytest @@ -15,7 +16,7 @@ from homeassistant.components.weather import ( ATTR_WEATHER_WIND_BEARING, ATTR_WEATHER_WIND_SPEED, ) -from homeassistant.const import ATTR_ATTRIBUTION +from homeassistant.const import ATTR_ATTRIBUTION, Platform from homeassistant.core import HomeAssistant from homeassistant.setup import async_setup_component from homeassistant.util.unit_system import METRIC_SYSTEM @@ -23,7 +24,17 @@ from homeassistant.util.unit_system import METRIC_SYSTEM from tests.typing import WebSocketGenerator -async def test_attributes(hass: HomeAssistant, disable_platforms) -> None: +@pytest.fixture +async def weather_only() -> None: + """Enable only the datetime platform.""" + with patch( + "homeassistant.components.demo.COMPONENTS_WITH_CONFIG_ENTRY_DEMO_PLATFORM", + [Platform.WEATHER], + ): + yield + + +async def test_attributes(hass: HomeAssistant, weather_only) -> None: """Test weather attributes.""" assert await async_setup_component( hass, weather.DOMAIN, {"weather": {"platform": "demo"}} @@ -115,7 +126,7 @@ async def test_forecast( hass: HomeAssistant, hass_ws_client: WebSocketGenerator, freezer: FrozenDateTimeFactory, - disable_platforms: None, + weather_only: None, forecast_type: str, expected_forecast: list[dict[str, Any]], ) -> None: diff --git a/tests/components/manual/test_alarm_control_panel.py b/tests/components/manual/test_alarm_control_panel.py index f1a4b2da2ef..9ca8ac9e2ba 100644 --- a/tests/components/manual/test_alarm_control_panel.py +++ b/tests/components/manual/test_alarm_control_panel.py @@ -40,7 +40,7 @@ async def test_setup_demo_platform(hass: HomeAssistant) -> None: """Test setup.""" mock = MagicMock() add_entities = mock.MagicMock() - await demo.async_setup_platform(hass, {}, add_entities) + await demo.async_setup_entry(hass, {}, add_entities) assert add_entities.call_count == 1