Remove deprecated Updater integration (#68981)

* Remove deprecated Updater integration

* Remove updater mock
This commit is contained in:
Franck Nijhof 2022-03-31 16:39:57 +02:00 committed by GitHub
parent 4e2b6db397
commit 2c66ac6203
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
58 changed files with 0 additions and 496 deletions

View File

@ -1076,8 +1076,6 @@ build.json @home-assistant/supervisor
/tests/components/upcloud/ @scop
/homeassistant/components/update/ @home-assistant/core
/tests/components/update/ @home-assistant/core
/homeassistant/components/updater/ @home-assistant/core
/tests/components/updater/ @home-assistant/core
/homeassistant/components/upnp/ @StevenLooman @ehendrix23
/tests/components/upnp/ @StevenLooman @ehendrix23
/homeassistant/components/uptime/ @frenck

View File

@ -1,141 +0,0 @@
"""Support to check for available updates."""
import asyncio
from datetime import timedelta
import logging
import async_timeout
from awesomeversion import AwesomeVersion
import voluptuous as vol
from homeassistant.components import hassio
from homeassistant.const import Platform, __version__ as current_version
from homeassistant.core import HomeAssistant
from homeassistant.helpers import discovery, update_coordinator
from homeassistant.helpers.aiohttp_client import async_get_clientsession
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.typing import ConfigType
_LOGGER = logging.getLogger(__name__)
ATTR_RELEASE_NOTES = "release_notes"
ATTR_NEWEST_VERSION = "newest_version"
CONF_REPORTING = "reporting"
CONF_COMPONENT_REPORTING = "include_used_components"
DOMAIN = "updater"
UPDATER_URL = "https://www.home-assistant.io/version.json"
CONFIG_SCHEMA = vol.Schema(
{
DOMAIN: {
vol.Optional(CONF_REPORTING): cv.boolean,
vol.Optional(CONF_COMPONENT_REPORTING): cv.boolean,
}
},
extra=vol.ALLOW_EXTRA,
)
RESPONSE_SCHEMA = vol.Schema(
{vol.Required("current_version"): cv.string, vol.Required("release_notes"): cv.url},
extra=vol.REMOVE_EXTRA,
)
class Updater:
"""Updater class for data exchange."""
def __init__(
self, update_available: bool, newest_version: str, release_notes: str
) -> None:
"""Initialize attributes."""
self.update_available = update_available
self.release_notes = release_notes
self.newest_version = newest_version
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the updater component."""
_LOGGER.warning(
"The updater integration has been deprecated and will be removed in 2022.5, "
"please remove it from your configuration"
)
async def check_new_version() -> Updater:
"""Check if a new version is available and report if one is."""
# Skip on dev
if "dev" in current_version:
return Updater(False, "", "")
newest, release_notes = await get_newest_version(hass)
_LOGGER.debug("Fetched version %s: %s", newest, release_notes)
# Load data from Supervisor
if hassio.is_hassio(hass):
core_info = hassio.get_core_info(hass)
newest = core_info["version_latest"]
# Validate version
update_available = False
if AwesomeVersion(newest) > AwesomeVersion(current_version):
_LOGGER.debug(
"The latest available version of Home Assistant is %s", newest
)
update_available = True
elif AwesomeVersion(newest) == AwesomeVersion(current_version):
_LOGGER.debug(
"You are on the latest version (%s) of Home Assistant", newest
)
elif AwesomeVersion(newest) < AwesomeVersion(current_version):
_LOGGER.debug(
"Local version (%s) is newer than the latest available version (%s)",
current_version,
newest,
)
_LOGGER.debug("Update available: %s", update_available)
return Updater(update_available, newest, release_notes)
coordinator = hass.data[DOMAIN] = update_coordinator.DataUpdateCoordinator[Updater](
hass,
_LOGGER,
name="Home Assistant update",
update_method=check_new_version,
update_interval=timedelta(days=1),
)
# This can take up to 15s which can delay startup
asyncio.create_task(coordinator.async_refresh())
hass.async_create_task(
discovery.async_load_platform(hass, Platform.BINARY_SENSOR, DOMAIN, {}, config)
)
return True
async def get_newest_version(hass):
"""Get the newest Home Assistant version."""
session = async_get_clientsession(hass)
async with async_timeout.timeout(30):
req = await session.get(UPDATER_URL)
try:
res = await req.json()
except ValueError as err:
raise update_coordinator.UpdateFailed(
"Received invalid JSON from Home Assistant Update"
) from err
try:
res = RESPONSE_SCHEMA(res)
return res["current_version"], res["release_notes"]
except vol.Invalid as err:
raise update_coordinator.UpdateFailed(
f"Got unexpected response: {err}"
) from err

View File

@ -1,56 +0,0 @@
"""Support for Home Assistant Updater binary sensors."""
from __future__ import annotations
from homeassistant.components.binary_sensor import (
BinarySensorDeviceClass,
BinarySensorEntity,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from . import ATTR_NEWEST_VERSION, ATTR_RELEASE_NOTES, DOMAIN as UPDATER_DOMAIN
async def async_setup_platform(
hass: HomeAssistant,
config: ConfigType,
async_add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up the updater binary sensors."""
if discovery_info is None:
return
async_add_entities([UpdaterBinary(hass.data[UPDATER_DOMAIN])])
class UpdaterBinary(CoordinatorEntity, BinarySensorEntity):
"""Representation of an updater binary sensor."""
_attr_device_class = BinarySensorDeviceClass.UPDATE
_attr_name = "Updater"
_attr_unique_id = "updater"
@property
def available(self) -> bool:
"""Return if entity is available."""
return True
@property
def is_on(self) -> bool:
"""Return true if there is an update available."""
return self.coordinator.data and self.coordinator.data.update_available
@property
def extra_state_attributes(self) -> dict | None:
"""Return the optional state attributes."""
if not self.coordinator.data:
return None
data = {}
if self.coordinator.data.release_notes:
data[ATTR_RELEASE_NOTES] = self.coordinator.data.release_notes
if self.coordinator.data.newest_version:
data[ATTR_NEWEST_VERSION] = self.coordinator.data.newest_version
return data

View File

@ -1,8 +0,0 @@
{
"domain": "updater",
"name": "Updater",
"documentation": "https://www.home-assistant.io/integrations/updater",
"codeowners": ["@home-assistant/core"],
"quality_scale": "internal",
"iot_class": "cloud_polling"
}

View File

@ -1 +0,0 @@
{ "title": "Updater" }

View File

@ -1,3 +0,0 @@
{
"title": "Opdateerder"
}

View File

@ -1,3 +0,0 @@
{
"title": "\u062a\u062d\u062f\u064a\u062b"
}

View File

@ -1,3 +0,0 @@
{
"title": "\u041e\u0431\u043d\u043e\u0432\u044f\u0432\u0430\u043d\u0435"
}

View File

@ -1,3 +0,0 @@
{
"title": "Updater"
}

View File

@ -1,3 +0,0 @@
{
"title": "Actualitzador"
}

View File

@ -1,3 +0,0 @@
{
"title": "Aktualiz\u00e1tor"
}

View File

@ -1,3 +0,0 @@
{
"title": "Diweddarwr"
}

View File

@ -1,3 +0,0 @@
{
"title": "Opdater"
}

View File

@ -1,3 +0,0 @@
{
"title": "Updater"
}

View File

@ -1,3 +0,0 @@
{
"title": "\u0395\u03bd\u03b7\u03bc\u03b5\u03c1\u03c9\u03c4\u03ae\u03c2"
}

View File

@ -1,3 +0,0 @@
{
"title": "Updater"
}

View File

@ -1,3 +0,0 @@
{
"title": "Actualizador"
}

View File

@ -1,3 +0,0 @@
{
"title": "Actualizador"
}

View File

@ -1,3 +0,0 @@
{
"title": "Uuendaja"
}

View File

@ -1,3 +0,0 @@
{
"title": "Eguneratzailea"
}

View File

@ -1,3 +0,0 @@
{
"title": "\u0628\u0647 \u0631\u0648\u0632 \u0631\u0633\u0627\u0646"
}

View File

@ -1,3 +0,0 @@
{
"title": "P\u00e4ivitys"
}

View File

@ -1,3 +0,0 @@
{
"title": "Mise \u00e0 jour"
}

View File

@ -1,3 +0,0 @@
{
"title": "Updater"
}

View File

@ -1,3 +0,0 @@
{
"title": "\u05de\u05e2\u05d3\u05db\u05df"
}

View File

@ -1,3 +0,0 @@
{
"title": "A\u017euriranje"
}

View File

@ -1,3 +0,0 @@
{
"title": "Friss\u00edt\u0151"
}

View File

@ -1,3 +0,0 @@
{
"title": "\u0539\u0561\u0580\u0574\u0561\u0581\u0576\u0578\u0572"
}

View File

@ -1,3 +0,0 @@
{
"title": "Pembaru"
}

View File

@ -1,3 +0,0 @@
{
"title": "Uppf\u00e6rslu\u00e1lfur"
}

View File

@ -1,3 +0,0 @@
{
"title": "Aggiornamento"
}

View File

@ -1,3 +0,0 @@
{
"title": "\u30a2\u30c3\u30d7\u30c7\u30fc\u30bf\u30fc"
}

View File

@ -1,3 +0,0 @@
{
"title": "\uc5c5\ub370\uc774\ud130"
}

View File

@ -1,3 +0,0 @@
{
"title": "Aktualis\u00e9ierung"
}

View File

@ -1,3 +0,0 @@
{
"title": "Atjaunin\u0101t\u0101js"
}

View File

@ -1,3 +0,0 @@
{
"title": "Oppdater"
}

View File

@ -1,3 +0,0 @@
{
"title": "Updater"
}

View File

@ -1,3 +0,0 @@
{
"title": "Oppdateringar"
}

View File

@ -1,3 +0,0 @@
{
"title": "Oppdaterer"
}

View File

@ -1,3 +0,0 @@
{
"title": "Aktualizator"
}

View File

@ -1,3 +0,0 @@
{
"title": "Gerenciador de atualiza\u00e7\u00f5es"
}

View File

@ -1,3 +0,0 @@
{
"title": "Atualizador"
}

View File

@ -1,3 +0,0 @@
{
"title": "Updater"
}

View File

@ -1,3 +0,0 @@
{
"title": "\u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435"
}

View File

@ -1,3 +0,0 @@
{
"title": "Aktualiz\u00e1tor"
}

View File

@ -1,3 +0,0 @@
{
"title": "Posodabljalnik"
}

View File

@ -1,3 +0,0 @@
{
"title": "Uppdaterare"
}

View File

@ -1,3 +0,0 @@
{
"title": "\u0b85\u0baa\u0bcd\u0b9f\u0bc7\u0b9f\u0bcd\u0b9f\u0bb0\u0bcd"
}

View File

@ -1,3 +0,0 @@
{
"title": "Updater"
}

View File

@ -1,3 +0,0 @@
{
"title": "\u0e2d\u0e31\u0e1e\u0e40\u0e14\u0e15"
}

View File

@ -1,3 +0,0 @@
{
"title": "G\u00fcncelleyici"
}

View File

@ -1,3 +0,0 @@
{
"title": "\u041e\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044f"
}

View File

@ -1,3 +0,0 @@
{
"title": "Tr\u00ecnh c\u1eadp nh\u1eadt"
}

View File

@ -1,3 +0,0 @@
{
"title": "\u66f4\u65b0\u63d0\u793a"
}

View File

@ -1,3 +0,0 @@
{
"title": "\u66f4\u65b0\u5668"
}

View File

@ -15,13 +15,6 @@ def mock_ssdp():
yield
@pytest.fixture(autouse=True)
def mock_updater():
"""Mock updater."""
with patch("homeassistant.components.updater.get_newest_version"):
yield
@pytest.fixture(autouse=True)
def recorder_url_mock():
"""Mock recorder url."""

View File

@ -1 +0,0 @@
"""Tests for the updater component."""

View File

@ -1,130 +0,0 @@
"""The tests for the Updater integration."""
from unittest.mock import patch
import pytest
from homeassistant.components import updater
from homeassistant.helpers.update_coordinator import UpdateFailed
from homeassistant.setup import async_setup_component
from tests.common import mock_component
NEW_VERSION = "10000.0"
MOCK_VERSION = "10.0"
MOCK_DEV_VERSION = "10.0.dev0"
MOCK_RESPONSE = {
"current_version": "0.15",
"release_notes": "https://home-assistant.io",
}
MOCK_CONFIG = {updater.DOMAIN: {"reporting": True}}
RELEASE_NOTES = "test release notes"
@pytest.fixture(autouse=True)
def mock_version():
"""Mock current version."""
with patch("homeassistant.components.updater.current_version", MOCK_VERSION):
yield
@pytest.fixture(name="mock_get_newest_version")
def mock_get_newest_version_fixture():
"""Fixture to mock get_newest_version."""
with patch(
"homeassistant.components.updater.get_newest_version",
return_value=(NEW_VERSION, RELEASE_NOTES),
) as mock:
yield mock
async def test_new_version_shows_entity_true(hass, mock_get_newest_version):
"""Test if sensor is true if new version is available."""
assert await async_setup_component(hass, updater.DOMAIN, {updater.DOMAIN: {}})
await hass.async_block_till_done()
assert hass.states.is_state("binary_sensor.updater", "on")
assert (
hass.states.get("binary_sensor.updater").attributes["newest_version"]
== NEW_VERSION
)
assert (
hass.states.get("binary_sensor.updater").attributes["release_notes"]
== RELEASE_NOTES
)
async def test_same_version_shows_entity_false(hass, mock_get_newest_version):
"""Test if sensor is false if no new version is available."""
mock_get_newest_version.return_value = (MOCK_VERSION, "")
assert await async_setup_component(hass, updater.DOMAIN, {updater.DOMAIN: {}})
await hass.async_block_till_done()
assert hass.states.is_state("binary_sensor.updater", "off")
assert (
hass.states.get("binary_sensor.updater").attributes["newest_version"]
== MOCK_VERSION
)
assert "release_notes" not in hass.states.get("binary_sensor.updater").attributes
async def test_deprecated_reporting(hass, mock_get_newest_version, caplog):
"""Test we do not gather analytics when disable reporting is active."""
mock_get_newest_version.return_value = (MOCK_VERSION, "")
assert await async_setup_component(
hass, updater.DOMAIN, {updater.DOMAIN: {"reporting": True}}
)
await hass.async_block_till_done()
assert "deprecated" in caplog.text
async def test_error_fetching_new_version_bad_json(hass, aioclient_mock):
"""Test we handle json error while fetching new version."""
aioclient_mock.get(updater.UPDATER_URL, text="not json")
with patch(
"homeassistant.helpers.system_info.async_get_system_info",
return_value={"fake": "bla"},
), pytest.raises(UpdateFailed):
await updater.get_newest_version(hass)
async def test_error_fetching_new_version_invalid_response(hass, aioclient_mock):
"""Test we handle response error while fetching new version."""
aioclient_mock.get(
updater.UPDATER_URL,
json={
"version": "0.15"
# 'release-notes' is missing
},
)
with patch(
"homeassistant.helpers.system_info.async_get_system_info",
return_value={"fake": "bla"},
), pytest.raises(UpdateFailed):
await updater.get_newest_version(hass)
async def test_new_version_shows_entity_after_hour_hassio(
hass, mock_get_newest_version
):
"""Test if binary sensor gets updated if new version is available / Hass.io."""
mock_component(hass, "hassio")
hass.data["hassio_core_info"] = {"version_latest": "999.0"}
assert await async_setup_component(hass, updater.DOMAIN, {updater.DOMAIN: {}})
await hass.async_block_till_done()
assert hass.states.is_state("binary_sensor.updater", "on")
assert (
hass.states.get("binary_sensor.updater").attributes["newest_version"] == "999.0"
)
assert (
hass.states.get("binary_sensor.updater").attributes["release_notes"]
== RELEASE_NOTES
)