mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Move volvooncall base entity to separate module (#126543)
This commit is contained in:
parent
8c4ea323ba
commit
95948e4eb7
@ -17,13 +17,8 @@ from homeassistant.const import (
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryAuthFailed
|
from homeassistant.exceptions import ConfigEntryAuthFailed
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
from homeassistant.helpers.device_registry import DeviceInfo
|
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||||
from homeassistant.helpers.update_coordinator import (
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||||
CoordinatorEntity,
|
|
||||||
DataUpdateCoordinator,
|
|
||||||
UpdateFailed,
|
|
||||||
)
|
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
CONF_MUTABLE,
|
CONF_MUTABLE,
|
||||||
@ -188,84 +183,3 @@ class VolvoUpdateCoordinator(DataUpdateCoordinator[None]): # pylint: disable=ha
|
|||||||
|
|
||||||
async with asyncio.timeout(10):
|
async with asyncio.timeout(10):
|
||||||
await self.volvo_data.update()
|
await self.volvo_data.update()
|
||||||
|
|
||||||
|
|
||||||
class VolvoEntity(CoordinatorEntity[VolvoUpdateCoordinator]):
|
|
||||||
"""Base class for all VOC entities."""
|
|
||||||
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
vin: str,
|
|
||||||
component: str,
|
|
||||||
attribute: str,
|
|
||||||
slug_attr: str,
|
|
||||||
coordinator: VolvoUpdateCoordinator,
|
|
||||||
) -> None:
|
|
||||||
"""Initialize the entity."""
|
|
||||||
super().__init__(coordinator)
|
|
||||||
|
|
||||||
self.vin = vin
|
|
||||||
self.component = component
|
|
||||||
self.attribute = attribute
|
|
||||||
self.slug_attr = slug_attr
|
|
||||||
|
|
||||||
@property
|
|
||||||
def instrument(self):
|
|
||||||
"""Return corresponding instrument."""
|
|
||||||
return self.coordinator.volvo_data.instrument(
|
|
||||||
self.vin, self.component, self.attribute, self.slug_attr
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def icon(self):
|
|
||||||
"""Return the icon."""
|
|
||||||
return self.instrument.icon
|
|
||||||
|
|
||||||
@property
|
|
||||||
def vehicle(self):
|
|
||||||
"""Return vehicle."""
|
|
||||||
return self.instrument.vehicle
|
|
||||||
|
|
||||||
@property
|
|
||||||
def _entity_name(self):
|
|
||||||
return self.instrument.name
|
|
||||||
|
|
||||||
@property
|
|
||||||
def _vehicle_name(self):
|
|
||||||
return self.coordinator.volvo_data.vehicle_name(self.vehicle)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
"""Return full name of the entity."""
|
|
||||||
return f"{self._vehicle_name} {self._entity_name}"
|
|
||||||
|
|
||||||
@property
|
|
||||||
def assumed_state(self):
|
|
||||||
"""Return true if unable to access real state of entity."""
|
|
||||||
return True
|
|
||||||
|
|
||||||
@property
|
|
||||||
def device_info(self) -> DeviceInfo:
|
|
||||||
"""Return a inique set of attributes for each vehicle."""
|
|
||||||
return DeviceInfo(
|
|
||||||
identifiers={(DOMAIN, self.vehicle.vin)},
|
|
||||||
name=self._vehicle_name,
|
|
||||||
model=self.vehicle.vehicle_type,
|
|
||||||
manufacturer="Volvo",
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def extra_state_attributes(self):
|
|
||||||
"""Return device specific state attributes."""
|
|
||||||
return dict(
|
|
||||||
self.instrument.attributes,
|
|
||||||
model=f"{self.vehicle.vehicle_type}/{self.vehicle.model_year}",
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def unique_id(self) -> str:
|
|
||||||
"""Return a unique ID."""
|
|
||||||
slug_override = ""
|
|
||||||
if self.instrument.slug_override is not None:
|
|
||||||
slug_override = f"-{self.instrument.slug_override}"
|
|
||||||
return f"{self.vin}-{self.component}-{self.attribute}{slug_override}"
|
|
||||||
|
@ -16,8 +16,9 @@ from homeassistant.core import HomeAssistant, callback
|
|||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import VolvoEntity, VolvoUpdateCoordinator
|
from . import VolvoUpdateCoordinator
|
||||||
from .const import DOMAIN, VOLVO_DISCOVERY_NEW
|
from .const import DOMAIN, VOLVO_DISCOVERY_NEW
|
||||||
|
from .entity import VolvoEntity
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
|
@ -10,8 +10,9 @@ from homeassistant.core import HomeAssistant, callback
|
|||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import VolvoEntity, VolvoUpdateCoordinator
|
from . import VolvoUpdateCoordinator
|
||||||
from .const import DOMAIN, VOLVO_DISCOVERY_NEW
|
from .const import DOMAIN, VOLVO_DISCOVERY_NEW
|
||||||
|
from .entity import VolvoEntity
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
|
88
homeassistant/components/volvooncall/entity.py
Normal file
88
homeassistant/components/volvooncall/entity.py
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
"""Support for Volvo On Call."""
|
||||||
|
|
||||||
|
from homeassistant.helpers.device_registry import DeviceInfo
|
||||||
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
|
from . import VolvoUpdateCoordinator
|
||||||
|
from .const import DOMAIN
|
||||||
|
|
||||||
|
|
||||||
|
class VolvoEntity(CoordinatorEntity[VolvoUpdateCoordinator]):
|
||||||
|
"""Base class for all VOC entities."""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
vin: str,
|
||||||
|
component: str,
|
||||||
|
attribute: str,
|
||||||
|
slug_attr: str,
|
||||||
|
coordinator: VolvoUpdateCoordinator,
|
||||||
|
) -> None:
|
||||||
|
"""Initialize the entity."""
|
||||||
|
super().__init__(coordinator)
|
||||||
|
|
||||||
|
self.vin = vin
|
||||||
|
self.component = component
|
||||||
|
self.attribute = attribute
|
||||||
|
self.slug_attr = slug_attr
|
||||||
|
|
||||||
|
@property
|
||||||
|
def instrument(self):
|
||||||
|
"""Return corresponding instrument."""
|
||||||
|
return self.coordinator.volvo_data.instrument(
|
||||||
|
self.vin, self.component, self.attribute, self.slug_attr
|
||||||
|
)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def icon(self):
|
||||||
|
"""Return the icon."""
|
||||||
|
return self.instrument.icon
|
||||||
|
|
||||||
|
@property
|
||||||
|
def vehicle(self):
|
||||||
|
"""Return vehicle."""
|
||||||
|
return self.instrument.vehicle
|
||||||
|
|
||||||
|
@property
|
||||||
|
def _entity_name(self):
|
||||||
|
return self.instrument.name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def _vehicle_name(self):
|
||||||
|
return self.coordinator.volvo_data.vehicle_name(self.vehicle)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self):
|
||||||
|
"""Return full name of the entity."""
|
||||||
|
return f"{self._vehicle_name} {self._entity_name}"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def assumed_state(self):
|
||||||
|
"""Return true if unable to access real state of entity."""
|
||||||
|
return True
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_info(self) -> DeviceInfo:
|
||||||
|
"""Return a inique set of attributes for each vehicle."""
|
||||||
|
return DeviceInfo(
|
||||||
|
identifiers={(DOMAIN, self.vehicle.vin)},
|
||||||
|
name=self._vehicle_name,
|
||||||
|
model=self.vehicle.vehicle_type,
|
||||||
|
manufacturer="Volvo",
|
||||||
|
)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def extra_state_attributes(self):
|
||||||
|
"""Return device specific state attributes."""
|
||||||
|
return dict(
|
||||||
|
self.instrument.attributes,
|
||||||
|
model=f"{self.vehicle.vehicle_type}/{self.vehicle.model_year}",
|
||||||
|
)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def unique_id(self) -> str:
|
||||||
|
"""Return a unique ID."""
|
||||||
|
slug_override = ""
|
||||||
|
if self.instrument.slug_override is not None:
|
||||||
|
slug_override = f"-{self.instrument.slug_override}"
|
||||||
|
return f"{self.vin}-{self.component}-{self.attribute}{slug_override}"
|
@ -12,8 +12,9 @@ from homeassistant.core import HomeAssistant, callback
|
|||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import VolvoEntity, VolvoUpdateCoordinator
|
from . import VolvoUpdateCoordinator
|
||||||
from .const import DOMAIN, VOLVO_DISCOVERY_NEW
|
from .const import DOMAIN, VOLVO_DISCOVERY_NEW
|
||||||
|
from .entity import VolvoEntity
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
|
@ -10,8 +10,9 @@ from homeassistant.core import HomeAssistant, callback
|
|||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import VolvoEntity, VolvoUpdateCoordinator
|
from . import VolvoUpdateCoordinator
|
||||||
from .const import DOMAIN, VOLVO_DISCOVERY_NEW
|
from .const import DOMAIN, VOLVO_DISCOVERY_NEW
|
||||||
|
from .entity import VolvoEntity
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
|
@ -12,8 +12,9 @@ from homeassistant.core import HomeAssistant, callback
|
|||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import VolvoEntity, VolvoUpdateCoordinator
|
from . import VolvoUpdateCoordinator
|
||||||
from .const import DOMAIN, VOLVO_DISCOVERY_NEW
|
from .const import DOMAIN, VOLVO_DISCOVERY_NEW
|
||||||
|
from .entity import VolvoEntity
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user