mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Replace aiogithub dependency with pynecil update check (#133213)
This commit is contained in:
parent
879d809e5a
commit
314076b85f
@ -271,6 +271,7 @@ homeassistant.components.ios.*
|
|||||||
homeassistant.components.iotty.*
|
homeassistant.components.iotty.*
|
||||||
homeassistant.components.ipp.*
|
homeassistant.components.ipp.*
|
||||||
homeassistant.components.iqvia.*
|
homeassistant.components.iqvia.*
|
||||||
|
homeassistant.components.iron_os.*
|
||||||
homeassistant.components.islamic_prayer_times.*
|
homeassistant.components.islamic_prayer_times.*
|
||||||
homeassistant.components.isy994.*
|
homeassistant.components.isy994.*
|
||||||
homeassistant.components.jellyfin.*
|
homeassistant.components.jellyfin.*
|
||||||
|
@ -5,8 +5,7 @@ from __future__ import annotations
|
|||||||
import logging
|
import logging
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from aiogithubapi import GitHubAPI
|
from pynecil import IronOSUpdate, Pynecil
|
||||||
from pynecil import Pynecil
|
|
||||||
|
|
||||||
from homeassistant.components import bluetooth
|
from homeassistant.components import bluetooth
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
@ -48,7 +47,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||||||
"""Set up IronOS firmware update coordinator."""
|
"""Set up IronOS firmware update coordinator."""
|
||||||
|
|
||||||
session = async_get_clientsession(hass)
|
session = async_get_clientsession(hass)
|
||||||
github = GitHubAPI(session=session)
|
github = IronOSUpdate(session)
|
||||||
|
|
||||||
hass.data[IRON_OS_KEY] = IronOSFirmwareUpdateCoordinator(hass, github)
|
hass.data[IRON_OS_KEY] = IronOSFirmwareUpdateCoordinator(hass, github)
|
||||||
await hass.data[IRON_OS_KEY].async_request_refresh()
|
await hass.data[IRON_OS_KEY].async_request_refresh()
|
||||||
|
@ -5,15 +5,16 @@ from __future__ import annotations
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
from typing import TYPE_CHECKING
|
|
||||||
|
|
||||||
from aiogithubapi import GitHubAPI, GitHubException, GitHubReleaseModel
|
|
||||||
from pynecil import (
|
from pynecil import (
|
||||||
CommunicationError,
|
CommunicationError,
|
||||||
DeviceInfoResponse,
|
DeviceInfoResponse,
|
||||||
|
IronOSUpdate,
|
||||||
|
LatestRelease,
|
||||||
LiveDataResponse,
|
LiveDataResponse,
|
||||||
Pynecil,
|
Pynecil,
|
||||||
SettingsDataResponse,
|
SettingsDataResponse,
|
||||||
|
UpdateException,
|
||||||
)
|
)
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
@ -104,10 +105,10 @@ class IronOSLiveDataCoordinator(IronOSBaseCoordinator[LiveDataResponse]):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
class IronOSFirmwareUpdateCoordinator(DataUpdateCoordinator[GitHubReleaseModel]):
|
class IronOSFirmwareUpdateCoordinator(DataUpdateCoordinator[LatestRelease]):
|
||||||
"""IronOS coordinator for retrieving update information from github."""
|
"""IronOS coordinator for retrieving update information from github."""
|
||||||
|
|
||||||
def __init__(self, hass: HomeAssistant, github: GitHubAPI) -> None:
|
def __init__(self, hass: HomeAssistant, github: IronOSUpdate) -> None:
|
||||||
"""Initialize IronOS coordinator."""
|
"""Initialize IronOS coordinator."""
|
||||||
super().__init__(
|
super().__init__(
|
||||||
hass,
|
hass,
|
||||||
@ -118,21 +119,13 @@ class IronOSFirmwareUpdateCoordinator(DataUpdateCoordinator[GitHubReleaseModel])
|
|||||||
)
|
)
|
||||||
self.github = github
|
self.github = github
|
||||||
|
|
||||||
async def _async_update_data(self) -> GitHubReleaseModel:
|
async def _async_update_data(self) -> LatestRelease:
|
||||||
"""Fetch data from Github."""
|
"""Fetch data from Github."""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
release = await self.github.repos.releases.latest("Ralim/IronOS")
|
return await self.github.latest_release()
|
||||||
|
except UpdateException as e:
|
||||||
except GitHubException as e:
|
raise UpdateFailed("Failed to check for latest IronOS update") from e
|
||||||
raise UpdateFailed(
|
|
||||||
"Failed to retrieve latest release data from Github"
|
|
||||||
) from e
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
assert release.data
|
|
||||||
|
|
||||||
return release.data
|
|
||||||
|
|
||||||
|
|
||||||
class IronOSSettingsCoordinator(IronOSBaseCoordinator[SettingsDataResponse]):
|
class IronOSSettingsCoordinator(IronOSBaseCoordinator[SettingsDataResponse]):
|
||||||
|
@ -12,6 +12,6 @@
|
|||||||
"dependencies": ["bluetooth_adapters"],
|
"dependencies": ["bluetooth_adapters"],
|
||||||
"documentation": "https://www.home-assistant.io/integrations/iron_os",
|
"documentation": "https://www.home-assistant.io/integrations/iron_os",
|
||||||
"iot_class": "local_polling",
|
"iot_class": "local_polling",
|
||||||
"loggers": ["pynecil", "aiogithubapi"],
|
"loggers": ["pynecil"],
|
||||||
"requirements": ["pynecil==2.1.0", "aiogithubapi==24.6.0"]
|
"requirements": ["pynecil==2.1.0"]
|
||||||
}
|
}
|
||||||
|
@ -81,4 +81,4 @@ rules:
|
|||||||
inject-websession:
|
inject-websession:
|
||||||
status: exempt
|
status: exempt
|
||||||
comment: Device doesn't make http requests.
|
comment: Device doesn't make http requests.
|
||||||
strict-typing: todo
|
strict-typing: done
|
||||||
|
10
mypy.ini
10
mypy.ini
@ -2465,6 +2465,16 @@ disallow_untyped_defs = true
|
|||||||
warn_return_any = true
|
warn_return_any = true
|
||||||
warn_unreachable = true
|
warn_unreachable = true
|
||||||
|
|
||||||
|
[mypy-homeassistant.components.iron_os.*]
|
||||||
|
check_untyped_defs = true
|
||||||
|
disallow_incomplete_defs = true
|
||||||
|
disallow_subclassing_any = true
|
||||||
|
disallow_untyped_calls = true
|
||||||
|
disallow_untyped_decorators = true
|
||||||
|
disallow_untyped_defs = true
|
||||||
|
warn_return_any = true
|
||||||
|
warn_unreachable = true
|
||||||
|
|
||||||
[mypy-homeassistant.components.islamic_prayer_times.*]
|
[mypy-homeassistant.components.islamic_prayer_times.*]
|
||||||
check_untyped_defs = true
|
check_untyped_defs = true
|
||||||
disallow_incomplete_defs = true
|
disallow_incomplete_defs = true
|
||||||
|
@ -252,7 +252,6 @@ aioflo==2021.11.0
|
|||||||
aioftp==0.21.3
|
aioftp==0.21.3
|
||||||
|
|
||||||
# homeassistant.components.github
|
# homeassistant.components.github
|
||||||
# homeassistant.components.iron_os
|
|
||||||
aiogithubapi==24.6.0
|
aiogithubapi==24.6.0
|
||||||
|
|
||||||
# homeassistant.components.guardian
|
# homeassistant.components.guardian
|
||||||
|
@ -237,7 +237,6 @@ aioesphomeapi==28.0.0
|
|||||||
aioflo==2021.11.0
|
aioflo==2021.11.0
|
||||||
|
|
||||||
# homeassistant.components.github
|
# homeassistant.components.github
|
||||||
# homeassistant.components.iron_os
|
|
||||||
aiogithubapi==24.6.0
|
aiogithubapi==24.6.0
|
||||||
|
|
||||||
# homeassistant.components.guardian
|
# homeassistant.components.guardian
|
||||||
|
@ -7,6 +7,7 @@ from bleak.backends.device import BLEDevice
|
|||||||
from habluetooth import BluetoothServiceInfoBleak
|
from habluetooth import BluetoothServiceInfoBleak
|
||||||
from pynecil import (
|
from pynecil import (
|
||||||
DeviceInfoResponse,
|
DeviceInfoResponse,
|
||||||
|
LatestRelease,
|
||||||
LiveDataResponse,
|
LiveDataResponse,
|
||||||
OperatingMode,
|
OperatingMode,
|
||||||
PowerSource,
|
PowerSource,
|
||||||
@ -114,24 +115,20 @@ def mock_ble_device() -> Generator[MagicMock]:
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def mock_githubapi() -> Generator[AsyncMock]:
|
def mock_ironosupdate() -> Generator[AsyncMock]:
|
||||||
"""Mock aiogithubapi."""
|
"""Mock IronOSUpdate."""
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.iron_os.GitHubAPI",
|
"homeassistant.components.iron_os.IronOSUpdate",
|
||||||
autospec=True,
|
autospec=True,
|
||||||
) as mock_client:
|
) as mock_client:
|
||||||
client = mock_client.return_value
|
client = mock_client.return_value
|
||||||
client.repos.releases.latest = AsyncMock()
|
client.latest_release.return_value = LatestRelease(
|
||||||
|
html_url="https://github.com/Ralim/IronOS/releases/tag/v2.22",
|
||||||
client.repos.releases.latest.return_value.data.html_url = (
|
name="V2.22 | TS101 & S60 Added | PinecilV2 improved",
|
||||||
"https://github.com/Ralim/IronOS/releases/tag/v2.22"
|
tag_name="v2.22",
|
||||||
|
body="**RELEASE_NOTES**",
|
||||||
)
|
)
|
||||||
client.repos.releases.latest.return_value.data.name = (
|
|
||||||
"V2.22 | TS101 & S60 Added | PinecilV2 improved"
|
|
||||||
)
|
|
||||||
client.repos.releases.latest.return_value.data.tag_name = "v2.22"
|
|
||||||
client.repos.releases.latest.return_value.data.body = "**RELEASE_NOTES**"
|
|
||||||
|
|
||||||
yield client
|
yield client
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
from collections.abc import AsyncGenerator
|
from collections.abc import AsyncGenerator
|
||||||
from unittest.mock import AsyncMock, patch
|
from unittest.mock import AsyncMock, patch
|
||||||
|
|
||||||
from aiogithubapi import GitHubException
|
from pynecil import UpdateException
|
||||||
import pytest
|
import pytest
|
||||||
from syrupy.assertion import SnapshotAssertion
|
from syrupy.assertion import SnapshotAssertion
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ async def update_only() -> AsyncGenerator[None]:
|
|||||||
yield
|
yield
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("mock_pynecil", "ble_device", "mock_githubapi")
|
@pytest.mark.usefixtures("mock_pynecil", "ble_device", "mock_ironosupdate")
|
||||||
async def test_update(
|
async def test_update(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: MockConfigEntry,
|
config_entry: MockConfigEntry,
|
||||||
@ -60,11 +60,11 @@ async def test_update(
|
|||||||
async def test_update_unavailable(
|
async def test_update_unavailable(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: MockConfigEntry,
|
config_entry: MockConfigEntry,
|
||||||
mock_githubapi: AsyncMock,
|
mock_ironosupdate: AsyncMock,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test update entity unavailable on error."""
|
"""Test update entity unavailable on error."""
|
||||||
|
|
||||||
mock_githubapi.repos.releases.latest.side_effect = GitHubException
|
mock_ironosupdate.latest_release.side_effect = UpdateException
|
||||||
|
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user