mirror of
https://github.com/home-assistant/core.git
synced 2026-09-24 07:25:52 -05:00
Use EntityStateAttribute enum in integration (#175933)
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
89b7a91742
commit
2582f6f5a9
@@ -8,12 +8,7 @@ import voluptuous as vol
|
||||
from homeassistant.components.counter import DOMAIN as COUNTER_DOMAIN
|
||||
from homeassistant.components.input_number import DOMAIN as INPUT_NUMBER_DOMAIN
|
||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
||||
from homeassistant.const import (
|
||||
ATTR_UNIT_OF_MEASUREMENT,
|
||||
CONF_METHOD,
|
||||
CONF_NAME,
|
||||
UnitOfTime,
|
||||
)
|
||||
from homeassistant.const import CONF_METHOD, CONF_NAME, EntityStateAttribute, UnitOfTime
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers import selector
|
||||
from homeassistant.helpers.schema_config_entry_flow import (
|
||||
@@ -62,13 +57,16 @@ def entity_selector_compatible(
|
||||
"""Return an entity selector which compatible entities."""
|
||||
current = handler.hass.states.get(handler.options[CONF_SOURCE_SENSOR])
|
||||
unit_of_measurement = (
|
||||
current.attributes.get(ATTR_UNIT_OF_MEASUREMENT) if current else None
|
||||
current.attributes.get(EntityStateAttribute.UNIT_OF_MEASUREMENT)
|
||||
if current
|
||||
else None
|
||||
)
|
||||
|
||||
entities = [
|
||||
ent.entity_id
|
||||
for ent in handler.hass.states.async_all(ALLOWED_DOMAINS)
|
||||
if ent.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == unit_of_measurement
|
||||
if ent.attributes.get(EntityStateAttribute.UNIT_OF_MEASUREMENT)
|
||||
== unit_of_measurement
|
||||
and ent.domain in ALLOWED_DOMAINS
|
||||
]
|
||||
|
||||
|
||||
@@ -20,12 +20,11 @@ from homeassistant.components.sensor import (
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
ATTR_DEVICE_CLASS,
|
||||
ATTR_UNIT_OF_MEASUREMENT,
|
||||
CONF_METHOD,
|
||||
CONF_NAME,
|
||||
CONF_UNIQUE_ID,
|
||||
STATE_UNAVAILABLE,
|
||||
EntityStateAttribute,
|
||||
UnitOfTime,
|
||||
)
|
||||
from homeassistant.core import (
|
||||
@@ -389,7 +388,9 @@ class IntegrationSensor(RestoreSensor):
|
||||
return device_class
|
||||
|
||||
def _derive_and_set_attributes_from_state(self, source_state: State) -> None:
|
||||
source_unit = source_state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
|
||||
source_unit = source_state.attributes.get(
|
||||
EntityStateAttribute.UNIT_OF_MEASUREMENT
|
||||
)
|
||||
if source_unit is not None:
|
||||
self._unit_of_measurement = self._calculate_unit(source_unit)
|
||||
else:
|
||||
@@ -397,7 +398,8 @@ class IntegrationSensor(RestoreSensor):
|
||||
self._unit_of_measurement = None
|
||||
|
||||
self._attr_device_class = self._calculate_device_class(
|
||||
source_state.attributes.get(ATTR_DEVICE_CLASS), self.unit_of_measurement
|
||||
source_state.attributes.get(EntityStateAttribute.DEVICE_CLASS),
|
||||
self.unit_of_measurement,
|
||||
)
|
||||
if self._attr_device_class:
|
||||
# Remove this sensors icon default and allow
|
||||
|
||||
Reference in New Issue
Block a user