diff --git a/homeassistant/components/mystrom/__init__.py b/homeassistant/components/mystrom/__init__.py index 307e99be1bd5..424a3f9e9c37 100644 --- a/homeassistant/components/mystrom/__init__.py +++ b/homeassistant/components/mystrom/__init__.py @@ -11,8 +11,9 @@ from pymystrom.switch import MyStromSwitch from homeassistant.const import CONF_HOST, Platform from homeassistant.core import HomeAssistant -from homeassistant.exceptions import ConfigEntryNotReady +from homeassistant.exceptions import ConfigEntryError, ConfigEntryNotReady +from .const import DOMAIN from .models import MyStromConfigEntry, MyStromData PLATFORMS_PLUGS = [Platform.SENSOR, Platform.SWITCH] @@ -71,19 +72,21 @@ async def async_setup_entry(hass: HomeAssistant, entry: MyStromConfigEntry) -> b platforms = PLATFORMS_BULB await _async_get_device_state(device, info["ip"]) if device.bulb_type not in ["rgblamp", "strip"]: - _LOGGER.error( - "Device %s (%s) is not a myStrom bulb nor myStrom LED Strip", - host, - mac, + raise ConfigEntryError( + translation_domain=DOMAIN, + translation_key="unsupported_bulb", + translation_placeholders={"host": host, "mac": mac}, ) - return False elif device_type == 110: device = _get_mystrom_pir(host) platforms = PLATFORMS_MOTION_SENSOR await _async_get_device_state(device, info["ip"]) else: - _LOGGER.error("Unsupported myStrom device type: %s", device_type) - return False + raise ConfigEntryError( + translation_domain=DOMAIN, + translation_key="unsupported_device_type", + translation_placeholders={"device_type": str(device_type)}, + ) entry.runtime_data = MyStromData( device=device, diff --git a/homeassistant/components/mystrom/strings.json b/homeassistant/components/mystrom/strings.json index c4bb37ceb23f..cd8bbb6ca013 100644 --- a/homeassistant/components/mystrom/strings.json +++ b/homeassistant/components/mystrom/strings.json @@ -38,6 +38,12 @@ "exceptions": { "switch_action_failed": { "message": "Failed to perform the action on the myStrom plug." + }, + "unsupported_bulb": { + "message": "Device {host} ({mac}) is not a myStrom bulb nor myStrom LED Strip" + }, + "unsupported_device_type": { + "message": "Unsupported myStrom device type: {device_type}" } } } diff --git a/tests/components/mystrom/test_init.py b/tests/components/mystrom/test_init.py index 61ff38a46b37..d803a440961b 100644 --- a/tests/components/mystrom/test_init.py +++ b/tests/components/mystrom/test_init.py @@ -138,7 +138,9 @@ async def test_init_of_unknown_bulb( with ( patch( "pymystrom.get_device_info", - side_effect=AsyncMock(return_value={"type": 102, "mac": DEVICE_MAC}), + side_effect=AsyncMock( + return_value={"type": 102, "mac": DEVICE_MAC, "ip": "1.1.1.1"} + ), ), patch("pymystrom.bulb.MyStromBulb.get_state", return_value={}), patch("pymystrom.bulb.MyStromBulb.bulb_type", "new_type"), @@ -152,6 +154,9 @@ async def test_init_of_unknown_bulb( await hass.async_block_till_done() assert config_entry.state is ConfigEntryState.SETUP_ERROR + assert config_entry.reason == ( + "Device 1.1.1.1 (6001940376EB) is not a myStrom bulb nor myStrom LED Strip" + ) async def test_init_of_unknown_device( @@ -166,6 +171,7 @@ async def test_init_of_unknown_device( await hass.async_block_till_done() assert config_entry.state is ConfigEntryState.SETUP_ERROR + assert config_entry.reason == "Unsupported myStrom device type: 103" async def test_init_cannot_connect_because_of_device_info(