mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Migrate Season to new entity naming style (#75088)
This commit is contained in:
parent
8d88562d40
commit
393610c534
@ -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."""
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user