Migrate Season to new entity naming style (#75088)

This commit is contained in:
Franck Nijhof 2022-07-16 15:28:13 +02:00 committed by GitHub
parent 8d88562d40
commit 393610c534
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 3 deletions

View File

@ -14,6 +14,8 @@ from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.const import CONF_NAME, CONF_TYPE
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.device_registry import DeviceEntryType
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from homeassistant.util.dt import utcnow
@ -121,13 +123,18 @@ class SeasonSensorEntity(SensorEntity):
"""Representation of the current season."""
_attr_device_class = "season__season"
_attr_has_entity_name = True
def __init__(self, entry: ConfigEntry, hemisphere: str) -> None:
"""Initialize the season."""
self._attr_name = entry.title
self._attr_unique_id = entry.entry_id
self.hemisphere = hemisphere
self.type = entry.data[CONF_TYPE]
self._attr_device_info = DeviceInfo(
name=entry.title,
identifiers={(DOMAIN, entry.entry_id)},
entry_type=DeviceEntryType.SERVICE,
)
def update(self) -> None:
"""Update season."""

View File

@ -4,7 +4,11 @@ from datetime import datetime
from freezegun import freeze_time
import pytest
from homeassistant.components.season.const import TYPE_ASTRONOMICAL, TYPE_METEOROLOGICAL
from homeassistant.components.season.const import (
DOMAIN,
TYPE_ASTRONOMICAL,
TYPE_METEOROLOGICAL,
)
from homeassistant.components.season.sensor import (
STATE_AUTUMN,
STATE_SPRING,
@ -13,7 +17,7 @@ from homeassistant.components.season.sensor import (
)
from homeassistant.const import CONF_TYPE, STATE_UNKNOWN
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
from homeassistant.helpers import device_registry as dr, entity_registry as er
from tests.common import MockConfigEntry
@ -123,6 +127,14 @@ async def test_season_southern_hemisphere(
assert entry
assert entry.unique_id == mock_config_entry.entry_id
device_registry = dr.async_get(hass)
assert entry.device_id
device_entry = device_registry.async_get(entry.device_id)
assert device_entry
assert device_entry.identifiers == {(DOMAIN, mock_config_entry.entry_id)}
assert device_entry.name == "Season"
assert device_entry.entry_type is dr.DeviceEntryType.SERVICE
async def test_season_equator(
hass: HomeAssistant,