Remove source and channel attributes from local version (#64827)

This commit is contained in:
Joakim Sørensen 2022-01-24 11:07:16 +01:00 committed by GitHub
parent 3b3a8db291
commit 92fbf0ee09
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 5 deletions

View file

@ -4,7 +4,7 @@ from __future__ import annotations
from typing import Any from typing import Any
from awesomeversion import AwesomeVersion from awesomeversion import AwesomeVersion
from pyhaversion import HaVersion from pyhaversion import HaVersion, HaVersionSource
from pyhaversion.exceptions import HaVersionException from pyhaversion.exceptions import HaVersionException
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
@ -41,8 +41,10 @@ class VersionDataUpdateCoordinator(DataUpdateCoordinator):
return str(self._version) if self._version else None return str(self._version) if self._version else None
@property @property
def version_data(self) -> dict[str, Any]: def version_data(self) -> dict[str, Any] | None:
"""Return the version data.""" """Return the version data."""
if self._api.source == HaVersionSource.LOCAL:
return None
return self._version_data or {} return self._version_data or {}
async def _async_update_data(self) -> None: async def _async_update_data(self) -> None:

View file

@ -122,6 +122,6 @@ class VersionSensorEntity(CoordinatorEntity, SensorEntity):
return self.coordinator.version return self.coordinator.version
@property @property
def extra_state_attributes(self) -> dict[str, Any]: def extra_state_attributes(self) -> dict[str, Any] | None:
"""Return extra state attributes of this sensor.""" """Return extra state attributes of this sensor."""
return self.coordinator.version_data return self.coordinator.version_data

View file

@ -57,8 +57,8 @@ async def test_version_sensor(hass: HomeAssistant):
state = hass.states.get("sensor.local_installation") state = hass.states.get("sensor.local_installation")
assert state.state == MOCK_VERSION assert state.state == MOCK_VERSION
assert state.attributes["source"] == "local" assert "source" not in state.attributes
assert state.attributes["channel"] == "stable" assert "channel" not in state.attributes
async def test_update(hass: HomeAssistant, caplog: pytest.LogCaptureFixture): async def test_update(hass: HomeAssistant, caplog: pytest.LogCaptureFixture):