mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Remove YAML solution from Open Exchange Rates (#98815)
This commit is contained in:
parent
65691fffd6
commit
26d7e9958f
@ -3,7 +3,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from homeassistant.components.sensor import SensorEntity
|
from homeassistant.components.sensor import SensorEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
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.core import HomeAssistant
|
||||||
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
@ -21,14 +21,12 @@ async def async_setup_entry(
|
|||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the Open Exchange Rates sensor."""
|
"""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")
|
quote: str = config_entry.data.get(CONF_QUOTE, "EUR")
|
||||||
coordinator = hass.data[DOMAIN][config_entry.entry_id]
|
coordinator = hass.data[DOMAIN][config_entry.entry_id]
|
||||||
|
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
OpenexchangeratesSensor(
|
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
|
for rate_quote in coordinator.data.rates
|
||||||
)
|
)
|
||||||
@ -39,13 +37,13 @@ class OpenexchangeratesSensor(
|
|||||||
):
|
):
|
||||||
"""Representation of an Open Exchange Rates sensor."""
|
"""Representation of an Open Exchange Rates sensor."""
|
||||||
|
|
||||||
|
_attr_has_entity_name = True
|
||||||
_attr_attribution = ATTRIBUTION
|
_attr_attribution = ATTRIBUTION
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
config_entry: ConfigEntry,
|
config_entry: ConfigEntry,
|
||||||
coordinator: OpenexchangeratesCoordinator,
|
coordinator: OpenexchangeratesCoordinator,
|
||||||
name: str | None,
|
|
||||||
quote: str,
|
quote: str,
|
||||||
enabled: bool,
|
enabled: bool,
|
||||||
) -> None:
|
) -> None:
|
||||||
@ -58,14 +56,7 @@ class OpenexchangeratesSensor(
|
|||||||
name=f"Open Exchange Rates {coordinator.base}",
|
name=f"Open Exchange Rates {coordinator.base}",
|
||||||
)
|
)
|
||||||
self._attr_entity_registry_enabled_default = enabled
|
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_name = quote
|
||||||
self._attr_has_entity_name = True
|
|
||||||
self._attr_native_unit_of_measurement = quote
|
self._attr_native_unit_of_measurement = quote
|
||||||
self._attr_unique_id = f"{config_entry.entry_id}_{quote}"
|
self._attr_unique_id = f"{config_entry.entry_id}_{quote}"
|
||||||
self._quote = quote
|
self._quote = quote
|
||||||
|
Loading…
x
Reference in New Issue
Block a user