mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
Move ProxmoxEntity to entity.py (#90480)
* Move ProxmoxEntity to entity.py * Update homeassistant/components/proxmoxve/entity.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/proxmoxve/entity.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/proxmoxve/entity.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/proxmoxve/entity.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/proxmoxve/binary_sensor.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> --------- Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
This commit is contained in:
parent
7010447b04
commit
43a7247dde
@ -22,10 +22,7 @@ from homeassistant.core import HomeAssistant
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.discovery import async_load_platform
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.helpers.update_coordinator import (
|
||||
CoordinatorEntity,
|
||||
DataUpdateCoordinator,
|
||||
)
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||
|
||||
from .const import (
|
||||
_LOGGER,
|
||||
@ -252,54 +249,6 @@ def call_api_container_vm(
|
||||
return status
|
||||
|
||||
|
||||
class ProxmoxEntity(CoordinatorEntity):
|
||||
"""Represents any entity created for the Proxmox VE platform."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
coordinator: DataUpdateCoordinator,
|
||||
unique_id: str,
|
||||
name: str,
|
||||
icon: str,
|
||||
host_name: str,
|
||||
node_name: str,
|
||||
vm_id: int | None = None,
|
||||
) -> None:
|
||||
"""Initialize the Proxmox entity."""
|
||||
super().__init__(coordinator)
|
||||
|
||||
self.coordinator = coordinator
|
||||
self._unique_id = unique_id
|
||||
self._name = name
|
||||
self._host_name = host_name
|
||||
self._icon = icon
|
||||
self._available = True
|
||||
self._node_name = node_name
|
||||
self._vm_id = vm_id
|
||||
|
||||
self._state = None
|
||||
|
||||
@property
|
||||
def unique_id(self) -> str:
|
||||
"""Return the unique ID for this sensor."""
|
||||
return self._unique_id
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
"""Return the name of the entity."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def icon(self) -> str:
|
||||
"""Return the mdi icon of the entity."""
|
||||
return self._icon
|
||||
|
||||
@property
|
||||
def available(self) -> bool:
|
||||
"""Return True if entity is available."""
|
||||
return self.coordinator.last_update_success and self._available
|
||||
|
||||
|
||||
class ProxmoxClient:
|
||||
"""A wrapper for the proxmoxer ProxmoxAPI client."""
|
||||
|
||||
|
@ -10,7 +10,8 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||
|
||||
from . import COORDINATORS, DOMAIN, PROXMOX_CLIENTS, ProxmoxEntity
|
||||
from .const import COORDINATORS, DOMAIN, PROXMOX_CLIENTS
|
||||
from .entity import ProxmoxEntity
|
||||
|
||||
|
||||
async def async_setup_platform(
|
||||
|
39
homeassistant/components/proxmoxve/entity.py
Normal file
39
homeassistant/components/proxmoxve/entity.py
Normal file
@ -0,0 +1,39 @@
|
||||
"""Proxmox parent entity class."""
|
||||
|
||||
from homeassistant.helpers.update_coordinator import (
|
||||
CoordinatorEntity,
|
||||
DataUpdateCoordinator,
|
||||
)
|
||||
|
||||
|
||||
class ProxmoxEntity(CoordinatorEntity):
|
||||
"""Represents any entity created for the Proxmox VE platform."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
coordinator: DataUpdateCoordinator,
|
||||
unique_id: str,
|
||||
name: str,
|
||||
icon: str,
|
||||
host_name: str,
|
||||
node_name: str,
|
||||
vm_id: int | None = None,
|
||||
) -> None:
|
||||
"""Initialize the Proxmox entity."""
|
||||
super().__init__(coordinator)
|
||||
|
||||
self.coordinator = coordinator
|
||||
self._attr_unique_id = unique_id
|
||||
self._attr_name = name
|
||||
self._host_name = host_name
|
||||
self._attr_icon = icon
|
||||
self._available = True
|
||||
self._node_name = node_name
|
||||
self._vm_id = vm_id
|
||||
|
||||
self._state = None
|
||||
|
||||
@property
|
||||
def available(self) -> bool:
|
||||
"""Return True if entity is available."""
|
||||
return self.coordinator.last_update_success and self._available
|
Loading…
x
Reference in New Issue
Block a user