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:
dougiteixeira 2023-03-29 18:04:37 -03:00 committed by GitHub
parent 7010447b04
commit 43a7247dde
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 53 deletions

View File

@ -22,10 +22,7 @@ from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.discovery import async_load_platform from homeassistant.helpers.discovery import async_load_platform
from homeassistant.helpers.typing import ConfigType from homeassistant.helpers.typing import ConfigType
from homeassistant.helpers.update_coordinator import ( from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
CoordinatorEntity,
DataUpdateCoordinator,
)
from .const import ( from .const import (
_LOGGER, _LOGGER,
@ -252,54 +249,6 @@ def call_api_container_vm(
return status 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: class ProxmoxClient:
"""A wrapper for the proxmoxer ProxmoxAPI client.""" """A wrapper for the proxmoxer ProxmoxAPI client."""

View File

@ -10,7 +10,8 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator 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( async def async_setup_platform(

View 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