mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 15:17:35 +00:00
Move tomorrowio base entity to separate module (#126531)
This commit is contained in:
parent
0fc7bc2762
commit
9c6f903178
@ -3,7 +3,6 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from pytomorrowio import TomorrowioV4
|
from pytomorrowio import TomorrowioV4
|
||||||
from pytomorrowio.const import CURRENT
|
|
||||||
|
|
||||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
||||||
from homeassistant.components.weather import DOMAIN as WEATHER_DOMAIN
|
from homeassistant.components.weather import DOMAIN as WEATHER_DOMAIN
|
||||||
@ -11,10 +10,8 @@ from homeassistant.config_entries import ConfigEntry
|
|||||||
from homeassistant.const import CONF_API_KEY
|
from homeassistant.const import CONF_API_KEY
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
|
||||||
|
|
||||||
from .const import ATTRIBUTION, DOMAIN, INTEGRATION_NAME
|
from .const import DOMAIN
|
||||||
from .coordinator import TomorrowioDataUpdateCoordinator
|
from .coordinator import TomorrowioDataUpdateCoordinator
|
||||||
|
|
||||||
PLATFORMS = [SENSOR_DOMAIN, WEATHER_DOMAIN]
|
PLATFORMS = [SENSOR_DOMAIN, WEATHER_DOMAIN]
|
||||||
@ -57,35 +54,3 @@ async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->
|
|||||||
hass.data.pop(DOMAIN)
|
hass.data.pop(DOMAIN)
|
||||||
|
|
||||||
return unload_ok
|
return unload_ok
|
||||||
|
|
||||||
|
|
||||||
class TomorrowioEntity(CoordinatorEntity[TomorrowioDataUpdateCoordinator]):
|
|
||||||
"""Base Tomorrow.io Entity."""
|
|
||||||
|
|
||||||
_attr_attribution = ATTRIBUTION
|
|
||||||
_attr_has_entity_name = True
|
|
||||||
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
config_entry: ConfigEntry,
|
|
||||||
coordinator: TomorrowioDataUpdateCoordinator,
|
|
||||||
api_version: int,
|
|
||||||
) -> None:
|
|
||||||
"""Initialize Tomorrow.io Entity."""
|
|
||||||
super().__init__(coordinator)
|
|
||||||
self.api_version = api_version
|
|
||||||
self._config_entry = config_entry
|
|
||||||
self._attr_device_info = DeviceInfo(
|
|
||||||
identifiers={(DOMAIN, self._config_entry.data[CONF_API_KEY])},
|
|
||||||
manufacturer=INTEGRATION_NAME,
|
|
||||||
sw_version=f"v{self.api_version}",
|
|
||||||
entry_type=DeviceEntryType.SERVICE,
|
|
||||||
)
|
|
||||||
|
|
||||||
def _get_current_property(self, property_name: str) -> int | str | float | None:
|
|
||||||
"""Get property from current conditions.
|
|
||||||
|
|
||||||
Used for V4 API.
|
|
||||||
"""
|
|
||||||
entry_id = self._config_entry.entry_id
|
|
||||||
return self.coordinator.data[entry_id].get(CURRENT, {}).get(property_name)
|
|
||||||
|
45
homeassistant/components/tomorrowio/entity.py
Normal file
45
homeassistant/components/tomorrowio/entity.py
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
"""The Tomorrow.io integration."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from pytomorrowio.const import CURRENT
|
||||||
|
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
from homeassistant.const import CONF_API_KEY
|
||||||
|
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
||||||
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
|
from .const import ATTRIBUTION, DOMAIN, INTEGRATION_NAME
|
||||||
|
from .coordinator import TomorrowioDataUpdateCoordinator
|
||||||
|
|
||||||
|
|
||||||
|
class TomorrowioEntity(CoordinatorEntity[TomorrowioDataUpdateCoordinator]):
|
||||||
|
"""Base Tomorrow.io Entity."""
|
||||||
|
|
||||||
|
_attr_attribution = ATTRIBUTION
|
||||||
|
_attr_has_entity_name = True
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
config_entry: ConfigEntry,
|
||||||
|
coordinator: TomorrowioDataUpdateCoordinator,
|
||||||
|
api_version: int,
|
||||||
|
) -> None:
|
||||||
|
"""Initialize Tomorrow.io Entity."""
|
||||||
|
super().__init__(coordinator)
|
||||||
|
self.api_version = api_version
|
||||||
|
self._config_entry = config_entry
|
||||||
|
self._attr_device_info = DeviceInfo(
|
||||||
|
identifiers={(DOMAIN, self._config_entry.data[CONF_API_KEY])},
|
||||||
|
manufacturer=INTEGRATION_NAME,
|
||||||
|
sw_version=f"v{self.api_version}",
|
||||||
|
entry_type=DeviceEntryType.SERVICE,
|
||||||
|
)
|
||||||
|
|
||||||
|
def _get_current_property(self, property_name: str) -> int | str | float | None:
|
||||||
|
"""Get property from current conditions.
|
||||||
|
|
||||||
|
Used for V4 API.
|
||||||
|
"""
|
||||||
|
entry_id = self._config_entry.entry_id
|
||||||
|
return self.coordinator.data[entry_id].get(CURRENT, {}).get(property_name)
|
@ -38,7 +38,6 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|||||||
from homeassistant.util.unit_conversion import DistanceConverter, SpeedConverter
|
from homeassistant.util.unit_conversion import DistanceConverter, SpeedConverter
|
||||||
from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM
|
from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM
|
||||||
|
|
||||||
from . import TomorrowioEntity
|
|
||||||
from .const import (
|
from .const import (
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
TMRW_ATTR_CARBON_MONOXIDE,
|
TMRW_ATTR_CARBON_MONOXIDE,
|
||||||
@ -70,6 +69,7 @@ from .const import (
|
|||||||
TMRW_ATTR_WIND_GUST,
|
TMRW_ATTR_WIND_GUST,
|
||||||
)
|
)
|
||||||
from .coordinator import TomorrowioDataUpdateCoordinator
|
from .coordinator import TomorrowioDataUpdateCoordinator
|
||||||
|
from .entity import TomorrowioEntity
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
|
@ -37,7 +37,6 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|||||||
from homeassistant.helpers.sun import is_up
|
from homeassistant.helpers.sun import is_up
|
||||||
from homeassistant.util import dt as dt_util
|
from homeassistant.util import dt as dt_util
|
||||||
|
|
||||||
from . import TomorrowioEntity
|
|
||||||
from .const import (
|
from .const import (
|
||||||
CLEAR_CONDITIONS,
|
CLEAR_CONDITIONS,
|
||||||
CONDITIONS,
|
CONDITIONS,
|
||||||
@ -61,6 +60,7 @@ from .const import (
|
|||||||
TMRW_ATTR_WIND_SPEED,
|
TMRW_ATTR_WIND_SPEED,
|
||||||
)
|
)
|
||||||
from .coordinator import TomorrowioDataUpdateCoordinator
|
from .coordinator import TomorrowioDataUpdateCoordinator
|
||||||
|
from .entity import TomorrowioEntity
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user