diff --git a/homeassistant/components/season/sensor.py b/homeassistant/components/season/sensor.py index 216475f0cdf..5fc161062bb 100644 --- a/homeassistant/components/season/sensor.py +++ b/homeassistant/components/season/sensor.py @@ -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.""" diff --git a/tests/components/season/test_sensor.py b/tests/components/season/test_sensor.py index 90d01106bba..0c2470edb7b 100644 --- a/tests/components/season/test_sensor.py +++ b/tests/components/season/test_sensor.py @@ -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,