diff --git a/homeassistant/components/hive/__init__.py b/homeassistant/components/hive/__init__.py index d50ead9bfaa5..7c73712403cc 100644 --- a/homeassistant/components/hive/__init__.py +++ b/homeassistant/components/hive/__init__.py @@ -16,7 +16,7 @@ from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady from homeassistant.helpers import aiohttp_client, device_registry as dr from homeassistant.helpers.dispatcher import async_dispatcher_send -from .const import DOMAIN, PLATFORM_LOOKUP, PLATFORMS +from .const import DOMAIN, PLATFORMS from .entity import HiveEntity _LOGGER = logging.getLogger(__name__) @@ -60,14 +60,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: HiveConfigEntry) -> bool manufacturer=hub_data["deviceData"]["manufacturer"], ) - await hass.config_entries.async_forward_entry_setups( - entry, - [ - ha_type - for ha_type, hive_type in PLATFORM_LOOKUP.items() - if devices.get(hive_type) - ], - ) + await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) return True diff --git a/homeassistant/components/hive/binary_sensor.py b/homeassistant/components/hive/binary_sensor.py index 3393924ba4f1..f0a9da64af32 100644 --- a/homeassistant/components/hive/binary_sensor.py +++ b/homeassistant/components/hive/binary_sensor.py @@ -77,7 +77,7 @@ async def async_setup_entry( sensors: list[BinarySensorEntity] = [] - devices = hive.session.deviceList.get("binary_sensor") + devices = hive.session.deviceList.get("binary_sensor", []) sensors.extend( HiveBinarySensorEntity(hass, entry, hive, dev, description) for dev in devices @@ -85,7 +85,7 @@ async def async_setup_entry( if dev["hiveType"] == description.key ) - devices = hive.session.deviceList.get("sensor") + devices = hive.session.deviceList.get("sensor", []) sensors.extend( HiveSensorEntity(hass, entry, hive, dev, description) for dev in devices diff --git a/homeassistant/components/hive/const.py b/homeassistant/components/hive/const.py index a14d22247189..84cecc62d245 100644 --- a/homeassistant/components/hive/const.py +++ b/homeassistant/components/hive/const.py @@ -17,14 +17,6 @@ PLATFORMS = [ Platform.SWITCH, Platform.WATER_HEATER, ] -PLATFORM_LOOKUP = { - Platform.BINARY_SENSOR: "binary_sensor", - Platform.CLIMATE: "climate", - Platform.LIGHT: "light", - Platform.SENSOR: "sensor", - Platform.SWITCH: "switch", - Platform.WATER_HEATER: "water_heater", -} SERVICE_BOOST_HOT_WATER = "boost_hot_water" SERVICE_BOOST_HEATING_ON = "boost_heating_on" SERVICE_BOOST_HEATING_OFF = "boost_heating_off" diff --git a/tests/components/hive/test_init.py b/tests/components/hive/test_init.py index 936052be7217..56774eaf1036 100644 --- a/tests/components/hive/test_init.py +++ b/tests/components/hive/test_init.py @@ -3,8 +3,16 @@ from typing import Any from unittest.mock import AsyncMock, MagicMock, patch +import pytest + from homeassistant.components.binary_sensor import BinarySensorDeviceClass -from homeassistant.components.hive.const import DOMAIN +from homeassistant.components.hive.const import ( + DOMAIN, + SERVICE_BOOST_HEATING_OFF, + SERVICE_BOOST_HEATING_ON, + SERVICE_BOOST_HOT_WATER, +) +from homeassistant.config_entries import ConfigEntryState from homeassistant.const import ATTR_DEVICE_CLASS, CONF_PASSWORD, CONF_USERNAME from homeassistant.core import HomeAssistant from homeassistant.helpers import device_registry as dr, entity_registry as er @@ -244,3 +252,34 @@ async def test_glass_break_device_class( state = hass.states.get(entity_id) assert state assert state.attributes[ATTR_DEVICE_CLASS] == BinarySensorDeviceClass.GLASS_BREAK + + +async def test_all_platforms_forwarded_without_devices( + hass: HomeAssistant, + caplog: pytest.LogCaptureFixture, +) -> None: + """All platforms are set up and the entry reloads on a device-less account.""" + entry = MockConfigEntry(domain=DOMAIN, data=_ENTRY_DATA) + entry.add_to_hass(hass) + + mock_hive = _make_mock_hive({}) + + with patch( + "homeassistant.components.hive.Hive", + return_value=mock_hive, + ): + await hass.config_entries.async_setup(entry.entry_id) + await hass.async_block_till_done() + + assert entry.state is ConfigEntryState.LOADED + # Entity services must not depend on device discovery. + assert hass.services.has_service(DOMAIN, SERVICE_BOOST_HOT_WATER) + assert hass.services.has_service(DOMAIN, SERVICE_BOOST_HEATING_ON) + assert hass.services.has_service(DOMAIN, SERVICE_BOOST_HEATING_OFF) + + await hass.config_entries.async_reload(entry.entry_id) + await hass.async_block_till_done() + + assert entry.state is ConfigEntryState.LOADED + assert "Error setting up entry" not in caplog.text + assert "Error unloading entry" not in caplog.text