mirror of
https://github.com/home-assistant/core.git
synced 2026-12-05 05:14:01 -04:00
Raise ConfigEntryError for unsupported devices in mystrom (#185097)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
6a53921410
commit
246eb3697e
@@ -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,
|
||||
|
||||
@@ -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}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user