mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Use constants for translation keys and rename latency time to latency (#97866)
Use constants for translation keys, rename latency time to latency and some small cleanups
This commit is contained in:
parent
0caeac1a82
commit
8195c9d1a7
@ -86,7 +86,7 @@ class MinecraftServer:
|
||||
# Data provided by 3rd party library
|
||||
self.version: str | None = None
|
||||
self.protocol_version: int | None = None
|
||||
self.latency_time: float | None = None
|
||||
self.latency: float | None = None
|
||||
self.players_online: int | None = None
|
||||
self.players_max: int | None = None
|
||||
self.players_list: list[str] | None = None
|
||||
@ -174,7 +174,7 @@ class MinecraftServer:
|
||||
self.protocol_version = status_response.version.protocol
|
||||
self.players_online = status_response.players.online
|
||||
self.players_max = status_response.players.max
|
||||
self.latency_time = status_response.latency
|
||||
self.latency = status_response.latency
|
||||
self.motd = status_response.motd.to_plain()
|
||||
|
||||
self.players_list = []
|
||||
@ -197,7 +197,7 @@ class MinecraftServer:
|
||||
self.protocol_version = None
|
||||
self.players_online = None
|
||||
self.players_max = None
|
||||
self.latency_time = None
|
||||
self.latency = None
|
||||
self.players_list = None
|
||||
self.motd = None
|
||||
|
||||
|
@ -8,7 +8,7 @@ from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import MinecraftServer
|
||||
from .const import DOMAIN, ICON_STATUS, NAME_STATUS
|
||||
from .const import DOMAIN, ICON_STATUS, KEY_STATUS, NAME_STATUS
|
||||
from .entity import MinecraftServerEntity
|
||||
|
||||
|
||||
@ -30,7 +30,7 @@ async def async_setup_entry(
|
||||
class MinecraftServerStatusBinarySensor(MinecraftServerEntity, BinarySensorEntity):
|
||||
"""Representation of a Minecraft Server status binary sensor."""
|
||||
|
||||
_attr_translation_key = "status"
|
||||
_attr_translation_key = KEY_STATUS
|
||||
|
||||
def __init__(self, server: MinecraftServer) -> None:
|
||||
"""Initialize status binary sensor."""
|
||||
|
@ -30,7 +30,7 @@ class MinecraftServerConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
address_left, separator, address_right = user_input[CONF_HOST].rpartition(
|
||||
":"
|
||||
)
|
||||
# If no separator is found, 'rpartition' return ('', '', original_string).
|
||||
# If no separator is found, 'rpartition' returns ('', '', original_string).
|
||||
if separator == "":
|
||||
host = address_right
|
||||
else:
|
||||
|
@ -8,7 +8,7 @@ DEFAULT_PORT = 25565
|
||||
|
||||
DOMAIN = "minecraft_server"
|
||||
|
||||
ICON_LATENCY_TIME = "mdi:signal"
|
||||
ICON_LATENCY = "mdi:signal"
|
||||
ICON_PLAYERS_MAX = "mdi:account-multiple"
|
||||
ICON_PLAYERS_ONLINE = "mdi:account-multiple"
|
||||
ICON_PROTOCOL_VERSION = "mdi:numeric"
|
||||
@ -16,11 +16,17 @@ ICON_STATUS = "mdi:lan"
|
||||
ICON_VERSION = "mdi:numeric"
|
||||
ICON_MOTD = "mdi:minecraft"
|
||||
|
||||
KEY_SERVERS = "servers"
|
||||
KEY_LATENCY = "latency"
|
||||
KEY_PLAYERS_MAX = "players_max"
|
||||
KEY_PLAYERS_ONLINE = "players_online"
|
||||
KEY_PROTOCOL_VERSION = "protocol_version"
|
||||
KEY_STATUS = "status"
|
||||
KEY_VERSION = "version"
|
||||
KEY_MOTD = "motd"
|
||||
|
||||
MANUFACTURER = "Mojang AB"
|
||||
|
||||
NAME_LATENCY_TIME = "Latency Time"
|
||||
NAME_LATENCY = "Latency Time"
|
||||
NAME_PLAYERS_MAX = "Players Max"
|
||||
NAME_PLAYERS_ONLINE = "Players Online"
|
||||
NAME_PROTOCOL_VERSION = "Protocol Version"
|
||||
|
@ -11,13 +11,19 @@ from . import MinecraftServer
|
||||
from .const import (
|
||||
ATTR_PLAYERS_LIST,
|
||||
DOMAIN,
|
||||
ICON_LATENCY_TIME,
|
||||
ICON_LATENCY,
|
||||
ICON_MOTD,
|
||||
ICON_PLAYERS_MAX,
|
||||
ICON_PLAYERS_ONLINE,
|
||||
ICON_PROTOCOL_VERSION,
|
||||
ICON_VERSION,
|
||||
NAME_LATENCY_TIME,
|
||||
KEY_LATENCY,
|
||||
KEY_MOTD,
|
||||
KEY_PLAYERS_MAX,
|
||||
KEY_PLAYERS_ONLINE,
|
||||
KEY_PROTOCOL_VERSION,
|
||||
KEY_VERSION,
|
||||
NAME_LATENCY,
|
||||
NAME_MOTD,
|
||||
NAME_PLAYERS_MAX,
|
||||
NAME_PLAYERS_ONLINE,
|
||||
@ -41,7 +47,7 @@ async def async_setup_entry(
|
||||
entities = [
|
||||
MinecraftServerVersionSensor(server),
|
||||
MinecraftServerProtocolVersionSensor(server),
|
||||
MinecraftServerLatencyTimeSensor(server),
|
||||
MinecraftServerLatencySensor(server),
|
||||
MinecraftServerPlayersOnlineSensor(server),
|
||||
MinecraftServerPlayersMaxSensor(server),
|
||||
MinecraftServerMOTDSensor(server),
|
||||
@ -75,7 +81,7 @@ class MinecraftServerSensorEntity(MinecraftServerEntity, SensorEntity):
|
||||
class MinecraftServerVersionSensor(MinecraftServerSensorEntity):
|
||||
"""Representation of a Minecraft Server version sensor."""
|
||||
|
||||
_attr_translation_key = "version"
|
||||
_attr_translation_key = KEY_VERSION
|
||||
|
||||
def __init__(self, server: MinecraftServer) -> None:
|
||||
"""Initialize version sensor."""
|
||||
@ -89,7 +95,7 @@ class MinecraftServerVersionSensor(MinecraftServerSensorEntity):
|
||||
class MinecraftServerProtocolVersionSensor(MinecraftServerSensorEntity):
|
||||
"""Representation of a Minecraft Server protocol version sensor."""
|
||||
|
||||
_attr_translation_key = "protocol_version"
|
||||
_attr_translation_key = KEY_PROTOCOL_VERSION
|
||||
|
||||
def __init__(self, server: MinecraftServer) -> None:
|
||||
"""Initialize protocol version sensor."""
|
||||
@ -104,29 +110,29 @@ class MinecraftServerProtocolVersionSensor(MinecraftServerSensorEntity):
|
||||
self._attr_native_value = self._server.protocol_version
|
||||
|
||||
|
||||
class MinecraftServerLatencyTimeSensor(MinecraftServerSensorEntity):
|
||||
"""Representation of a Minecraft Server latency time sensor."""
|
||||
class MinecraftServerLatencySensor(MinecraftServerSensorEntity):
|
||||
"""Representation of a Minecraft Server latency sensor."""
|
||||
|
||||
_attr_translation_key = "latency"
|
||||
_attr_translation_key = KEY_LATENCY
|
||||
|
||||
def __init__(self, server: MinecraftServer) -> None:
|
||||
"""Initialize latency time sensor."""
|
||||
"""Initialize latency sensor."""
|
||||
super().__init__(
|
||||
server=server,
|
||||
type_name=NAME_LATENCY_TIME,
|
||||
icon=ICON_LATENCY_TIME,
|
||||
type_name=NAME_LATENCY,
|
||||
icon=ICON_LATENCY,
|
||||
unit=UnitOfTime.MILLISECONDS,
|
||||
)
|
||||
|
||||
async def async_update(self) -> None:
|
||||
"""Update latency time."""
|
||||
self._attr_native_value = self._server.latency_time
|
||||
"""Update latency."""
|
||||
self._attr_native_value = self._server.latency
|
||||
|
||||
|
||||
class MinecraftServerPlayersOnlineSensor(MinecraftServerSensorEntity):
|
||||
"""Representation of a Minecraft Server online players sensor."""
|
||||
|
||||
_attr_translation_key = "players_online"
|
||||
_attr_translation_key = KEY_PLAYERS_ONLINE
|
||||
|
||||
def __init__(self, server: MinecraftServer) -> None:
|
||||
"""Initialize online players sensor."""
|
||||
@ -153,7 +159,7 @@ class MinecraftServerPlayersOnlineSensor(MinecraftServerSensorEntity):
|
||||
class MinecraftServerPlayersMaxSensor(MinecraftServerSensorEntity):
|
||||
"""Representation of a Minecraft Server maximum number of players sensor."""
|
||||
|
||||
_attr_translation_key = "players_max"
|
||||
_attr_translation_key = KEY_PLAYERS_MAX
|
||||
|
||||
def __init__(self, server: MinecraftServer) -> None:
|
||||
"""Initialize maximum number of players sensor."""
|
||||
@ -172,7 +178,7 @@ class MinecraftServerPlayersMaxSensor(MinecraftServerSensorEntity):
|
||||
class MinecraftServerMOTDSensor(MinecraftServerSensorEntity):
|
||||
"""Representation of a Minecraft Server MOTD sensor."""
|
||||
|
||||
_attr_translation_key = "motd"
|
||||
_attr_translation_key = KEY_MOTD
|
||||
|
||||
def __init__(self, server: MinecraftServer) -> None:
|
||||
"""Initialize MOTD sensor."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user