diff --git a/homeassistant/components/proxmoxve/binary_sensor.py b/homeassistant/components/proxmoxve/binary_sensor.py index 1d607a741bd7..d688e41b6244 100644 --- a/homeassistant/components/proxmoxve/binary_sensor.py +++ b/homeassistant/components/proxmoxve/binary_sensor.py @@ -17,7 +17,7 @@ from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback from .const import NODE_ONLINE, VM_CONTAINER_RUNNING -from .coordinator import ProxmoxConfigEntry, ProxmoxCoordinator, ProxmoxNodeData +from .coordinator import ProxmoxConfigEntry, ProxmoxNodeData from .entity import ProxmoxContainerEntity, ProxmoxNodeEntity, ProxmoxVMEntity _LOGGER = logging.getLogger(__name__) @@ -147,18 +147,6 @@ class ProxmoxNodeBinarySensor(ProxmoxNodeEntity, BinarySensorEntity): entity_description: ProxmoxNodeBinarySensorEntityDescription - def __init__( - self, - coordinator: ProxmoxCoordinator, - entity_description: ProxmoxNodeBinarySensorEntityDescription, - node_data: ProxmoxNodeData, - ) -> None: - """Initialize Proxmox node binary sensor entity.""" - self.entity_description = entity_description - super().__init__(coordinator, node_data) - - self._attr_unique_id = f"{coordinator.config_entry.entry_id}_{node_data.node['id']}_{entity_description.key}" - @property def is_on(self) -> bool | None: """Return true if the binary sensor is on.""" @@ -170,19 +158,6 @@ class ProxmoxVMBinarySensor(ProxmoxVMEntity, BinarySensorEntity): entity_description: ProxmoxVMBinarySensorEntityDescription - def __init__( - self, - coordinator: ProxmoxCoordinator, - entity_description: ProxmoxVMBinarySensorEntityDescription, - vm_data: dict[str, Any], - node_data: ProxmoxNodeData, - ) -> None: - """Initialize the Proxmox VM binary sensor.""" - self.entity_description = entity_description - super().__init__(coordinator, vm_data, node_data) - - self._attr_unique_id = f"{coordinator.config_entry.entry_id}_{self.device_id}_{entity_description.key}" - @property def is_on(self) -> bool | None: """Return true if the binary sensor is on.""" @@ -194,19 +169,6 @@ class ProxmoxContainerBinarySensor(ProxmoxContainerEntity, BinarySensorEntity): entity_description: ProxmoxContainerBinarySensorEntityDescription - def __init__( - self, - coordinator: ProxmoxCoordinator, - entity_description: ProxmoxContainerBinarySensorEntityDescription, - container_data: dict[str, Any], - node_data: ProxmoxNodeData, - ) -> None: - """Initialize the Proxmox Container binary sensor.""" - self.entity_description = entity_description - super().__init__(coordinator, container_data, node_data) - - self._attr_unique_id = f"{coordinator.config_entry.entry_id}_{self.device_id}_{entity_description.key}" - @property def is_on(self) -> bool | None: """Return true if the binary sensor is on.""" diff --git a/homeassistant/components/proxmoxve/button.py b/homeassistant/components/proxmoxve/button.py index 8f8e3ddeb723..da23ecbc8420 100644 --- a/homeassistant/components/proxmoxve/button.py +++ b/homeassistant/components/proxmoxve/button.py @@ -262,18 +262,6 @@ class ProxmoxNodeButtonEntity(ProxmoxNodeEntity, ProxmoxBaseButton): entity_description: ProxmoxNodeButtonNodeEntityDescription - def __init__( - self, - coordinator: ProxmoxCoordinator, - entity_description: ProxmoxNodeButtonNodeEntityDescription, - node_data: ProxmoxNodeData, - ) -> None: - """Initialize the Proxmox Node button entity.""" - self.entity_description = entity_description - super().__init__(coordinator, node_data) - - self._attr_unique_id = f"{coordinator.config_entry.entry_id}_{node_data.node['id']}_{entity_description.key}" - async def _async_press_call(self) -> None: """Execute the node button action via executor.""" await self.hass.async_add_executor_job( @@ -288,19 +276,6 @@ class ProxmoxVMButtonEntity(ProxmoxVMEntity, ProxmoxBaseButton): entity_description: ProxmoxVMButtonEntityDescription - def __init__( - self, - coordinator: ProxmoxCoordinator, - entity_description: ProxmoxVMButtonEntityDescription, - vm_data: dict[str, Any], - node_data: ProxmoxNodeData, - ) -> None: - """Initialize the Proxmox VM button entity.""" - self.entity_description = entity_description - super().__init__(coordinator, vm_data, node_data) - - self._attr_unique_id = f"{coordinator.config_entry.entry_id}_{self.device_id}_{entity_description.key}" - async def _async_press_call(self) -> None: """Execute the VM button action via executor.""" await self.hass.async_add_executor_job( @@ -316,19 +291,6 @@ class ProxmoxContainerButtonEntity(ProxmoxContainerEntity, ProxmoxBaseButton): entity_description: ProxmoxContainerButtonEntityDescription - def __init__( - self, - coordinator: ProxmoxCoordinator, - entity_description: ProxmoxContainerButtonEntityDescription, - container_data: dict[str, Any], - node_data: ProxmoxNodeData, - ) -> None: - """Initialize the Proxmox Container button entity.""" - self.entity_description = entity_description - super().__init__(coordinator, container_data, node_data) - - self._attr_unique_id = f"{coordinator.config_entry.entry_id}_{self.device_id}_{entity_description.key}" - async def _async_press_call(self) -> None: """Execute the container button action via executor.""" await self.hass.async_add_executor_job( diff --git a/homeassistant/components/proxmoxve/entity.py b/homeassistant/components/proxmoxve/entity.py index 2bae10f7ed37..5684845391a6 100644 --- a/homeassistant/components/proxmoxve/entity.py +++ b/homeassistant/components/proxmoxve/entity.py @@ -8,6 +8,7 @@ from yarl import URL from homeassistant.const import CONF_HOST, CONF_PORT from homeassistant.helpers.device_registry import DeviceInfo +from homeassistant.helpers.entity import EntityDescription from homeassistant.helpers.update_coordinator import CoordinatorEntity from .const import DOMAIN @@ -36,6 +37,7 @@ class ProxmoxNodeEntity(ProxmoxCoordinatorEntity): def __init__( self, coordinator: ProxmoxCoordinator, + entity_description: EntityDescription, node_data: ProxmoxNodeData, ) -> None: """Initialize the Proxmox node entity.""" @@ -43,6 +45,7 @@ class ProxmoxNodeEntity(ProxmoxCoordinatorEntity): self._node_data = node_data self.device_id = node_data.node["id"] self.device_name = node_data.node["node"] + self.entity_description = entity_description self._attr_device_info = DeviceInfo( identifiers={ (DOMAIN, f"{coordinator.config_entry.entry_id}_node_{self.device_id}") @@ -54,6 +57,8 @@ class ProxmoxNodeEntity(ProxmoxCoordinatorEntity): ), ) + self._attr_unique_id = f"{coordinator.config_entry.entry_id}_{node_data.node['id']}_{entity_description.key}" + @property def available(self) -> bool: """Return if the device is available.""" @@ -66,11 +71,13 @@ class ProxmoxVMEntity(ProxmoxCoordinatorEntity): def __init__( self, coordinator: ProxmoxCoordinator, + entity_description: EntityDescription, vm_data: dict[str, Any], node_data: ProxmoxNodeData, ) -> None: """Initialize the Proxmox VM entity.""" super().__init__(coordinator) + self.entity_description = entity_description self._vm_data = vm_data self._node_name = node_data.node["node"] self.device_id = vm_data["vmid"] @@ -91,6 +98,8 @@ class ProxmoxVMEntity(ProxmoxCoordinatorEntity): ), ) + self._attr_unique_id = f"{coordinator.config_entry.entry_id}_{self.device_id}_{entity_description.key}" + @property def available(self) -> bool: """Return if the device is available.""" @@ -112,11 +121,13 @@ class ProxmoxContainerEntity(ProxmoxCoordinatorEntity): def __init__( self, coordinator: ProxmoxCoordinator, + entity_description: EntityDescription, container_data: dict[str, Any], node_data: ProxmoxNodeData, ) -> None: """Initialize the Proxmox Container entity.""" super().__init__(coordinator) + self.entity_description = entity_description self._container_data = container_data self._node_name = node_data.node["node"] self.device_id = container_data["vmid"] @@ -140,6 +151,8 @@ class ProxmoxContainerEntity(ProxmoxCoordinatorEntity): ), ) + self._attr_unique_id = f"{coordinator.config_entry.entry_id}_{self.device_id}_{entity_description.key}" + @property def available(self) -> bool: """Return if the device is available.""" diff --git a/homeassistant/components/proxmoxve/sensor.py b/homeassistant/components/proxmoxve/sensor.py index 1a680b1a4a39..f8137b6e757e 100644 --- a/homeassistant/components/proxmoxve/sensor.py +++ b/homeassistant/components/proxmoxve/sensor.py @@ -18,7 +18,7 @@ from homeassistant.const import PERCENTAGE, UnitOfInformation from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback -from .coordinator import ProxmoxConfigEntry, ProxmoxCoordinator, ProxmoxNodeData +from .coordinator import ProxmoxConfigEntry, ProxmoxNodeData from .entity import ProxmoxContainerEntity, ProxmoxNodeEntity, ProxmoxVMEntity @@ -320,18 +320,6 @@ class ProxmoxNodeSensor(ProxmoxNodeEntity, SensorEntity): entity_description: ProxmoxNodeSensorEntityDescription - def __init__( - self, - coordinator: ProxmoxCoordinator, - entity_description: ProxmoxNodeSensorEntityDescription, - node_data: ProxmoxNodeData, - ) -> None: - """Initialize the sensor.""" - super().__init__(coordinator, node_data) - self.entity_description = entity_description - - self._attr_unique_id = f"{coordinator.config_entry.entry_id}_{node_data.node['id']}_{entity_description.key}" - @property def native_value(self) -> StateType: """Return the native value of the sensor.""" @@ -343,19 +331,6 @@ class ProxmoxVMSensor(ProxmoxVMEntity, SensorEntity): entity_description: ProxmoxVMSensorEntityDescription - def __init__( - self, - coordinator: ProxmoxCoordinator, - entity_description: ProxmoxVMSensorEntityDescription, - vm_data: dict[str, Any], - node_data: ProxmoxNodeData, - ) -> None: - """Initialize the Proxmox VM sensor.""" - self.entity_description = entity_description - super().__init__(coordinator, vm_data, node_data) - - self._attr_unique_id = f"{coordinator.config_entry.entry_id}_{self.device_id}_{entity_description.key}" - @property def native_value(self) -> StateType: """Return the native value of the sensor.""" @@ -367,19 +342,6 @@ class ProxmoxContainerSensor(ProxmoxContainerEntity, SensorEntity): entity_description: ProxmoxContainerSensorEntityDescription - def __init__( - self, - coordinator: ProxmoxCoordinator, - entity_description: ProxmoxContainerSensorEntityDescription, - container_data: dict[str, Any], - node_data: ProxmoxNodeData, - ) -> None: - """Initialize the Proxmox container sensor.""" - self.entity_description = entity_description - super().__init__(coordinator, container_data, node_data) - - self._attr_unique_id = f"{coordinator.config_entry.entry_id}_{self.device_id}_{entity_description.key}" - @property def native_value(self) -> StateType: """Return the native value of the sensor."""