mirror of
https://github.com/home-assistant/core.git
synced 2025-06-25 01:21:51 +02:00
Replace aiogithub dependency with pynecil update check (#133213)
This commit is contained in:
@ -271,6 +271,7 @@ homeassistant.components.ios.*
|
||||
homeassistant.components.iotty.*
|
||||
homeassistant.components.ipp.*
|
||||
homeassistant.components.iqvia.*
|
||||
homeassistant.components.iron_os.*
|
||||
homeassistant.components.islamic_prayer_times.*
|
||||
homeassistant.components.isy994.*
|
||||
homeassistant.components.jellyfin.*
|
||||
|
@ -5,8 +5,7 @@ from __future__ import annotations
|
||||
import logging
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from aiogithubapi import GitHubAPI
|
||||
from pynecil import Pynecil
|
||||
from pynecil import IronOSUpdate, Pynecil
|
||||
|
||||
from homeassistant.components import bluetooth
|
||||
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."""
|
||||
|
||||
session = async_get_clientsession(hass)
|
||||
github = GitHubAPI(session=session)
|
||||
github = IronOSUpdate(session)
|
||||
|
||||
hass.data[IRON_OS_KEY] = IronOSFirmwareUpdateCoordinator(hass, github)
|
||||
await hass.data[IRON_OS_KEY].async_request_refresh()
|
||||
|
@ -5,15 +5,16 @@ from __future__ import annotations
|
||||
from dataclasses import dataclass
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from aiogithubapi import GitHubAPI, GitHubException, GitHubReleaseModel
|
||||
from pynecil import (
|
||||
CommunicationError,
|
||||
DeviceInfoResponse,
|
||||
IronOSUpdate,
|
||||
LatestRelease,
|
||||
LiveDataResponse,
|
||||
Pynecil,
|
||||
SettingsDataResponse,
|
||||
UpdateException,
|
||||
)
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
@ -104,10 +105,10 @@ class IronOSLiveDataCoordinator(IronOSBaseCoordinator[LiveDataResponse]):
|
||||
return False
|
||||
|
||||
|
||||
class IronOSFirmwareUpdateCoordinator(DataUpdateCoordinator[GitHubReleaseModel]):
|
||||
class IronOSFirmwareUpdateCoordinator(DataUpdateCoordinator[LatestRelease]):
|
||||
"""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."""
|
||||
super().__init__(
|
||||
hass,
|
||||
@ -118,21 +119,13 @@ class IronOSFirmwareUpdateCoordinator(DataUpdateCoordinator[GitHubReleaseModel])
|
||||
)
|
||||
self.github = github
|
||||
|
||||
async def _async_update_data(self) -> GitHubReleaseModel:
|
||||
async def _async_update_data(self) -> LatestRelease:
|
||||
"""Fetch data from Github."""
|
||||
|
||||
try:
|
||||
release = await self.github.repos.releases.latest("Ralim/IronOS")
|
||||
|
||||
except GitHubException as e:
|
||||
raise UpdateFailed(
|
||||
"Failed to retrieve latest release data from Github"
|
||||
) from e
|
||||
|
||||
if TYPE_CHECKING:
|
||||
assert release.data
|
||||
|
||||
return release.data
|
||||
return await self.github.latest_release()
|
||||
except UpdateException as e:
|
||||
raise UpdateFailed("Failed to check for latest IronOS update") from e
|
||||
|
||||
|
||||
class IronOSSettingsCoordinator(IronOSBaseCoordinator[SettingsDataResponse]):
|
||||
|
@ -12,6 +12,6 @@
|
||||
"dependencies": ["bluetooth_adapters"],
|
||||
"documentation": "https://www.home-assistant.io/integrations/iron_os",
|
||||
"iot_class": "local_polling",
|
||||
"loggers": ["pynecil", "aiogithubapi"],
|
||||
"requirements": ["pynecil==2.1.0", "aiogithubapi==24.6.0"]
|
||||
"loggers": ["pynecil"],
|
||||
"requirements": ["pynecil==2.1.0"]
|
||||
}
|
||||
|
@ -81,4 +81,4 @@ rules:
|
||||
inject-websession:
|
||||
status: exempt
|
||||
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_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.*]
|
||||
check_untyped_defs = true
|
||||
disallow_incomplete_defs = true
|
||||
|
@ -252,7 +252,6 @@ aioflo==2021.11.0
|
||||
aioftp==0.21.3
|
||||
|
||||
# homeassistant.components.github
|
||||
# homeassistant.components.iron_os
|
||||
aiogithubapi==24.6.0
|
||||
|
||||
# homeassistant.components.guardian
|
||||
|
@ -237,7 +237,6 @@ aioesphomeapi==28.0.0
|
||||
aioflo==2021.11.0
|
||||
|
||||
# homeassistant.components.github
|
||||
# homeassistant.components.iron_os
|
||||
aiogithubapi==24.6.0
|
||||
|
||||
# homeassistant.components.guardian
|
||||
|
@ -7,6 +7,7 @@ from bleak.backends.device import BLEDevice
|
||||
from habluetooth import BluetoothServiceInfoBleak
|
||||
from pynecil import (
|
||||
DeviceInfoResponse,
|
||||
LatestRelease,
|
||||
LiveDataResponse,
|
||||
OperatingMode,
|
||||
PowerSource,
|
||||
@ -114,24 +115,20 @@ def mock_ble_device() -> Generator[MagicMock]:
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def mock_githubapi() -> Generator[AsyncMock]:
|
||||
"""Mock aiogithubapi."""
|
||||
def mock_ironosupdate() -> Generator[AsyncMock]:
|
||||
"""Mock IronOSUpdate."""
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.iron_os.GitHubAPI",
|
||||
"homeassistant.components.iron_os.IronOSUpdate",
|
||||
autospec=True,
|
||||
) as mock_client:
|
||||
client = mock_client.return_value
|
||||
client.repos.releases.latest = AsyncMock()
|
||||
|
||||
client.repos.releases.latest.return_value.data.html_url = (
|
||||
"https://github.com/Ralim/IronOS/releases/tag/v2.22"
|
||||
client.latest_release.return_value = LatestRelease(
|
||||
html_url="https://github.com/Ralim/IronOS/releases/tag/v2.22",
|
||||
name="V2.22 | TS101 & S60 Added | PinecilV2 improved",
|
||||
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
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
from collections.abc import AsyncGenerator
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
from aiogithubapi import GitHubException
|
||||
from pynecil import UpdateException
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
@ -26,7 +26,7 @@ async def update_only() -> AsyncGenerator[None]:
|
||||
yield
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_pynecil", "ble_device", "mock_githubapi")
|
||||
@pytest.mark.usefixtures("mock_pynecil", "ble_device", "mock_ironosupdate")
|
||||
async def test_update(
|
||||
hass: HomeAssistant,
|
||||
config_entry: MockConfigEntry,
|
||||
@ -60,11 +60,11 @@ async def test_update(
|
||||
async def test_update_unavailable(
|
||||
hass: HomeAssistant,
|
||||
config_entry: MockConfigEntry,
|
||||
mock_githubapi: AsyncMock,
|
||||
mock_ironosupdate: AsyncMock,
|
||||
) -> None:
|
||||
"""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)
|
||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
Reference in New Issue
Block a user