diff --git a/homeassistant/components/sensor/__init__.py b/homeassistant/components/sensor/__init__.py index e7f4b00fd773b..29d31d10ffc48 100644 --- a/homeassistant/components/sensor/__init__.py +++ b/homeassistant/components/sensor/__init__.py @@ -63,6 +63,7 @@ from homeassistant.helpers.typing import UNDEFINED, ConfigType, StateType, UndefinedType from homeassistant.util import dt as dt_util from homeassistant.util.enum import try_parse_enum +from homeassistant.util.hass_dict import HassKey from .const import ( # noqa: F401 _DEPRECATED_STATE_CLASS_MEASUREMENT, @@ -88,6 +89,7 @@ _LOGGER: Final = logging.getLogger(__name__) +DOMAIN_DATA: HassKey[EntityComponent[SensorEntity]] = HassKey(DOMAIN) ENTITY_ID_FORMAT: Final = DOMAIN + ".{}" PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA PLATFORM_SCHEMA_BASE = cv.PLATFORM_SCHEMA_BASE @@ -115,7 +117,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: """Track states and offer events for sensors.""" - component = hass.data[DOMAIN] = EntityComponent[SensorEntity]( + component = hass.data[DOMAIN_DATA] = EntityComponent[SensorEntity]( _LOGGER, DOMAIN, hass, SCAN_INTERVAL ) @@ -126,14 +128,12 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up a config entry.""" - component: EntityComponent[SensorEntity] = hass.data[DOMAIN] - return await component.async_setup_entry(entry) + return await hass.data[DOMAIN_DATA].async_setup_entry(entry) async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Unload a config entry.""" - component: EntityComponent[SensorEntity] = hass.data[DOMAIN] - return await component.async_unload_entry(entry) + return await hass.data[DOMAIN_DATA].async_unload_entry(entry) class SensorEntityDescription(EntityDescription, frozen_or_thawed=True): diff --git a/homeassistant/components/sensor/recorder.py b/homeassistant/components/sensor/recorder.py index fce41a13ca61c..462b25dd55263 100644 --- a/homeassistant/components/sensor/recorder.py +++ b/homeassistant/components/sensor/recorder.py @@ -37,6 +37,7 @@ from homeassistant.loader import async_suggest_report_issue from homeassistant.util import dt as dt_util from homeassistant.util.enum import try_parse_enum +from homeassistant.util.hass_dict import HassKey from .const import ( ATTR_LAST_RESET, @@ -63,14 +64,15 @@ "ft³/m": UnitOfVolumeFlowRate.CUBIC_FEET_PER_MINUTE, } + # Keep track of entities for which a warning about decreasing value has been logged -SEEN_DIP = "sensor_seen_total_increasing_dip" -WARN_DIP = "sensor_warn_total_increasing_dip" +SEEN_DIP: HassKey[set[str]] = HassKey(f"{DOMAIN}_seen_total_increasing_dip") +WARN_DIP: HassKey[set[str]] = HassKey(f"{DOMAIN}_warn_total_increasing_dip") # Keep track of entities for which a warning about negative value has been logged -WARN_NEGATIVE = "sensor_warn_total_increasing_negative" +WARN_NEGATIVE: HassKey[set[str]] = HassKey(f"{DOMAIN}_warn_total_increasing_negative") # Keep track of entities for which a warning about unsupported unit has been logged -WARN_UNSUPPORTED_UNIT = "sensor_warn_unsupported_unit" -WARN_UNSTABLE_UNIT = "sensor_warn_unstable_unit" +WARN_UNSUPPORTED_UNIT: HassKey[set[str]] = HassKey(f"{DOMAIN}_warn_unsupported_unit") +WARN_UNSTABLE_UNIT: HassKey[set[str]] = HassKey(f"{DOMAIN}_warn_unstable_unit") # Link to dev statistics where issues around LTS can be fixed LINK_DEV_STATISTICS = "https://my.home-assistant.io/redirect/developer_statistics"