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
|
||||
from typing import cast
|
||||
|
||||
from aiohttp import ContentTypeError
|
||||
from async_timeout import timeout
|
||||
import pyevilgenius
|
||||
|
||||
|
@ -54,6 +55,8 @@ class EvilGeniusUpdateCoordinator(DataUpdateCoordinator[dict]):
|
|||
|
||||
info: dict
|
||||
|
||||
product: dict | None
|
||||
|
||||
def __init__(
|
||||
self, hass: HomeAssistant, name: str, client: pyevilgenius.EvilGeniusDevice
|
||||
) -> None:
|
||||
|
@ -71,14 +74,30 @@ class EvilGeniusUpdateCoordinator(DataUpdateCoordinator[dict]):
|
|||
"""Return the device name."""
|
||||
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:
|
||||
"""Update Evil Genius data."""
|
||||
if not hasattr(self, "info"):
|
||||
async with timeout(5):
|
||||
self.info = await self.client.get_info()
|
||||
|
||||
if not hasattr(self, "product"):
|
||||
async with timeout(5):
|
||||
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_data())
|
||||
return cast(dict, await self.client.get_all())
|
||||
|
||||
|
||||
class EvilGeniusEntity(CoordinatorEntity[EvilGeniusUpdateCoordinator]):
|
||||
|
@ -92,6 +111,7 @@ class EvilGeniusEntity(CoordinatorEntity[EvilGeniusUpdateCoordinator]):
|
|||
identifiers={(DOMAIN, info["wiFiChipId"])},
|
||||
connections={(dr.CONNECTION_NETWORK_MAC, info["macAddress"])},
|
||||
name=self.coordinator.device_name,
|
||||
model=self.coordinator.product_name,
|
||||
manufacturer="Evil Genius Labs",
|
||||
sw_version=info["coreVersion"].replace("_", "."),
|
||||
configuration_url=self.coordinator.client.url,
|
||||
|
|
|
@ -32,7 +32,7 @@ async def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> dict[str,
|
|||
|
||||
try:
|
||||
async with async_timeout.timeout(10):
|
||||
data = await hub.get_data()
|
||||
data = await hub.get_all()
|
||||
info = await hub.get_info()
|
||||
except aiohttp.ClientError as err:
|
||||
_LOGGER.debug("Unable to connect: %s", err)
|
||||
|
|
|
@ -19,5 +19,5 @@ async def async_get_config_entry_diagnostics(
|
|||
|
||||
return {
|
||||
"info": async_redact_data(coordinator.info, TO_REDACT),
|
||||
"data": coordinator.data,
|
||||
"all": coordinator.data,
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
"name": "Evil Genius Labs",
|
||||
"config_flow": true,
|
||||
"documentation": "https://www.home-assistant.io/integrations/evil_genius_labs",
|
||||
"requirements": ["pyevilgenius==1.0.0"],
|
||||
"requirements": ["pyevilgenius==2.0.0"],
|
||||
"codeowners": ["@balloob"],
|
||||
"iot_class": "local_polling"
|
||||
}
|
||||
|
|
|
@ -1468,7 +1468,7 @@ pyephember==0.3.1
|
|||
pyeverlights==0.1.0
|
||||
|
||||
# homeassistant.components.evil_genius_labs
|
||||
pyevilgenius==1.0.0
|
||||
pyevilgenius==2.0.0
|
||||
|
||||
# homeassistant.components.ezviz
|
||||
pyezviz==0.2.0.6
|
||||
|
|
|
@ -962,7 +962,7 @@ pyefergy==22.1.1
|
|||
pyeverlights==0.1.0
|
||||
|
||||
# homeassistant.components.evil_genius_labs
|
||||
pyevilgenius==1.0.0
|
||||
pyevilgenius==2.0.0
|
||||
|
||||
# homeassistant.components.ezviz
|
||||
pyezviz==0.2.0.6
|
||||
|
|
|
@ -10,7 +10,7 @@ from tests.common import MockConfigEntry, load_fixture
|
|||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def data_fixture():
|
||||
def all_fixture():
|
||||
"""Fixture data."""
|
||||
data = json.loads(load_fixture("data.json", "evil_genius_labs"))
|
||||
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"))
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def product_fixture():
|
||||
"""Fixture info."""
|
||||
return {"productName": "Fibonacci256"}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def config_entry(hass):
|
||||
"""Evil genius labs config entry."""
|
||||
|
@ -32,15 +38,18 @@ def config_entry(hass):
|
|||
|
||||
@pytest.fixture
|
||||
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."""
|
||||
with patch(
|
||||
"pyevilgenius.EvilGeniusDevice.get_data",
|
||||
return_value=data_fixture,
|
||||
"pyevilgenius.EvilGeniusDevice.get_all",
|
||||
return_value=all_fixture,
|
||||
), patch(
|
||||
"pyevilgenius.EvilGeniusDevice.get_info",
|
||||
return_value=info_fixture,
|
||||
), patch(
|
||||
"pyevilgenius.EvilGeniusDevice.get_product",
|
||||
return_value=product_fixture,
|
||||
), patch(
|
||||
"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
|
||||
|
||||
|
||||
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."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
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
|
||||
|
||||
with patch(
|
||||
"pyevilgenius.EvilGeniusDevice.get_data",
|
||||
return_value=data_fixture,
|
||||
"pyevilgenius.EvilGeniusDevice.get_all",
|
||||
return_value=all_fixture,
|
||||
), patch(
|
||||
"pyevilgenius.EvilGeniusDevice.get_info",
|
||||
return_value=info_fixture,
|
||||
), patch(
|
||||
"pyevilgenius.EvilGeniusDevice.get_product",
|
||||
return_value=product_fixture,
|
||||
), patch(
|
||||
"homeassistant.components.evil_genius_labs.async_setup_entry",
|
||||
return_value=True,
|
||||
|
@ -51,7 +56,7 @@ async def test_form_cannot_connect(hass: HomeAssistant, caplog) -> None:
|
|||
)
|
||||
|
||||
with patch(
|
||||
"pyevilgenius.EvilGeniusDevice.get_data",
|
||||
"pyevilgenius.EvilGeniusDevice.get_all",
|
||||
side_effect=aiohttp.ClientError,
|
||||
):
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
|
@ -73,7 +78,7 @@ async def test_form_timeout(hass: HomeAssistant) -> None:
|
|||
)
|
||||
|
||||
with patch(
|
||||
"pyevilgenius.EvilGeniusDevice.get_data",
|
||||
"pyevilgenius.EvilGeniusDevice.get_all",
|
||||
side_effect=asyncio.TimeoutError,
|
||||
):
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
|
@ -94,7 +99,7 @@ async def test_form_unknown(hass: HomeAssistant) -> None:
|
|||
)
|
||||
|
||||
with patch(
|
||||
"pyevilgenius.EvilGeniusDevice.get_data",
|
||||
"pyevilgenius.EvilGeniusDevice.get_all",
|
||||
side_effect=ValueError("BOOM"),
|
||||
):
|
||||
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", [[]])
|
||||
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."""
|
||||
assert await get_diagnostics_for_config_entry(hass, hass_client, config_entry) == {
|
||||
|
@ -17,5 +17,5 @@ async def test_entry_diagnostics(
|
|||
"wiFiSsidDefault": REDACTED,
|
||||
"wiFiSSID": REDACTED,
|
||||
},
|
||||
"data": data_fixture,
|
||||
"all": all_fixture,
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue