Skip to content

Commit

Permalink
Merge pull request #56 from dougiteixeira/entity-name-translations
Browse files Browse the repository at this point in the history
Add entity name translations
  • Loading branch information
dougiteixeira authored Jul 20, 2023
2 parents c3bd2fa + bd15fab commit 0900f87
Show file tree
Hide file tree
Showing 11 changed files with 261 additions and 36 deletions.
12 changes: 5 additions & 7 deletions custom_components/proxmoxve/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Support for Proxmox VE."""
from __future__ import annotations

from typing import Any
import warnings

from proxmoxer import AuthenticationError, ProxmoxAPI
from proxmoxer.core import ResourceException
Expand All @@ -10,10 +12,9 @@
RetryError,
SSLError,
)
from urllib3.exceptions import InsecureRequestWarning
import voluptuous as vol

import warnings

from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.const import (
CONF_HOST,
Expand All @@ -35,9 +36,6 @@
)
from homeassistant.helpers.typing import ConfigType


from urllib3.exceptions import InsecureRequestWarning

from .const import (
CONF_CONTAINERS,
CONF_LXC,
Expand Down Expand Up @@ -176,11 +174,11 @@ async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry):
device_identifiers.append(
f"{config_entry.data[CONF_HOST]}_{config_entry.data[CONF_PORT]}_{config_entry.data.get(CONF_NODE)}"
)
for resource in config_entry.data.get(CONF_QEMU):
for resource in config_entry.data[CONF_QEMU]:
device_identifiers.append(
f"{config_entry.data[CONF_HOST]}_{config_entry.data[CONF_PORT]}_{config_entry.data.get(CONF_NODE)}_{resource}"
)
for resource in config_entry.data.get(CONF_LXC):
for resource in config_entry.data[CONF_LXC]:
device_identifiers.append(
f"{config_entry.data[CONF_HOST]}_{config_entry.data[CONF_PORT]}_{config_entry.data.get(CONF_NODE)}_{resource}"
)
Expand Down
3 changes: 3 additions & 0 deletions custom_components/proxmoxve/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class ProxmoxBinarySensorEntityDescription(
name="Status",
device_class=BinarySensorDeviceClass.RUNNING,
on_value="online",
translation_key="status",
),
)

Expand All @@ -47,6 +48,7 @@ class ProxmoxBinarySensorEntityDescription(
name="Status",
device_class=BinarySensorDeviceClass.RUNNING,
on_value="running",
translation_key="status",
),
ProxmoxBinarySensorEntityDescription(
key=ProxmoxKeyAPIParse.HEALTH,
Expand All @@ -55,6 +57,7 @@ class ProxmoxBinarySensorEntityDescription(
on_value="running",
inverted=True,
api_category=ProxmoxType.QEMU,
translation_key="health",
),
)

Expand Down
16 changes: 13 additions & 3 deletions custom_components/proxmoxve/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
)
from .const import (
CONF_LXC,
CONF_NODE,
CONF_NODES,
CONF_QEMU,
COORDINATORS,
Expand All @@ -43,26 +42,30 @@ class ProxmoxButtonEntityDescription(ProxmoxEntityDescription, ButtonEntityDescr
ProxmoxButtonEntityDescription(
key=ProxmoxCommand.START_ALL,
icon="mdi:play",
name="Start All",
name="Start all",
entity_registry_enabled_default=False,
translation_key="start_all",
),
ProxmoxButtonEntityDescription(
key=ProxmoxCommand.STOP_ALL,
icon="mdi:stop",
name="Stop All",
name="Stop all",
entity_registry_enabled_default=False,
translation_key="stop_all",
),
ProxmoxButtonEntityDescription(
key=ProxmoxCommand.SHUTDOWN,
icon="mdi:server-off",
name="Shutdown",
entity_registry_enabled_default=False,
translation_key="shutdown",
),
ProxmoxButtonEntityDescription(
key=ProxmoxCommand.REBOOT,
icon="mdi:restart",
name="Reboot",
entity_registry_enabled_default=False,
translation_key="reboot",
),
)

Expand All @@ -73,48 +76,55 @@ class ProxmoxButtonEntityDescription(ProxmoxEntityDescription, ButtonEntityDescr
name="Reboot",
api_category=[ProxmoxType.QEMU, ProxmoxType.LXC],
entity_registry_enabled_default=False,
translation_key="reboot",
),
ProxmoxButtonEntityDescription(
key=ProxmoxCommand.START,
icon="mdi:server",
name="Start",
api_category=[ProxmoxType.QEMU, ProxmoxType.LXC],
entity_registry_enabled_default=False,
translation_key="start",
),
ProxmoxButtonEntityDescription(
key=ProxmoxCommand.SHUTDOWN,
icon="mdi:server-off",
name="Shutdown",
api_category=[ProxmoxType.QEMU, ProxmoxType.LXC],
entity_registry_enabled_default=False,
translation_key="shutdown",
),
ProxmoxButtonEntityDescription(
key=ProxmoxCommand.STOP,
icon="mdi:stop",
name="Stop",
api_category=[ProxmoxType.QEMU, ProxmoxType.LXC],
entity_registry_enabled_default=False,
translation_key="stop",
),
ProxmoxButtonEntityDescription(
key=ProxmoxCommand.RESUME,
icon="mdi:play",
name="Resume",
api_category=ProxmoxType.QEMU,
entity_registry_enabled_default=False,
translation_key="resume",
),
ProxmoxButtonEntityDescription(
key=ProxmoxCommand.SUSPEND,
icon="mdi:pause",
name="Suspend",
api_category=ProxmoxType.QEMU,
entity_registry_enabled_default=False,
translation_key="suspend",
),
ProxmoxButtonEntityDescription(
key=ProxmoxCommand.RESET,
icon="mdi:restart-alert",
name="Reset",
api_category=ProxmoxType.QEMU,
entity_registry_enabled_default=False,
translation_key="reset",
),
)

Expand Down
2 changes: 1 addition & 1 deletion custom_components/proxmoxve/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ async def async_step_expose(
self._config[CONF_LXC].append(lxc_selection)

return self.async_create_entry(
title=(f"{self._config[CONF_HOST]}:" f"{self._config[CONF_PORT]}"),
title=(f"{self._config[CONF_HOST]}:{self._config[CONF_PORT]}"),
data=self._config,
)

Expand Down
4 changes: 2 additions & 2 deletions custom_components/proxmoxve/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from requests.exceptions import ConnectTimeout, SSLError

from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_HOST, CONF_PORT, CONF_USERNAME
from homeassistant.const import CONF_HOST, CONF_USERNAME
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.issue_registry import (
Expand All @@ -21,7 +21,7 @@
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed

from .const import CONF_NODE, DOMAIN, LOGGER, UPDATE_INTERVAL, ProxmoxType
from .models import ProxmoxNodeData, ProxmoxVMData, ProxmoxLXCData
from .models import ProxmoxLXCData, ProxmoxNodeData, ProxmoxVMData


class ProxmoxCoordinator(
Expand Down
2 changes: 2 additions & 0 deletions custom_components/proxmoxve/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
CoordinatorEntity,
DataUpdateCoordinator,
)

from .models import ProxmoxEntityDescription


class ProxmoxEntity(CoordinatorEntity):
"""Represents any entity created for the Proxmox VE platform."""

Expand Down
2 changes: 1 addition & 1 deletion custom_components/proxmoxve/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"issue_tracker": "https://github.com/dougiteixeira/proxmoxve/issues",
"loggers": ["proxmoxer"],
"requirements": ["proxmoxer==2.0.1"],
"version": "2.0.0"
"version": "2.0.3"
}
2 changes: 1 addition & 1 deletion custom_components/proxmoxve/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ class ProxmoxButtonDescription(ButtonEntityDescription):

unit_metric: str | None = None
unit_imperial: str | None = None
button_command: str | None = None
button_command: str | None = None
Loading

0 comments on commit 0900f87

Please sign in to comment.