Bump pyevilgenius to 2.0.0 (#70074)
* Bump pyevilgenius to 2.0.0 * Fix tests
This commit is contained in:
parent
03c91dad78
commit
5f6a970826
9 changed files with 52 additions and 18 deletions
|
@ -5,6 +5,7 @@ from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
from typing import cast
|
from typing import cast
|
||||||
|
|
||||||
|
from aiohttp import ContentTypeError
|
||||||
from async_timeout import timeout
|
from async_timeout import timeout
|
||||||
import pyevilgenius
|
import pyevilgenius
|
||||||
|
|
||||||
|
@ -54,6 +55,8 @@ class EvilGeniusUpdateCoordinator(DataUpdateCoordinator[dict]):
|
||||||
|
|
||||||
info: dict
|
info: dict
|
||||||
|
|
||||||
|
product: dict | None
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, hass: HomeAssistant, name: str, client: pyevilgenius.EvilGeniusDevice
|
self, hass: HomeAssistant, name: str, client: pyevilgenius.EvilGeniusDevice
|
||||||
) -> None:
|
) -> None:
|
||||||
|
@ -71,14 +74,30 @@ class EvilGeniusUpdateCoordinator(DataUpdateCoordinator[dict]):
|
||||||
"""Return the device name."""
|
"""Return the device name."""
|
||||||
return cast(str, self.data["name"]["value"])
|
return cast(str, self.data["name"]["value"])
|
||||||
|
|
||||||
|
@property
|
||||||
|
def product_name(self) -> str | None:
|
||||||
|
"""Return the product name."""
|
||||||
|
if self.product is None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
return cast(str, self.product["productName"])
|
||||||
|
|
||||||
async def _async_update_data(self) -> dict:
|
async def _async_update_data(self) -> dict:
|
||||||
"""Update Evil Genius data."""
|
"""Update Evil Genius data."""
|
||||||
if not hasattr(self, "info"):
|
if not hasattr(self, "info"):
|
||||||
async with timeout(5):
|
async with timeout(5):
|
||||||
self.info = await self.client.get_info()
|
self.info = await self.client.get_info()
|
||||||
|
|
||||||
|
if not hasattr(self, "product"):
|
||||||
async with timeout(5):
|
async with timeout(5):
|
||||||
return cast(dict, await self.client.get_data())
|
try:
|
||||||
|
self.product = await self.client.get_product()
|
||||||
|
except ContentTypeError:
|
||||||
|
# Older versions of the API don't support this
|
||||||
|
self.product = None
|
||||||
|
|
||||||
|
async with timeout(5):
|
||||||
|
return cast(dict, await self.client.get_all())
|
||||||
|
|
||||||
|
|
||||||
class EvilGeniusEntity(CoordinatorEntity[EvilGeniusUpdateCoordinator]):
|
class EvilGeniusEntity(CoordinatorEntity[EvilGeniusUpdateCoordinator]):
|
||||||
|
@ -92,6 +111,7 @@ class EvilGeniusEntity(CoordinatorEntity[EvilGeniusUpdateCoordinator]):
|
||||||
identifiers={(DOMAIN, info["wiFiChipId"])},
|
identifiers={(DOMAIN, info["wiFiChipId"])},
|
||||||
connections={(dr.CONNECTION_NETWORK_MAC, info["macAddress"])},
|
connections={(dr.CONNECTION_NETWORK_MAC, info["macAddress"])},
|
||||||
name=self.coordinator.device_name,
|
name=self.coordinator.device_name,
|
||||||
|
model=self.coordinator.product_name,
|
||||||
manufacturer="Evil Genius Labs",
|
manufacturer="Evil Genius Labs",
|
||||||
sw_version=info["coreVersion"].replace("_", "."),
|
sw_version=info["coreVersion"].replace("_", "."),
|
||||||
configuration_url=self.coordinator.client.url,
|
configuration_url=self.coordinator.client.url,
|
||||||
|
|
|
@ -32,7 +32,7 @@ async def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> dict[str,
|
||||||
|
|
||||||
try:
|
try:
|
||||||
async with async_timeout.timeout(10):
|
async with async_timeout.timeout(10):
|
||||||
data = await hub.get_data()
|
data = await hub.get_all()
|
||||||
info = await hub.get_info()
|
info = await hub.get_info()
|
||||||
except aiohttp.ClientError as err:
|
except aiohttp.ClientError as err:
|
||||||
_LOGGER.debug("Unable to connect: %s", err)
|
_LOGGER.debug("Unable to connect: %s", err)
|
||||||
|
|
|
@ -19,5 +19,5 @@ async def async_get_config_entry_diagnostics(
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"info": async_redact_data(coordinator.info, TO_REDACT),
|
"info": async_redact_data(coordinator.info, TO_REDACT),
|
||||||
"data": coordinator.data,
|
"all": coordinator.data,
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
"name": "Evil Genius Labs",
|
"name": "Evil Genius Labs",
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"documentation": "https://www.home-assistant.io/integrations/evil_genius_labs",
|
"documentation": "https://www.home-assistant.io/integrations/evil_genius_labs",
|
||||||
"requirements": ["pyevilgenius==1.0.0"],
|
"requirements": ["pyevilgenius==2.0.0"],
|
||||||
"codeowners": ["@balloob"],
|
"codeowners": ["@balloob"],
|
||||||
"iot_class": "local_polling"
|
"iot_class": "local_polling"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1468,7 +1468,7 @@ pyephember==0.3.1
|
||||||
pyeverlights==0.1.0
|
pyeverlights==0.1.0
|
||||||
|
|
||||||
# homeassistant.components.evil_genius_labs
|
# homeassistant.components.evil_genius_labs
|
||||||
pyevilgenius==1.0.0
|
pyevilgenius==2.0.0
|
||||||
|
|
||||||
# homeassistant.components.ezviz
|
# homeassistant.components.ezviz
|
||||||
pyezviz==0.2.0.6
|
pyezviz==0.2.0.6
|
||||||
|
|
|
@ -962,7 +962,7 @@ pyefergy==22.1.1
|
||||||
pyeverlights==0.1.0
|
pyeverlights==0.1.0
|
||||||
|
|
||||||
# homeassistant.components.evil_genius_labs
|
# homeassistant.components.evil_genius_labs
|
||||||
pyevilgenius==1.0.0
|
pyevilgenius==2.0.0
|
||||||
|
|
||||||
# homeassistant.components.ezviz
|
# homeassistant.components.ezviz
|
||||||
pyezviz==0.2.0.6
|
pyezviz==0.2.0.6
|
||||||
|
|
|
@ -10,7 +10,7 @@ from tests.common import MockConfigEntry, load_fixture
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="session")
|
@pytest.fixture(scope="session")
|
||||||
def data_fixture():
|
def all_fixture():
|
||||||
"""Fixture data."""
|
"""Fixture data."""
|
||||||
data = json.loads(load_fixture("data.json", "evil_genius_labs"))
|
data = json.loads(load_fixture("data.json", "evil_genius_labs"))
|
||||||
return {item["name"]: item for item in data}
|
return {item["name"]: item for item in data}
|
||||||
|
@ -22,6 +22,12 @@ def info_fixture():
|
||||||
return json.loads(load_fixture("info.json", "evil_genius_labs"))
|
return json.loads(load_fixture("info.json", "evil_genius_labs"))
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope="session")
|
||||||
|
def product_fixture():
|
||||||
|
"""Fixture info."""
|
||||||
|
return {"productName": "Fibonacci256"}
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def config_entry(hass):
|
def config_entry(hass):
|
||||||
"""Evil genius labs config entry."""
|
"""Evil genius labs config entry."""
|
||||||
|
@ -32,15 +38,18 @@ def config_entry(hass):
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def setup_evil_genius_labs(
|
async def setup_evil_genius_labs(
|
||||||
hass, config_entry, data_fixture, info_fixture, platforms
|
hass, config_entry, all_fixture, info_fixture, product_fixture, platforms
|
||||||
):
|
):
|
||||||
"""Test up Evil Genius Labs instance."""
|
"""Test up Evil Genius Labs instance."""
|
||||||
with patch(
|
with patch(
|
||||||
"pyevilgenius.EvilGeniusDevice.get_data",
|
"pyevilgenius.EvilGeniusDevice.get_all",
|
||||||
return_value=data_fixture,
|
return_value=all_fixture,
|
||||||
), patch(
|
), patch(
|
||||||
"pyevilgenius.EvilGeniusDevice.get_info",
|
"pyevilgenius.EvilGeniusDevice.get_info",
|
||||||
return_value=info_fixture,
|
return_value=info_fixture,
|
||||||
|
), patch(
|
||||||
|
"pyevilgenius.EvilGeniusDevice.get_product",
|
||||||
|
return_value=product_fixture,
|
||||||
), patch(
|
), patch(
|
||||||
"homeassistant.components.evil_genius_labs.PLATFORMS", platforms
|
"homeassistant.components.evil_genius_labs.PLATFORMS", platforms
|
||||||
):
|
):
|
||||||
|
|
|
@ -10,7 +10,9 @@ from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.data_entry_flow import RESULT_TYPE_CREATE_ENTRY, RESULT_TYPE_FORM
|
from homeassistant.data_entry_flow import RESULT_TYPE_CREATE_ENTRY, RESULT_TYPE_FORM
|
||||||
|
|
||||||
|
|
||||||
async def test_form(hass: HomeAssistant, data_fixture, info_fixture) -> None:
|
async def test_form(
|
||||||
|
hass: HomeAssistant, all_fixture, info_fixture, product_fixture
|
||||||
|
) -> None:
|
||||||
"""Test we get the form."""
|
"""Test we get the form."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
|
@ -19,11 +21,14 @@ async def test_form(hass: HomeAssistant, data_fixture, info_fixture) -> None:
|
||||||
assert result["errors"] is None
|
assert result["errors"] is None
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"pyevilgenius.EvilGeniusDevice.get_data",
|
"pyevilgenius.EvilGeniusDevice.get_all",
|
||||||
return_value=data_fixture,
|
return_value=all_fixture,
|
||||||
), patch(
|
), patch(
|
||||||
"pyevilgenius.EvilGeniusDevice.get_info",
|
"pyevilgenius.EvilGeniusDevice.get_info",
|
||||||
return_value=info_fixture,
|
return_value=info_fixture,
|
||||||
|
), patch(
|
||||||
|
"pyevilgenius.EvilGeniusDevice.get_product",
|
||||||
|
return_value=product_fixture,
|
||||||
), patch(
|
), patch(
|
||||||
"homeassistant.components.evil_genius_labs.async_setup_entry",
|
"homeassistant.components.evil_genius_labs.async_setup_entry",
|
||||||
return_value=True,
|
return_value=True,
|
||||||
|
@ -51,7 +56,7 @@ async def test_form_cannot_connect(hass: HomeAssistant, caplog) -> None:
|
||||||
)
|
)
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"pyevilgenius.EvilGeniusDevice.get_data",
|
"pyevilgenius.EvilGeniusDevice.get_all",
|
||||||
side_effect=aiohttp.ClientError,
|
side_effect=aiohttp.ClientError,
|
||||||
):
|
):
|
||||||
result2 = await hass.config_entries.flow.async_configure(
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
|
@ -73,7 +78,7 @@ async def test_form_timeout(hass: HomeAssistant) -> None:
|
||||||
)
|
)
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"pyevilgenius.EvilGeniusDevice.get_data",
|
"pyevilgenius.EvilGeniusDevice.get_all",
|
||||||
side_effect=asyncio.TimeoutError,
|
side_effect=asyncio.TimeoutError,
|
||||||
):
|
):
|
||||||
result2 = await hass.config_entries.flow.async_configure(
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
|
@ -94,7 +99,7 @@ async def test_form_unknown(hass: HomeAssistant) -> None:
|
||||||
)
|
)
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"pyevilgenius.EvilGeniusDevice.get_data",
|
"pyevilgenius.EvilGeniusDevice.get_all",
|
||||||
side_effect=ValueError("BOOM"),
|
side_effect=ValueError("BOOM"),
|
||||||
):
|
):
|
||||||
result2 = await hass.config_entries.flow.async_configure(
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
|
|
|
@ -8,7 +8,7 @@ from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||||
|
|
||||||
@pytest.mark.parametrize("platforms", [[]])
|
@pytest.mark.parametrize("platforms", [[]])
|
||||||
async def test_entry_diagnostics(
|
async def test_entry_diagnostics(
|
||||||
hass, hass_client, setup_evil_genius_labs, config_entry, data_fixture, info_fixture
|
hass, hass_client, setup_evil_genius_labs, config_entry, all_fixture, info_fixture
|
||||||
):
|
):
|
||||||
"""Test config entry diagnostics."""
|
"""Test config entry diagnostics."""
|
||||||
assert await get_diagnostics_for_config_entry(hass, hass_client, config_entry) == {
|
assert await get_diagnostics_for_config_entry(hass, hass_client, config_entry) == {
|
||||||
|
@ -17,5 +17,5 @@ async def test_entry_diagnostics(
|
||||||
"wiFiSsidDefault": REDACTED,
|
"wiFiSsidDefault": REDACTED,
|
||||||
"wiFiSSID": REDACTED,
|
"wiFiSSID": REDACTED,
|
||||||
},
|
},
|
||||||
"data": data_fixture,
|
"all": all_fixture,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue