Skip to content

Commit

Permalink
Clean-up Minecraft Server constants (home-assistant#100666)
Browse files Browse the repository at this point in the history
  • Loading branch information
elmurato authored Sep 21, 2023
1 parent 9f56aec commit f2fc621
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 49 deletions.
6 changes: 5 additions & 1 deletion homeassistant/components/minecraft_server/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from .const import DOMAIN, ICON_STATUS, KEY_STATUS
from .const import DOMAIN
from .coordinator import MinecraftServerCoordinator
from .entity import MinecraftServerEntity

ICON_STATUS = "mdi:lan"

KEY_STATUS = "status"


@dataclass
class MinecraftServerBinarySensorEntityDescription(BinarySensorEntityDescription):
Expand Down
4 changes: 3 additions & 1 deletion homeassistant/components/minecraft_server/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
from homeassistant.data_entry_flow import FlowResult

from . import helpers
from .const import DEFAULT_HOST, DEFAULT_NAME, DEFAULT_PORT, DOMAIN
from .const import DEFAULT_NAME, DEFAULT_PORT, DOMAIN

DEFAULT_HOST = "localhost:25565"

_LOGGER = logging.getLogger(__name__)

Expand Down
25 changes: 0 additions & 25 deletions homeassistant/components/minecraft_server/const.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,9 @@
"""Constants for the Minecraft Server integration."""

ATTR_PLAYERS_LIST = "players_list"

DEFAULT_HOST = "localhost:25565"
DEFAULT_NAME = "Minecraft Server"
DEFAULT_PORT = 25565

DOMAIN = "minecraft_server"

ICON_LATENCY = "mdi:signal"
ICON_PLAYERS_MAX = "mdi:account-multiple"
ICON_PLAYERS_ONLINE = "mdi:account-multiple"
ICON_PROTOCOL_VERSION = "mdi:numeric"
ICON_STATUS = "mdi:lan"
ICON_VERSION = "mdi:numeric"
ICON_MOTD = "mdi:minecraft"

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"

SCAN_INTERVAL = 60

SRV_RECORD_PREFIX = "_minecraft._tcp"

UNIT_PLAYERS_MAX = "players"
UNIT_PLAYERS_ONLINE = "players"
5 changes: 3 additions & 2 deletions homeassistant/components/minecraft_server/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed

from . import helpers
from .const import SCAN_INTERVAL

SCAN_INTERVAL = timedelta(seconds=60)

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -45,7 +46,7 @@ def __init__(
hass=hass,
name=config_data[CONF_NAME],
logger=_LOGGER,
update_interval=timedelta(seconds=SCAN_INTERVAL),
update_interval=SCAN_INTERVAL,
)

# Server data
Expand Down
4 changes: 3 additions & 1 deletion homeassistant/components/minecraft_server/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.update_coordinator import CoordinatorEntity

from .const import DOMAIN, MANUFACTURER
from .const import DOMAIN
from .coordinator import MinecraftServerCoordinator

MANUFACTURER = "Mojang Studios"


class MinecraftServerEntity(CoordinatorEntity[MinecraftServerCoordinator]):
"""Representation of a Minecraft Server base entity."""
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/minecraft_server/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from homeassistant.const import CONF_HOST, CONF_PORT

from .const import SRV_RECORD_PREFIX
SRV_RECORD_PREFIX = "_minecraft._tcp"

_LOGGER = logging.getLogger(__name__)

Expand Down
36 changes: 18 additions & 18 deletions homeassistant/components/minecraft_server/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,27 @@
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import StateType

from .const import (
ATTR_PLAYERS_LIST,
DOMAIN,
ICON_LATENCY,
ICON_MOTD,
ICON_PLAYERS_MAX,
ICON_PLAYERS_ONLINE,
ICON_PROTOCOL_VERSION,
ICON_VERSION,
KEY_LATENCY,
KEY_MOTD,
KEY_PLAYERS_MAX,
KEY_PLAYERS_ONLINE,
KEY_PROTOCOL_VERSION,
KEY_VERSION,
UNIT_PLAYERS_MAX,
UNIT_PLAYERS_ONLINE,
)
from .const import DOMAIN, KEY_LATENCY, KEY_MOTD
from .coordinator import MinecraftServerCoordinator, MinecraftServerData
from .entity import MinecraftServerEntity

ATTR_PLAYERS_LIST = "players_list"

ICON_LATENCY = "mdi:signal"
ICON_PLAYERS_MAX = "mdi:account-multiple"
ICON_PLAYERS_ONLINE = "mdi:account-multiple"
ICON_PROTOCOL_VERSION = "mdi:numeric"
ICON_VERSION = "mdi:numeric"
ICON_MOTD = "mdi:minecraft"

KEY_PLAYERS_MAX = "players_max"
KEY_PLAYERS_ONLINE = "players_online"
KEY_PROTOCOL_VERSION = "protocol_version"
KEY_VERSION = "version"

UNIT_PLAYERS_MAX = "players"
UNIT_PLAYERS_ONLINE = "players"


@dataclass
class MinecraftServerEntityDescriptionMixin:
Expand Down

0 comments on commit f2fc621

Please sign in to comment.