Remove YAML solution from Open Exchange Rates (#98815)
This commit is contained in:
parent
65691fffd6
commit
26d7e9958f
1 changed files with 4 additions and 13 deletions
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
|||
|
||||
from homeassistant.components.sensor import SensorEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_NAME, CONF_QUOTE
|
||||
from homeassistant.const import CONF_QUOTE
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
@ -21,14 +21,12 @@ async def async_setup_entry(
|
|||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Open Exchange Rates sensor."""
|
||||
# Only YAML imported configs have name and quote in config entry data.
|
||||
name: str | None = config_entry.data.get(CONF_NAME)
|
||||
quote: str = config_entry.data.get(CONF_QUOTE, "EUR")
|
||||
coordinator = hass.data[DOMAIN][config_entry.entry_id]
|
||||
|
||||
async_add_entities(
|
||||
OpenexchangeratesSensor(
|
||||
config_entry, coordinator, name, rate_quote, rate_quote == quote
|
||||
config_entry, coordinator, rate_quote, rate_quote == quote
|
||||
)
|
||||
for rate_quote in coordinator.data.rates
|
||||
)
|
||||
|
@ -39,13 +37,13 @@ class OpenexchangeratesSensor(
|
|||
):
|
||||
"""Representation of an Open Exchange Rates sensor."""
|
||||
|
||||
_attr_has_entity_name = True
|
||||
_attr_attribution = ATTRIBUTION
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
config_entry: ConfigEntry,
|
||||
coordinator: OpenexchangeratesCoordinator,
|
||||
name: str | None,
|
||||
quote: str,
|
||||
enabled: bool,
|
||||
) -> None:
|
||||
|
@ -58,14 +56,7 @@ class OpenexchangeratesSensor(
|
|||
name=f"Open Exchange Rates {coordinator.base}",
|
||||
)
|
||||
self._attr_entity_registry_enabled_default = enabled
|
||||
if name and enabled:
|
||||
# name is legacy imported from YAML config
|
||||
# this block can be removed when removing import from YAML
|
||||
self._attr_name = name
|
||||
self._attr_has_entity_name = False
|
||||
else:
|
||||
self._attr_name = quote
|
||||
self._attr_has_entity_name = True
|
||||
self._attr_name = quote
|
||||
self._attr_native_unit_of_measurement = quote
|
||||
self._attr_unique_id = f"{config_entry.entry_id}_{quote}"
|
||||
self._quote = quote
|
||||
|
|
Loading…
Add table
Reference in a new issue